PluginProbe
Extendify / 3.0.6
Extendify v3.0.6
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / tests / Integration / CronTest.php

CronTest.php in Extendify 3.0.6, at tests/Integration/CronTest.php

47 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Extendify\Tests\Integration;
4
5 use Extendify\Shared\Services\Import\Post;
6 use WP_UnitTestCase;
7
8 class CronTest extends WP_UnitTestCase
9 {
10 public function test_cron_executes()
11 {
12 $isLocked = false;
13 $cronUserId = null;
14 $user = self::factory()->user->create();
15 wp_set_current_user($user);
16 $postId = self::factory()->post->create(['post_content' => '<p>original</p>']);
17 wp_set_post_lock($postId);
18
19 // Cron runs as no user, so we need to reset the current user to 0 to simulate that.
20 wp_set_current_user(0);
21 add_action('my_cron_hook', function () use ($postId, &$isLocked, &$cronUserId) {
22 $isLocked = wp_check_post_lock($postId);
23 $cronUserId = get_current_user_id();
24 });
25
26 wp_schedule_single_event(time() - 10, 'my_cron_hook');
27
28 $crons = _get_cron_array();
29 foreach ($crons as $timestamp => $hooks) {
30 if ($timestamp > time()) continue;
31
32 foreach ($hooks as $hook => $events) {
33 foreach ($events as $event) {
34 do_action_ref_array($hook, $event['args']);
35 }
36 }
37 }
38
39 $this->assertTrue(Post::isLocked($postId));
40 $this->assertNotFalse(wp_check_post_lock($postId));
41 $this->assertNotNull($postId);
42 $this->assertIsNumeric($isLocked);
43 $this->assertSame($user, $isLocked);
44 $this->assertSame(0, $cronUserId);
45 }
46 }
47