Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1605 last php unit test #1718

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Service/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ public function getJobhook(): string {
return $this->jobhook;
}

/**
* @return int timestamp of scheduled event
*/
public function getTimestamp(): int {
return $this->timestamp;
}

/**
* Unschedules the current job.
* This can have multiple reasons:
Expand Down
24 changes: 15 additions & 9 deletions tests/php/Service/SchedulerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,35 @@ public function testReSchedule() {
);
}

/**
* Tests custom recurrences via wp cron interfaces
*/
public function testCustomRecurrence() {

$thirty_minutes = 'thirty_minutes';

$customSchedule = new Scheduler(
'test2',
'CommonsBooking\Tests\Service\dummyFunction',
'thirty_minutes',
$thirty_minutes,
'',
array($this->dummyOptionsKey,$this->dummyFieldId),
$this->dummyUpdateHook
);
$this->jobhooks[] = $customSchedule->getJobhook();

// Should contain custom cron intervals, because Scheduler(...) adds filter
$this->assertContains( 'thirty_minutes', array_keys( wp_get_schedules() ) );

$now = new DateTime('now', new \DateTimeZone('UTC'));
$nowTS = $now->getTimestamp();
// Should contain custom cron intervals, because Scheduler(...) adds filter
$this->assertContains( $thirty_minutes, array_keys( wp_get_schedules() ) );

$this->assertEquals(
$nowTS,
wp_next_scheduled($customSchedule->getJobhook())
// returns timestamp which is used to set internal event object (via wp_schedule_event in Scheduler class)
$customSchedule->getTimestamp(),
// returns timestamp from internal event object identified by job hook
wp_next_scheduled( $customSchedule->getJobhook() )
);

$event = wp_get_scheduled_event($customSchedule->getJobhook());
$this->assertEquals('thirty_minutes',$event->schedule);
$this->assertEquals( $thirty_minutes , $event->schedule );

}

Expand Down
Loading