Completed
Pull Request — develop (#1630)
by
unknown
01:13
created
src/ext/action-scheduler/tests/phpunit/migration/Scheduler_Test.php 2 patches
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -9,139 +9,139 @@
 block discarded – undo
9 9
  * @group migration
10 10
  */
11 11
 class Scheduler_Test extends ActionScheduler_UnitTestCase {
12
-	public function setUp() {
13
-		parent::setUp();
14
-		if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) {
15
-			// register the post type and taxonomy necessary for the store to work
16
-			$store = new PostStore();
17
-			$store->init();
18
-		}
19
-	}
20
-
21
-	public function test_migration_is_complete() {
22
-		ActionScheduler_DataController::mark_migration_complete();
23
-		$this->assertTrue( ActionScheduler_DataController::is_migration_complete() );
24
-	}
25
-
26
-	public function test_migration_is_not_complete() {
27
-		$this->assertFalse( ActionScheduler_DataController::is_migration_complete() );
28
-		update_option( ActionScheduler_DataController::STATUS_FLAG, 'something_random' );
29
-		$this->assertFalse( ActionScheduler_DataController::is_migration_complete() );
30
-	}
31
-
32
-	public function test_migration_is_scheduled() {
33
-		// Clear the any existing migration hooks that have already been setup.
34
-		as_unschedule_all_actions( Scheduler::HOOK );
35
-
36
-		$scheduler = new Scheduler();
37
-		$this->assertFalse(
38
-			$scheduler->is_migration_scheduled(),
39
-			'Migration is not automatically scheduled when a new ' . Scheduler::class . ' instance is created.'
40
-		);
41
-
42
-		$scheduler->schedule_migration();
43
-		$this->assertTrue(
44
-			$scheduler->is_migration_scheduled(),
45
-			'Migration is scheduled only after schedule_migration() has been called.'
46
-		);
47
-	}
48
-
49
-	public function test_scheduler_runs_migration() {
50
-		$source_store      = new PostStore();
51
-		$destination_store = new ActionScheduler_DBStore();
52
-
53
-		$return_5 = function () {
54
-			return 5;
55
-		};
56
-		add_filter( 'action_scheduler/migration_batch_size', $return_5 );
57
-
58
-		// Make sure successive migration actions are delayed so all actions aren't migrated at once on separate hooks
59
-		$return_60 = function () {
60
-			return 60;
61
-		};
62
-		add_filter( 'action_scheduler/migration_interval', $return_60 );
63
-
64
-		for ( $i = 0; $i < 10; $i ++ ) {
65
-			$time     = as_get_datetime_object( $i + 1 . ' minutes' );
66
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
67
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
68
-			$future[] = $source_store->save_action( $action );
69
-
70
-			$time     = as_get_datetime_object( $i + 1 . ' minutes ago' );
71
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
72
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
73
-			$due[]    = $source_store->save_action( $action );
74
-		}
75
-
76
-		$this->assertCount( 20, $source_store->query_actions( array( 'per_page' => 0 ) ) );
77
-
78
-		$scheduler = new Scheduler();
79
-		$scheduler->unschedule_migration();
80
-		$scheduler->schedule_migration( time() - 1 );
81
-
82
-		$queue_runner = ActionScheduler_Mocker::get_queue_runner( $destination_store );
83
-		$queue_runner->run();
84
-
85
-		// 5 actions should have moved from the source store when the queue runner triggered the migration action
86
-		$this->assertCount(
87
-			15,
88
-			$source_store->query_actions(
89
-				array(
90
-					'per_page' => 0,
91
-					'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
92
-				)
93
-			)
94
-		);
95
-
96
-		remove_filter( 'action_scheduler/migration_batch_size', $return_5 );
97
-		remove_filter( 'action_scheduler/migration_interval', $return_60 );
98
-	}
99
-
100
-	public function test_scheduler_marks_itself_complete() {
101
-		$source_store      = new PostStore();
102
-		$destination_store = new ActionScheduler_DBStore();
103
-
104
-		for ( $i = 0; $i < 5; $i ++ ) {
105
-			$time     = as_get_datetime_object( $i + 1 . ' minutes ago' );
106
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
107
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
108
-			$due[]    = $source_store->save_action( $action );
109
-		}
110
-
111
-		$this->assertCount( 5, $source_store->query_actions( array( 'per_page' => 0 ) ) );
112
-
113
-		$scheduler = new Scheduler();
114
-		$scheduler->unschedule_migration();
115
-		$scheduler->schedule_migration( time() - 1 );
116
-
117
-		$queue_runner = ActionScheduler_Mocker::get_queue_runner( $destination_store );
118
-		$queue_runner->run();
119
-
120
-		// All actions should have moved from the source store when the queue runner triggered the migration action
121
-		$this->assertCount(
122
-			0,
123
-			$source_store->query_actions(
124
-				array(
125
-					'per_page' => 0,
126
-					'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
127
-				)
128
-			)
129
-		);
130
-
131
-		// schedule another so we can get it to run immediately
132
-		$scheduler->unschedule_migration();
133
-		$scheduler->schedule_migration( time() - 1 );
134
-
135
-		// run again so it knows that there's nothing left to process
136
-		$queue_runner->run();
137
-
138
-		$scheduler->unhook();
139
-
140
-		// ensure the flag is set marking migration as complete
141
-		$this->assertTrue( ActionScheduler_DataController::is_migration_complete() );
142
-
143
-		// ensure that another instance has not been scheduled
144
-		$this->assertFalse( $scheduler->is_migration_scheduled() );
145
-
146
-	}
12
+    public function setUp() {
13
+        parent::setUp();
14
+        if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) {
15
+            // register the post type and taxonomy necessary for the store to work
16
+            $store = new PostStore();
17
+            $store->init();
18
+        }
19
+    }
20
+
21
+    public function test_migration_is_complete() {
22
+        ActionScheduler_DataController::mark_migration_complete();
23
+        $this->assertTrue( ActionScheduler_DataController::is_migration_complete() );
24
+    }
25
+
26
+    public function test_migration_is_not_complete() {
27
+        $this->assertFalse( ActionScheduler_DataController::is_migration_complete() );
28
+        update_option( ActionScheduler_DataController::STATUS_FLAG, 'something_random' );
29
+        $this->assertFalse( ActionScheduler_DataController::is_migration_complete() );
30
+    }
31
+
32
+    public function test_migration_is_scheduled() {
33
+        // Clear the any existing migration hooks that have already been setup.
34
+        as_unschedule_all_actions( Scheduler::HOOK );
35
+
36
+        $scheduler = new Scheduler();
37
+        $this->assertFalse(
38
+            $scheduler->is_migration_scheduled(),
39
+            'Migration is not automatically scheduled when a new ' . Scheduler::class . ' instance is created.'
40
+        );
41
+
42
+        $scheduler->schedule_migration();
43
+        $this->assertTrue(
44
+            $scheduler->is_migration_scheduled(),
45
+            'Migration is scheduled only after schedule_migration() has been called.'
46
+        );
47
+    }
48
+
49
+    public function test_scheduler_runs_migration() {
50
+        $source_store      = new PostStore();
51
+        $destination_store = new ActionScheduler_DBStore();
52
+
53
+        $return_5 = function () {
54
+            return 5;
55
+        };
56
+        add_filter( 'action_scheduler/migration_batch_size', $return_5 );
57
+
58
+        // Make sure successive migration actions are delayed so all actions aren't migrated at once on separate hooks
59
+        $return_60 = function () {
60
+            return 60;
61
+        };
62
+        add_filter( 'action_scheduler/migration_interval', $return_60 );
63
+
64
+        for ( $i = 0; $i < 10; $i ++ ) {
65
+            $time     = as_get_datetime_object( $i + 1 . ' minutes' );
66
+            $schedule = new ActionScheduler_SimpleSchedule( $time );
67
+            $action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
68
+            $future[] = $source_store->save_action( $action );
69
+
70
+            $time     = as_get_datetime_object( $i + 1 . ' minutes ago' );
71
+            $schedule = new ActionScheduler_SimpleSchedule( $time );
72
+            $action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
73
+            $due[]    = $source_store->save_action( $action );
74
+        }
75
+
76
+        $this->assertCount( 20, $source_store->query_actions( array( 'per_page' => 0 ) ) );
77
+
78
+        $scheduler = new Scheduler();
79
+        $scheduler->unschedule_migration();
80
+        $scheduler->schedule_migration( time() - 1 );
81
+
82
+        $queue_runner = ActionScheduler_Mocker::get_queue_runner( $destination_store );
83
+        $queue_runner->run();
84
+
85
+        // 5 actions should have moved from the source store when the queue runner triggered the migration action
86
+        $this->assertCount(
87
+            15,
88
+            $source_store->query_actions(
89
+                array(
90
+                    'per_page' => 0,
91
+                    'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
92
+                )
93
+            )
94
+        );
95
+
96
+        remove_filter( 'action_scheduler/migration_batch_size', $return_5 );
97
+        remove_filter( 'action_scheduler/migration_interval', $return_60 );
98
+    }
99
+
100
+    public function test_scheduler_marks_itself_complete() {
101
+        $source_store      = new PostStore();
102
+        $destination_store = new ActionScheduler_DBStore();
103
+
104
+        for ( $i = 0; $i < 5; $i ++ ) {
105
+            $time     = as_get_datetime_object( $i + 1 . ' minutes ago' );
106
+            $schedule = new ActionScheduler_SimpleSchedule( $time );
107
+            $action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
108
+            $due[]    = $source_store->save_action( $action );
109
+        }
110
+
111
+        $this->assertCount( 5, $source_store->query_actions( array( 'per_page' => 0 ) ) );
112
+
113
+        $scheduler = new Scheduler();
114
+        $scheduler->unschedule_migration();
115
+        $scheduler->schedule_migration( time() - 1 );
116
+
117
+        $queue_runner = ActionScheduler_Mocker::get_queue_runner( $destination_store );
118
+        $queue_runner->run();
119
+
120
+        // All actions should have moved from the source store when the queue runner triggered the migration action
121
+        $this->assertCount(
122
+            0,
123
+            $source_store->query_actions(
124
+                array(
125
+                    'per_page' => 0,
126
+                    'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
127
+                )
128
+            )
129
+        );
130
+
131
+        // schedule another so we can get it to run immediately
132
+        $scheduler->unschedule_migration();
133
+        $scheduler->schedule_migration( time() - 1 );
134
+
135
+        // run again so it knows that there's nothing left to process
136
+        $queue_runner->run();
137
+
138
+        $scheduler->unhook();
139
+
140
+        // ensure the flag is set marking migration as complete
141
+        $this->assertTrue( ActionScheduler_DataController::is_migration_complete() );
142
+
143
+        // ensure that another instance has not been scheduled
144
+        $this->assertFalse( $scheduler->is_migration_scheduled() );
145
+
146
+    }
147 147
 }
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 class Scheduler_Test extends ActionScheduler_UnitTestCase {
12 12
 	public function setUp() {
13 13
 		parent::setUp();
14
-		if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) {
14
+		if ( ! taxonomy_exists(PostStore::GROUP_TAXONOMY)) {
15 15
 			// register the post type and taxonomy necessary for the store to work
16 16
 			$store = new PostStore();
17 17
 			$store->init();
@@ -20,23 +20,23 @@  discard block
 block discarded – undo
20 20
 
21 21
 	public function test_migration_is_complete() {
22 22
 		ActionScheduler_DataController::mark_migration_complete();
23
-		$this->assertTrue( ActionScheduler_DataController::is_migration_complete() );
23
+		$this->assertTrue(ActionScheduler_DataController::is_migration_complete());
24 24
 	}
25 25
 
26 26
 	public function test_migration_is_not_complete() {
27
-		$this->assertFalse( ActionScheduler_DataController::is_migration_complete() );
28
-		update_option( ActionScheduler_DataController::STATUS_FLAG, 'something_random' );
29
-		$this->assertFalse( ActionScheduler_DataController::is_migration_complete() );
27
+		$this->assertFalse(ActionScheduler_DataController::is_migration_complete());
28
+		update_option(ActionScheduler_DataController::STATUS_FLAG, 'something_random');
29
+		$this->assertFalse(ActionScheduler_DataController::is_migration_complete());
30 30
 	}
31 31
 
32 32
 	public function test_migration_is_scheduled() {
33 33
 		// Clear the any existing migration hooks that have already been setup.
34
-		as_unschedule_all_actions( Scheduler::HOOK );
34
+		as_unschedule_all_actions(Scheduler::HOOK);
35 35
 
36 36
 		$scheduler = new Scheduler();
37 37
 		$this->assertFalse(
38 38
 			$scheduler->is_migration_scheduled(),
39
-			'Migration is not automatically scheduled when a new ' . Scheduler::class . ' instance is created.'
39
+			'Migration is not automatically scheduled when a new '.Scheduler::class.' instance is created.'
40 40
 		);
41 41
 
42 42
 		$scheduler->schedule_migration();
@@ -50,36 +50,36 @@  discard block
 block discarded – undo
50 50
 		$source_store      = new PostStore();
51 51
 		$destination_store = new ActionScheduler_DBStore();
52 52
 
53
-		$return_5 = function () {
53
+		$return_5 = function() {
54 54
 			return 5;
55 55
 		};
56
-		add_filter( 'action_scheduler/migration_batch_size', $return_5 );
56
+		add_filter('action_scheduler/migration_batch_size', $return_5);
57 57
 
58 58
 		// Make sure successive migration actions are delayed so all actions aren't migrated at once on separate hooks
59
-		$return_60 = function () {
59
+		$return_60 = function() {
60 60
 			return 60;
61 61
 		};
62
-		add_filter( 'action_scheduler/migration_interval', $return_60 );
63
-
64
-		for ( $i = 0; $i < 10; $i ++ ) {
65
-			$time     = as_get_datetime_object( $i + 1 . ' minutes' );
66
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
67
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
68
-			$future[] = $source_store->save_action( $action );
69
-
70
-			$time     = as_get_datetime_object( $i + 1 . ' minutes ago' );
71
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
72
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
73
-			$due[]    = $source_store->save_action( $action );
62
+		add_filter('action_scheduler/migration_interval', $return_60);
63
+
64
+		for ($i = 0; $i < 10; $i++) {
65
+			$time     = as_get_datetime_object($i + 1.' minutes');
66
+			$schedule = new ActionScheduler_SimpleSchedule($time);
67
+			$action   = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
68
+			$future[] = $source_store->save_action($action);
69
+
70
+			$time     = as_get_datetime_object($i + 1.' minutes ago');
71
+			$schedule = new ActionScheduler_SimpleSchedule($time);
72
+			$action   = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
73
+			$due[]    = $source_store->save_action($action);
74 74
 		}
75 75
 
76
-		$this->assertCount( 20, $source_store->query_actions( array( 'per_page' => 0 ) ) );
76
+		$this->assertCount(20, $source_store->query_actions(array('per_page' => 0)));
77 77
 
78 78
 		$scheduler = new Scheduler();
79 79
 		$scheduler->unschedule_migration();
80
-		$scheduler->schedule_migration( time() - 1 );
80
+		$scheduler->schedule_migration(time() - 1);
81 81
 
82
-		$queue_runner = ActionScheduler_Mocker::get_queue_runner( $destination_store );
82
+		$queue_runner = ActionScheduler_Mocker::get_queue_runner($destination_store);
83 83
 		$queue_runner->run();
84 84
 
85 85
 		// 5 actions should have moved from the source store when the queue runner triggered the migration action
@@ -93,28 +93,28 @@  discard block
 block discarded – undo
93 93
 			)
94 94
 		);
95 95
 
96
-		remove_filter( 'action_scheduler/migration_batch_size', $return_5 );
97
-		remove_filter( 'action_scheduler/migration_interval', $return_60 );
96
+		remove_filter('action_scheduler/migration_batch_size', $return_5);
97
+		remove_filter('action_scheduler/migration_interval', $return_60);
98 98
 	}
99 99
 
100 100
 	public function test_scheduler_marks_itself_complete() {
101 101
 		$source_store      = new PostStore();
102 102
 		$destination_store = new ActionScheduler_DBStore();
103 103
 
104
-		for ( $i = 0; $i < 5; $i ++ ) {
105
-			$time     = as_get_datetime_object( $i + 1 . ' minutes ago' );
106
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
107
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
108
-			$due[]    = $source_store->save_action( $action );
104
+		for ($i = 0; $i < 5; $i++) {
105
+			$time     = as_get_datetime_object($i + 1.' minutes ago');
106
+			$schedule = new ActionScheduler_SimpleSchedule($time);
107
+			$action   = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
108
+			$due[]    = $source_store->save_action($action);
109 109
 		}
110 110
 
111
-		$this->assertCount( 5, $source_store->query_actions( array( 'per_page' => 0 ) ) );
111
+		$this->assertCount(5, $source_store->query_actions(array('per_page' => 0)));
112 112
 
113 113
 		$scheduler = new Scheduler();
114 114
 		$scheduler->unschedule_migration();
115
-		$scheduler->schedule_migration( time() - 1 );
115
+		$scheduler->schedule_migration(time() - 1);
116 116
 
117
-		$queue_runner = ActionScheduler_Mocker::get_queue_runner( $destination_store );
117
+		$queue_runner = ActionScheduler_Mocker::get_queue_runner($destination_store);
118 118
 		$queue_runner->run();
119 119
 
120 120
 		// All actions should have moved from the source store when the queue runner triggered the migration action
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 
131 131
 		// schedule another so we can get it to run immediately
132 132
 		$scheduler->unschedule_migration();
133
-		$scheduler->schedule_migration( time() - 1 );
133
+		$scheduler->schedule_migration(time() - 1);
134 134
 
135 135
 		// run again so it knows that there's nothing left to process
136 136
 		$queue_runner->run();
@@ -138,10 +138,10 @@  discard block
 block discarded – undo
138 138
 		$scheduler->unhook();
139 139
 
140 140
 		// ensure the flag is set marking migration as complete
141
-		$this->assertTrue( ActionScheduler_DataController::is_migration_complete() );
141
+		$this->assertTrue(ActionScheduler_DataController::is_migration_complete());
142 142
 
143 143
 		// ensure that another instance has not been scheduled
144
-		$this->assertFalse( $scheduler->is_migration_scheduled() );
144
+		$this->assertFalse($scheduler->is_migration_scheduled());
145 145
 
146 146
 	}
147 147
 }
Please login to merge, or discard this patch.
src/ext/action-scheduler/tests/phpunit/migration/ActionMigrator_Test.php 2 patches
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -9,137 +9,137 @@
 block discarded – undo
9 9
  * @group migration
10 10
  */
11 11
 class ActionMigrator_Test extends ActionScheduler_UnitTestCase {
12
-	public function setUp() {
13
-		parent::setUp();
14
-		if ( ! taxonomy_exists( ActionScheduler_wpPostStore::GROUP_TAXONOMY ) ) {
15
-			// register the post type and taxonomy necessary for the store to work
16
-			$store = new ActionScheduler_wpPostStore();
17
-			$store->init();
18
-		}
19
-	}
20
-
21
-	public function test_migrate_from_wpPost_to_db() {
22
-		$source      = new ActionScheduler_wpPostStore();
23
-		$destination = new ActionScheduler_DBStore();
24
-		$migrator    = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
25
-
26
-		$time      = as_get_datetime_object();
27
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
28
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
29
-		$action_id = $source->save_action( $action );
30
-
31
-		$new_id = $migrator->migrate( $action_id );
32
-
33
-		// ensure we get the same record out of the new store as we stored in the old
34
-		$retrieved = $destination->fetch_action( $new_id );
35
-		$this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
36
-		$this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
37
-		$this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
38
-		$this->assertEquals( $action->get_group(), $retrieved->get_group() );
39
-		$this->assertEquals( \ActionScheduler_Store::STATUS_PENDING, $destination->get_status( $new_id ) );
40
-
41
-		// ensure that the record in the old store does not exist
42
-		$old_action = $source->fetch_action( $action_id );
43
-		$this->assertInstanceOf( 'ActionScheduler_NullAction', $old_action );
44
-	}
45
-
46
-	public function test_does_not_migrate_missing_action_from_wpPost_to_db() {
47
-		$source      = new ActionScheduler_wpPostStore();
48
-		$destination = new ActionScheduler_DBStore();
49
-		$migrator    = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
50
-
51
-		$action_id = rand( 100, 100000 );
52
-
53
-		$new_id = $migrator->migrate( $action_id );
54
-		$this->assertSame( 0, $new_id );
55
-
56
-		// ensure we get the same record out of the new store as we stored in the old
57
-		$retrieved = $destination->fetch_action( $new_id );
58
-		$this->assertInstanceOf( 'ActionScheduler_NullAction', $retrieved );
59
-	}
60
-
61
-	public function test_migrate_completed_action_from_wpPost_to_db() {
62
-		$source      = new ActionScheduler_wpPostStore();
63
-		$destination = new ActionScheduler_DBStore();
64
-		$migrator    = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
65
-
66
-		$time      = as_get_datetime_object();
67
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
68
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
69
-		$action_id = $source->save_action( $action );
70
-		$source->mark_complete( $action_id );
71
-
72
-		$new_id = $migrator->migrate( $action_id );
73
-
74
-		// ensure we get the same record out of the new store as we stored in the old
75
-		$retrieved = $destination->fetch_action( $new_id );
76
-		$this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
77
-		$this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
78
-		$this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
79
-		$this->assertEquals( $action->get_group(), $retrieved->get_group() );
80
-		$this->assertTrue( $retrieved->is_finished() );
81
-		$this->assertEquals( \ActionScheduler_Store::STATUS_COMPLETE, $destination->get_status( $new_id ) );
82
-
83
-		// ensure that the record in the old store does not exist
84
-		$old_action = $source->fetch_action( $action_id );
85
-		$this->assertInstanceOf( 'ActionScheduler_NullAction', $old_action );
86
-	}
87
-
88
-	public function test_migrate_failed_action_from_wpPost_to_db() {
89
-		$source      = new ActionScheduler_wpPostStore();
90
-		$destination = new ActionScheduler_DBStore();
91
-		$migrator    = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
92
-
93
-		$time      = as_get_datetime_object();
94
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
95
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
96
-		$action_id = $source->save_action( $action );
97
-		$source->mark_failure( $action_id );
98
-
99
-		$new_id = $migrator->migrate( $action_id );
100
-
101
-		// ensure we get the same record out of the new store as we stored in the old
102
-		$retrieved = $destination->fetch_action( $new_id );
103
-		$this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
104
-		$this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
105
-		$this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
106
-		$this->assertEquals( $action->get_group(), $retrieved->get_group() );
107
-		$this->assertTrue( $retrieved->is_finished() );
108
-		$this->assertEquals( \ActionScheduler_Store::STATUS_FAILED, $destination->get_status( $new_id ) );
109
-
110
-		// ensure that the record in the old store does not exist
111
-		$old_action = $source->fetch_action( $action_id );
112
-		$this->assertInstanceOf( 'ActionScheduler_NullAction', $old_action );
113
-	}
114
-
115
-	public function test_migrate_canceled_action_from_wpPost_to_db() {
116
-		$source      = new ActionScheduler_wpPostStore();
117
-		$destination = new ActionScheduler_DBStore();
118
-		$migrator    = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
119
-
120
-		$time      = as_get_datetime_object();
121
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
122
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
123
-		$action_id = $source->save_action( $action );
124
-		$source->cancel_action( $action_id );
125
-
126
-		$new_id = $migrator->migrate( $action_id );
127
-
128
-		// ensure we get the same record out of the new store as we stored in the old
129
-		$retrieved = $destination->fetch_action( $new_id );
130
-		$this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
131
-		$this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
132
-		$this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
133
-		$this->assertEquals( $action->get_group(), $retrieved->get_group() );
134
-		$this->assertTrue( $retrieved->is_finished() );
135
-		$this->assertEquals( \ActionScheduler_Store::STATUS_CANCELED, $destination->get_status( $new_id ) );
136
-
137
-		// ensure that the record in the old store does not exist
138
-		$old_action = $source->fetch_action( $action_id );
139
-		$this->assertInstanceOf( 'ActionScheduler_NullAction', $old_action );
140
-	}
141
-
142
-	private function get_log_migrator() {
143
-		return new LogMigrator( \ActionScheduler::logger(), new ActionScheduler_DBLogger() );
144
-	}
12
+    public function setUp() {
13
+        parent::setUp();
14
+        if ( ! taxonomy_exists( ActionScheduler_wpPostStore::GROUP_TAXONOMY ) ) {
15
+            // register the post type and taxonomy necessary for the store to work
16
+            $store = new ActionScheduler_wpPostStore();
17
+            $store->init();
18
+        }
19
+    }
20
+
21
+    public function test_migrate_from_wpPost_to_db() {
22
+        $source      = new ActionScheduler_wpPostStore();
23
+        $destination = new ActionScheduler_DBStore();
24
+        $migrator    = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
25
+
26
+        $time      = as_get_datetime_object();
27
+        $schedule  = new ActionScheduler_SimpleSchedule( $time );
28
+        $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
29
+        $action_id = $source->save_action( $action );
30
+
31
+        $new_id = $migrator->migrate( $action_id );
32
+
33
+        // ensure we get the same record out of the new store as we stored in the old
34
+        $retrieved = $destination->fetch_action( $new_id );
35
+        $this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
36
+        $this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
37
+        $this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
38
+        $this->assertEquals( $action->get_group(), $retrieved->get_group() );
39
+        $this->assertEquals( \ActionScheduler_Store::STATUS_PENDING, $destination->get_status( $new_id ) );
40
+
41
+        // ensure that the record in the old store does not exist
42
+        $old_action = $source->fetch_action( $action_id );
43
+        $this->assertInstanceOf( 'ActionScheduler_NullAction', $old_action );
44
+    }
45
+
46
+    public function test_does_not_migrate_missing_action_from_wpPost_to_db() {
47
+        $source      = new ActionScheduler_wpPostStore();
48
+        $destination = new ActionScheduler_DBStore();
49
+        $migrator    = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
50
+
51
+        $action_id = rand( 100, 100000 );
52
+
53
+        $new_id = $migrator->migrate( $action_id );
54
+        $this->assertSame( 0, $new_id );
55
+
56
+        // ensure we get the same record out of the new store as we stored in the old
57
+        $retrieved = $destination->fetch_action( $new_id );
58
+        $this->assertInstanceOf( 'ActionScheduler_NullAction', $retrieved );
59
+    }
60
+
61
+    public function test_migrate_completed_action_from_wpPost_to_db() {
62
+        $source      = new ActionScheduler_wpPostStore();
63
+        $destination = new ActionScheduler_DBStore();
64
+        $migrator    = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
65
+
66
+        $time      = as_get_datetime_object();
67
+        $schedule  = new ActionScheduler_SimpleSchedule( $time );
68
+        $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
69
+        $action_id = $source->save_action( $action );
70
+        $source->mark_complete( $action_id );
71
+
72
+        $new_id = $migrator->migrate( $action_id );
73
+
74
+        // ensure we get the same record out of the new store as we stored in the old
75
+        $retrieved = $destination->fetch_action( $new_id );
76
+        $this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
77
+        $this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
78
+        $this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
79
+        $this->assertEquals( $action->get_group(), $retrieved->get_group() );
80
+        $this->assertTrue( $retrieved->is_finished() );
81
+        $this->assertEquals( \ActionScheduler_Store::STATUS_COMPLETE, $destination->get_status( $new_id ) );
82
+
83
+        // ensure that the record in the old store does not exist
84
+        $old_action = $source->fetch_action( $action_id );
85
+        $this->assertInstanceOf( 'ActionScheduler_NullAction', $old_action );
86
+    }
87
+
88
+    public function test_migrate_failed_action_from_wpPost_to_db() {
89
+        $source      = new ActionScheduler_wpPostStore();
90
+        $destination = new ActionScheduler_DBStore();
91
+        $migrator    = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
92
+
93
+        $time      = as_get_datetime_object();
94
+        $schedule  = new ActionScheduler_SimpleSchedule( $time );
95
+        $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
96
+        $action_id = $source->save_action( $action );
97
+        $source->mark_failure( $action_id );
98
+
99
+        $new_id = $migrator->migrate( $action_id );
100
+
101
+        // ensure we get the same record out of the new store as we stored in the old
102
+        $retrieved = $destination->fetch_action( $new_id );
103
+        $this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
104
+        $this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
105
+        $this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
106
+        $this->assertEquals( $action->get_group(), $retrieved->get_group() );
107
+        $this->assertTrue( $retrieved->is_finished() );
108
+        $this->assertEquals( \ActionScheduler_Store::STATUS_FAILED, $destination->get_status( $new_id ) );
109
+
110
+        // ensure that the record in the old store does not exist
111
+        $old_action = $source->fetch_action( $action_id );
112
+        $this->assertInstanceOf( 'ActionScheduler_NullAction', $old_action );
113
+    }
114
+
115
+    public function test_migrate_canceled_action_from_wpPost_to_db() {
116
+        $source      = new ActionScheduler_wpPostStore();
117
+        $destination = new ActionScheduler_DBStore();
118
+        $migrator    = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
119
+
120
+        $time      = as_get_datetime_object();
121
+        $schedule  = new ActionScheduler_SimpleSchedule( $time );
122
+        $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
123
+        $action_id = $source->save_action( $action );
124
+        $source->cancel_action( $action_id );
125
+
126
+        $new_id = $migrator->migrate( $action_id );
127
+
128
+        // ensure we get the same record out of the new store as we stored in the old
129
+        $retrieved = $destination->fetch_action( $new_id );
130
+        $this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
131
+        $this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
132
+        $this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
133
+        $this->assertEquals( $action->get_group(), $retrieved->get_group() );
134
+        $this->assertTrue( $retrieved->is_finished() );
135
+        $this->assertEquals( \ActionScheduler_Store::STATUS_CANCELED, $destination->get_status( $new_id ) );
136
+
137
+        // ensure that the record in the old store does not exist
138
+        $old_action = $source->fetch_action( $action_id );
139
+        $this->assertInstanceOf( 'ActionScheduler_NullAction', $old_action );
140
+    }
141
+
142
+    private function get_log_migrator() {
143
+        return new LogMigrator( \ActionScheduler::logger(), new ActionScheduler_DBLogger() );
144
+    }
145 145
 }
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 class ActionMigrator_Test extends ActionScheduler_UnitTestCase {
12 12
 	public function setUp() {
13 13
 		parent::setUp();
14
-		if ( ! taxonomy_exists( ActionScheduler_wpPostStore::GROUP_TAXONOMY ) ) {
14
+		if ( ! taxonomy_exists(ActionScheduler_wpPostStore::GROUP_TAXONOMY)) {
15 15
 			// register the post type and taxonomy necessary for the store to work
16 16
 			$store = new ActionScheduler_wpPostStore();
17 17
 			$store->init();
@@ -21,125 +21,125 @@  discard block
 block discarded – undo
21 21
 	public function test_migrate_from_wpPost_to_db() {
22 22
 		$source      = new ActionScheduler_wpPostStore();
23 23
 		$destination = new ActionScheduler_DBStore();
24
-		$migrator    = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
24
+		$migrator    = new ActionMigrator($source, $destination, $this->get_log_migrator());
25 25
 
26 26
 		$time      = as_get_datetime_object();
27
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
28
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
29
-		$action_id = $source->save_action( $action );
27
+		$schedule  = new ActionScheduler_SimpleSchedule($time);
28
+		$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group');
29
+		$action_id = $source->save_action($action);
30 30
 
31
-		$new_id = $migrator->migrate( $action_id );
31
+		$new_id = $migrator->migrate($action_id);
32 32
 
33 33
 		// ensure we get the same record out of the new store as we stored in the old
34
-		$retrieved = $destination->fetch_action( $new_id );
35
-		$this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
36
-		$this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
37
-		$this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
38
-		$this->assertEquals( $action->get_group(), $retrieved->get_group() );
39
-		$this->assertEquals( \ActionScheduler_Store::STATUS_PENDING, $destination->get_status( $new_id ) );
34
+		$retrieved = $destination->fetch_action($new_id);
35
+		$this->assertEquals($action->get_hook(), $retrieved->get_hook());
36
+		$this->assertEqualSets($action->get_args(), $retrieved->get_args());
37
+		$this->assertEquals($action->get_schedule()->get_date()->format('U'), $retrieved->get_schedule()->get_date()->format('U'));
38
+		$this->assertEquals($action->get_group(), $retrieved->get_group());
39
+		$this->assertEquals(\ActionScheduler_Store::STATUS_PENDING, $destination->get_status($new_id));
40 40
 
41 41
 		// ensure that the record in the old store does not exist
42
-		$old_action = $source->fetch_action( $action_id );
43
-		$this->assertInstanceOf( 'ActionScheduler_NullAction', $old_action );
42
+		$old_action = $source->fetch_action($action_id);
43
+		$this->assertInstanceOf('ActionScheduler_NullAction', $old_action);
44 44
 	}
45 45
 
46 46
 	public function test_does_not_migrate_missing_action_from_wpPost_to_db() {
47 47
 		$source      = new ActionScheduler_wpPostStore();
48 48
 		$destination = new ActionScheduler_DBStore();
49
-		$migrator    = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
49
+		$migrator    = new ActionMigrator($source, $destination, $this->get_log_migrator());
50 50
 
51
-		$action_id = rand( 100, 100000 );
51
+		$action_id = rand(100, 100000);
52 52
 
53
-		$new_id = $migrator->migrate( $action_id );
54
-		$this->assertSame( 0, $new_id );
53
+		$new_id = $migrator->migrate($action_id);
54
+		$this->assertSame(0, $new_id);
55 55
 
56 56
 		// ensure we get the same record out of the new store as we stored in the old
57
-		$retrieved = $destination->fetch_action( $new_id );
58
-		$this->assertInstanceOf( 'ActionScheduler_NullAction', $retrieved );
57
+		$retrieved = $destination->fetch_action($new_id);
58
+		$this->assertInstanceOf('ActionScheduler_NullAction', $retrieved);
59 59
 	}
60 60
 
61 61
 	public function test_migrate_completed_action_from_wpPost_to_db() {
62 62
 		$source      = new ActionScheduler_wpPostStore();
63 63
 		$destination = new ActionScheduler_DBStore();
64
-		$migrator    = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
64
+		$migrator    = new ActionMigrator($source, $destination, $this->get_log_migrator());
65 65
 
66 66
 		$time      = as_get_datetime_object();
67
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
68
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
69
-		$action_id = $source->save_action( $action );
70
-		$source->mark_complete( $action_id );
67
+		$schedule  = new ActionScheduler_SimpleSchedule($time);
68
+		$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group');
69
+		$action_id = $source->save_action($action);
70
+		$source->mark_complete($action_id);
71 71
 
72
-		$new_id = $migrator->migrate( $action_id );
72
+		$new_id = $migrator->migrate($action_id);
73 73
 
74 74
 		// ensure we get the same record out of the new store as we stored in the old
75
-		$retrieved = $destination->fetch_action( $new_id );
76
-		$this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
77
-		$this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
78
-		$this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
79
-		$this->assertEquals( $action->get_group(), $retrieved->get_group() );
80
-		$this->assertTrue( $retrieved->is_finished() );
81
-		$this->assertEquals( \ActionScheduler_Store::STATUS_COMPLETE, $destination->get_status( $new_id ) );
75
+		$retrieved = $destination->fetch_action($new_id);
76
+		$this->assertEquals($action->get_hook(), $retrieved->get_hook());
77
+		$this->assertEqualSets($action->get_args(), $retrieved->get_args());
78
+		$this->assertEquals($action->get_schedule()->get_date()->format('U'), $retrieved->get_schedule()->get_date()->format('U'));
79
+		$this->assertEquals($action->get_group(), $retrieved->get_group());
80
+		$this->assertTrue($retrieved->is_finished());
81
+		$this->assertEquals(\ActionScheduler_Store::STATUS_COMPLETE, $destination->get_status($new_id));
82 82
 
83 83
 		// ensure that the record in the old store does not exist
84
-		$old_action = $source->fetch_action( $action_id );
85
-		$this->assertInstanceOf( 'ActionScheduler_NullAction', $old_action );
84
+		$old_action = $source->fetch_action($action_id);
85
+		$this->assertInstanceOf('ActionScheduler_NullAction', $old_action);
86 86
 	}
87 87
 
88 88
 	public function test_migrate_failed_action_from_wpPost_to_db() {
89 89
 		$source      = new ActionScheduler_wpPostStore();
90 90
 		$destination = new ActionScheduler_DBStore();
91
-		$migrator    = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
91
+		$migrator    = new ActionMigrator($source, $destination, $this->get_log_migrator());
92 92
 
93 93
 		$time      = as_get_datetime_object();
94
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
95
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
96
-		$action_id = $source->save_action( $action );
97
-		$source->mark_failure( $action_id );
94
+		$schedule  = new ActionScheduler_SimpleSchedule($time);
95
+		$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group');
96
+		$action_id = $source->save_action($action);
97
+		$source->mark_failure($action_id);
98 98
 
99
-		$new_id = $migrator->migrate( $action_id );
99
+		$new_id = $migrator->migrate($action_id);
100 100
 
101 101
 		// ensure we get the same record out of the new store as we stored in the old
102
-		$retrieved = $destination->fetch_action( $new_id );
103
-		$this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
104
-		$this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
105
-		$this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
106
-		$this->assertEquals( $action->get_group(), $retrieved->get_group() );
107
-		$this->assertTrue( $retrieved->is_finished() );
108
-		$this->assertEquals( \ActionScheduler_Store::STATUS_FAILED, $destination->get_status( $new_id ) );
102
+		$retrieved = $destination->fetch_action($new_id);
103
+		$this->assertEquals($action->get_hook(), $retrieved->get_hook());
104
+		$this->assertEqualSets($action->get_args(), $retrieved->get_args());
105
+		$this->assertEquals($action->get_schedule()->get_date()->format('U'), $retrieved->get_schedule()->get_date()->format('U'));
106
+		$this->assertEquals($action->get_group(), $retrieved->get_group());
107
+		$this->assertTrue($retrieved->is_finished());
108
+		$this->assertEquals(\ActionScheduler_Store::STATUS_FAILED, $destination->get_status($new_id));
109 109
 
110 110
 		// ensure that the record in the old store does not exist
111
-		$old_action = $source->fetch_action( $action_id );
112
-		$this->assertInstanceOf( 'ActionScheduler_NullAction', $old_action );
111
+		$old_action = $source->fetch_action($action_id);
112
+		$this->assertInstanceOf('ActionScheduler_NullAction', $old_action);
113 113
 	}
114 114
 
115 115
 	public function test_migrate_canceled_action_from_wpPost_to_db() {
116 116
 		$source      = new ActionScheduler_wpPostStore();
117 117
 		$destination = new ActionScheduler_DBStore();
118
-		$migrator    = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
118
+		$migrator    = new ActionMigrator($source, $destination, $this->get_log_migrator());
119 119
 
120 120
 		$time      = as_get_datetime_object();
121
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
122
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
123
-		$action_id = $source->save_action( $action );
124
-		$source->cancel_action( $action_id );
121
+		$schedule  = new ActionScheduler_SimpleSchedule($time);
122
+		$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group');
123
+		$action_id = $source->save_action($action);
124
+		$source->cancel_action($action_id);
125 125
 
126
-		$new_id = $migrator->migrate( $action_id );
126
+		$new_id = $migrator->migrate($action_id);
127 127
 
128 128
 		// ensure we get the same record out of the new store as we stored in the old
129
-		$retrieved = $destination->fetch_action( $new_id );
130
-		$this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
131
-		$this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
132
-		$this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
133
-		$this->assertEquals( $action->get_group(), $retrieved->get_group() );
134
-		$this->assertTrue( $retrieved->is_finished() );
135
-		$this->assertEquals( \ActionScheduler_Store::STATUS_CANCELED, $destination->get_status( $new_id ) );
129
+		$retrieved = $destination->fetch_action($new_id);
130
+		$this->assertEquals($action->get_hook(), $retrieved->get_hook());
131
+		$this->assertEqualSets($action->get_args(), $retrieved->get_args());
132
+		$this->assertEquals($action->get_schedule()->get_date()->format('U'), $retrieved->get_schedule()->get_date()->format('U'));
133
+		$this->assertEquals($action->get_group(), $retrieved->get_group());
134
+		$this->assertTrue($retrieved->is_finished());
135
+		$this->assertEquals(\ActionScheduler_Store::STATUS_CANCELED, $destination->get_status($new_id));
136 136
 
137 137
 		// ensure that the record in the old store does not exist
138
-		$old_action = $source->fetch_action( $action_id );
139
-		$this->assertInstanceOf( 'ActionScheduler_NullAction', $old_action );
138
+		$old_action = $source->fetch_action($action_id);
139
+		$this->assertInstanceOf('ActionScheduler_NullAction', $old_action);
140 140
 	}
141 141
 
142 142
 	private function get_log_migrator() {
143
-		return new LogMigrator( \ActionScheduler::logger(), new ActionScheduler_DBLogger() );
143
+		return new LogMigrator(\ActionScheduler::logger(), new ActionScheduler_DBLogger());
144 144
 	}
145 145
 }
Please login to merge, or discard this patch.
src/ext/action-scheduler/tests/phpunit/migration/LogMigrator_Test.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -8,46 +8,46 @@
 block discarded – undo
8 8
  * @group migration
9 9
  */
10 10
 class LogMigrator_Test extends ActionScheduler_UnitTestCase {
11
-	function setUp() {
12
-		parent::setUp();
13
-		if ( ! taxonomy_exists( ActionScheduler_wpPostStore::GROUP_TAXONOMY ) ) {
14
-			// register the post type and taxonomy necessary for the store to work
15
-			$store = new ActionScheduler_wpPostStore();
16
-			$store->init();
17
-		}
18
-	}
11
+    function setUp() {
12
+        parent::setUp();
13
+        if ( ! taxonomy_exists( ActionScheduler_wpPostStore::GROUP_TAXONOMY ) ) {
14
+            // register the post type and taxonomy necessary for the store to work
15
+            $store = new ActionScheduler_wpPostStore();
16
+            $store->init();
17
+        }
18
+    }
19 19
 
20
-	public function test_migrate_from_wpComment_to_db() {
21
-		$source                = new ActionScheduler_wpCommentLogger();
22
-		$destination           = new ActionScheduler_DBLogger();
23
-		$migrator              = new LogMigrator( $source, $destination );
24
-		$source_action_id      = rand( 10, 10000 );
25
-		$destination_action_id = rand( 10, 10000 );
20
+    public function test_migrate_from_wpComment_to_db() {
21
+        $source                = new ActionScheduler_wpCommentLogger();
22
+        $destination           = new ActionScheduler_DBLogger();
23
+        $migrator              = new LogMigrator( $source, $destination );
24
+        $source_action_id      = rand( 10, 10000 );
25
+        $destination_action_id = rand( 10, 10000 );
26 26
 
27
-		$logs = array();
28
-		for ( $i = 0; $i < 3; $i++ ) {
29
-			for ( $j = 0; $j < 5; $j++ ) {
30
-				$logs[ $i ][ $j ] = md5( rand() );
31
-				if ( $i == 1 ) {
32
-					$source->log( $source_action_id, $logs[ $i ][ $j ] );
33
-				}
34
-			}
35
-		}
27
+        $logs = array();
28
+        for ( $i = 0; $i < 3; $i++ ) {
29
+            for ( $j = 0; $j < 5; $j++ ) {
30
+                $logs[ $i ][ $j ] = md5( rand() );
31
+                if ( $i == 1 ) {
32
+                    $source->log( $source_action_id, $logs[ $i ][ $j ] );
33
+                }
34
+            }
35
+        }
36 36
 
37
-		$migrator->migrate( $source_action_id, $destination_action_id );
37
+        $migrator->migrate( $source_action_id, $destination_action_id );
38 38
 
39
-		$migrated = $destination->get_logs( $destination_action_id );
40
-		$this->assertEqualSets(
41
-			$logs[1],
42
-			array_map(
43
-				function ( $log ) {
44
-					return $log->get_message();
45
-				},
46
-				$migrated
47
-			)
48
-		);
39
+        $migrated = $destination->get_logs( $destination_action_id );
40
+        $this->assertEqualSets(
41
+            $logs[1],
42
+            array_map(
43
+                function ( $log ) {
44
+                    return $log->get_message();
45
+                },
46
+                $migrated
47
+            )
48
+        );
49 49
 
50
-		// no API for deleting logs, so we leave them for manual cleanup later
51
-		$this->assertCount( 5, $source->get_logs( $source_action_id ) );
52
-	}
50
+        // no API for deleting logs, so we leave them for manual cleanup later
51
+        $this->assertCount( 5, $source->get_logs( $source_action_id ) );
52
+    }
53 53
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 class LogMigrator_Test extends ActionScheduler_UnitTestCase {
11 11
 	function setUp() {
12 12
 		parent::setUp();
13
-		if ( ! taxonomy_exists( ActionScheduler_wpPostStore::GROUP_TAXONOMY ) ) {
13
+		if ( ! taxonomy_exists(ActionScheduler_wpPostStore::GROUP_TAXONOMY)) {
14 14
 			// register the post type and taxonomy necessary for the store to work
15 15
 			$store = new ActionScheduler_wpPostStore();
16 16
 			$store->init();
@@ -20,27 +20,27 @@  discard block
 block discarded – undo
20 20
 	public function test_migrate_from_wpComment_to_db() {
21 21
 		$source                = new ActionScheduler_wpCommentLogger();
22 22
 		$destination           = new ActionScheduler_DBLogger();
23
-		$migrator              = new LogMigrator( $source, $destination );
24
-		$source_action_id      = rand( 10, 10000 );
25
-		$destination_action_id = rand( 10, 10000 );
23
+		$migrator              = new LogMigrator($source, $destination);
24
+		$source_action_id      = rand(10, 10000);
25
+		$destination_action_id = rand(10, 10000);
26 26
 
27 27
 		$logs = array();
28
-		for ( $i = 0; $i < 3; $i++ ) {
29
-			for ( $j = 0; $j < 5; $j++ ) {
30
-				$logs[ $i ][ $j ] = md5( rand() );
31
-				if ( $i == 1 ) {
32
-					$source->log( $source_action_id, $logs[ $i ][ $j ] );
28
+		for ($i = 0; $i < 3; $i++) {
29
+			for ($j = 0; $j < 5; $j++) {
30
+				$logs[$i][$j] = md5(rand());
31
+				if ($i == 1) {
32
+					$source->log($source_action_id, $logs[$i][$j]);
33 33
 				}
34 34
 			}
35 35
 		}
36 36
 
37
-		$migrator->migrate( $source_action_id, $destination_action_id );
37
+		$migrator->migrate($source_action_id, $destination_action_id);
38 38
 
39
-		$migrated = $destination->get_logs( $destination_action_id );
39
+		$migrated = $destination->get_logs($destination_action_id);
40 40
 		$this->assertEqualSets(
41 41
 			$logs[1],
42 42
 			array_map(
43
-				function ( $log ) {
43
+				function($log) {
44 44
 					return $log->get_message();
45 45
 				},
46 46
 				$migrated
@@ -48,6 +48,6 @@  discard block
 block discarded – undo
48 48
 		);
49 49
 
50 50
 		// no API for deleting logs, so we leave them for manual cleanup later
51
-		$this->assertCount( 5, $source->get_logs( $source_action_id ) );
51
+		$this->assertCount(5, $source->get_logs($source_action_id));
52 52
 	}
53 53
 }
Please login to merge, or discard this patch.
src/ext/action-scheduler/tests/phpunit/migration/Runner_Test.php 2 patches
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -11,110 +11,110 @@
 block discarded – undo
11 11
  * @group migration
12 12
  */
13 13
 class Runner_Test extends ActionScheduler_UnitTestCase {
14
-	public function setUp() {
15
-		parent::setUp();
16
-		if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) {
17
-			// register the post type and taxonomy necessary for the store to work
18
-			$store = new PostStore();
19
-			$store->init();
20
-		}
21
-	}
22
-
23
-	public function test_migrate_batches() {
24
-		$source_store       = new PostStore();
25
-		$destination_store  = new ActionScheduler_DBStore();
26
-		$source_logger      = new CommentLogger();
27
-		$destination_logger = new ActionScheduler_DBLogger();
28
-
29
-		$config = new Config();
30
-		$config->set_source_store( $source_store );
31
-		$config->set_source_logger( $source_logger );
32
-		$config->set_destination_store( $destination_store );
33
-		$config->set_destination_logger( $destination_logger );
34
-
35
-		$runner = new Runner( $config );
36
-
37
-		$due      = array();
38
-		$future   = array();
39
-		$complete = array();
40
-
41
-		for ( $i = 0; $i < 5; $i ++ ) {
42
-			$time     = as_get_datetime_object( $i + 1 . ' minutes' );
43
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
44
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
45
-			$future[] = $source_store->save_action( $action );
46
-
47
-			$time     = as_get_datetime_object( $i + 1 . ' minutes ago' );
48
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
49
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
50
-			$due[]    = $source_store->save_action( $action );
51
-
52
-			$time       = as_get_datetime_object( $i + 1 . ' minutes ago' );
53
-			$schedule   = new ActionScheduler_SimpleSchedule( $time );
54
-			$action     = new ActionScheduler_FinishedAction( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
55
-			$complete[] = $source_store->save_action( $action );
56
-		}
57
-
58
-		$created = $source_store->query_actions( array( 'per_page' => 0 ) );
59
-		$this->assertCount( 15, $created );
60
-
61
-		$runner->run( 10 );
62
-
63
-		// due actions should migrate in the first batch
64
-		$migrated = $destination_store->query_actions(
65
-			array(
66
-				'per_page' => 0,
67
-				'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
68
-			)
69
-		);
70
-		$this->assertCount( 5, $migrated );
71
-
72
-		$remaining = $source_store->query_actions(
73
-			array(
74
-				'per_page' => 0,
75
-				'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
76
-			)
77
-		);
78
-		$this->assertCount( 10, $remaining );
79
-
80
-		$runner->run( 10 );
81
-
82
-		// pending actions should migrate in the second batch
83
-		$migrated = $destination_store->query_actions(
84
-			array(
85
-				'per_page' => 0,
86
-				'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
87
-			)
88
-		);
89
-		$this->assertCount( 10, $migrated );
90
-
91
-		$remaining = $source_store->query_actions(
92
-			array(
93
-				'per_page' => 0,
94
-				'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
95
-			)
96
-		);
97
-		$this->assertCount( 5, $remaining );
98
-
99
-		$runner->run( 10 );
100
-
101
-		// completed actions should migrate in the third batch
102
-		$migrated = $destination_store->query_actions(
103
-			array(
104
-				'per_page' => 0,
105
-				'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
106
-			)
107
-		);
108
-		$this->assertCount( 15, $migrated );
109
-
110
-		$remaining = $source_store->query_actions(
111
-			array(
112
-				'per_page' => 0,
113
-				'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
114
-			)
115
-		);
116
-		$this->assertCount( 0, $remaining );
117
-
118
-	}
14
+    public function setUp() {
15
+        parent::setUp();
16
+        if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) {
17
+            // register the post type and taxonomy necessary for the store to work
18
+            $store = new PostStore();
19
+            $store->init();
20
+        }
21
+    }
22
+
23
+    public function test_migrate_batches() {
24
+        $source_store       = new PostStore();
25
+        $destination_store  = new ActionScheduler_DBStore();
26
+        $source_logger      = new CommentLogger();
27
+        $destination_logger = new ActionScheduler_DBLogger();
28
+
29
+        $config = new Config();
30
+        $config->set_source_store( $source_store );
31
+        $config->set_source_logger( $source_logger );
32
+        $config->set_destination_store( $destination_store );
33
+        $config->set_destination_logger( $destination_logger );
34
+
35
+        $runner = new Runner( $config );
36
+
37
+        $due      = array();
38
+        $future   = array();
39
+        $complete = array();
40
+
41
+        for ( $i = 0; $i < 5; $i ++ ) {
42
+            $time     = as_get_datetime_object( $i + 1 . ' minutes' );
43
+            $schedule = new ActionScheduler_SimpleSchedule( $time );
44
+            $action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
45
+            $future[] = $source_store->save_action( $action );
46
+
47
+            $time     = as_get_datetime_object( $i + 1 . ' minutes ago' );
48
+            $schedule = new ActionScheduler_SimpleSchedule( $time );
49
+            $action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
50
+            $due[]    = $source_store->save_action( $action );
51
+
52
+            $time       = as_get_datetime_object( $i + 1 . ' minutes ago' );
53
+            $schedule   = new ActionScheduler_SimpleSchedule( $time );
54
+            $action     = new ActionScheduler_FinishedAction( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
55
+            $complete[] = $source_store->save_action( $action );
56
+        }
57
+
58
+        $created = $source_store->query_actions( array( 'per_page' => 0 ) );
59
+        $this->assertCount( 15, $created );
60
+
61
+        $runner->run( 10 );
62
+
63
+        // due actions should migrate in the first batch
64
+        $migrated = $destination_store->query_actions(
65
+            array(
66
+                'per_page' => 0,
67
+                'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
68
+            )
69
+        );
70
+        $this->assertCount( 5, $migrated );
71
+
72
+        $remaining = $source_store->query_actions(
73
+            array(
74
+                'per_page' => 0,
75
+                'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
76
+            )
77
+        );
78
+        $this->assertCount( 10, $remaining );
79
+
80
+        $runner->run( 10 );
81
+
82
+        // pending actions should migrate in the second batch
83
+        $migrated = $destination_store->query_actions(
84
+            array(
85
+                'per_page' => 0,
86
+                'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
87
+            )
88
+        );
89
+        $this->assertCount( 10, $migrated );
90
+
91
+        $remaining = $source_store->query_actions(
92
+            array(
93
+                'per_page' => 0,
94
+                'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
95
+            )
96
+        );
97
+        $this->assertCount( 5, $remaining );
98
+
99
+        $runner->run( 10 );
100
+
101
+        // completed actions should migrate in the third batch
102
+        $migrated = $destination_store->query_actions(
103
+            array(
104
+                'per_page' => 0,
105
+                'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
106
+            )
107
+        );
108
+        $this->assertCount( 15, $migrated );
109
+
110
+        $remaining = $source_store->query_actions(
111
+            array(
112
+                'per_page' => 0,
113
+                'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
114
+            )
115
+        );
116
+        $this->assertCount( 0, $remaining );
117
+
118
+    }
119 119
 
120 120
 }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 class Runner_Test extends ActionScheduler_UnitTestCase {
14 14
 	public function setUp() {
15 15
 		parent::setUp();
16
-		if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) {
16
+		if ( ! taxonomy_exists(PostStore::GROUP_TAXONOMY)) {
17 17
 			// register the post type and taxonomy necessary for the store to work
18 18
 			$store = new PostStore();
19 19
 			$store->init();
@@ -27,38 +27,38 @@  discard block
 block discarded – undo
27 27
 		$destination_logger = new ActionScheduler_DBLogger();
28 28
 
29 29
 		$config = new Config();
30
-		$config->set_source_store( $source_store );
31
-		$config->set_source_logger( $source_logger );
32
-		$config->set_destination_store( $destination_store );
33
-		$config->set_destination_logger( $destination_logger );
30
+		$config->set_source_store($source_store);
31
+		$config->set_source_logger($source_logger);
32
+		$config->set_destination_store($destination_store);
33
+		$config->set_destination_logger($destination_logger);
34 34
 
35
-		$runner = new Runner( $config );
35
+		$runner = new Runner($config);
36 36
 
37 37
 		$due      = array();
38 38
 		$future   = array();
39 39
 		$complete = array();
40 40
 
41
-		for ( $i = 0; $i < 5; $i ++ ) {
42
-			$time     = as_get_datetime_object( $i + 1 . ' minutes' );
43
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
44
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
45
-			$future[] = $source_store->save_action( $action );
46
-
47
-			$time     = as_get_datetime_object( $i + 1 . ' minutes ago' );
48
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
49
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
50
-			$due[]    = $source_store->save_action( $action );
51
-
52
-			$time       = as_get_datetime_object( $i + 1 . ' minutes ago' );
53
-			$schedule   = new ActionScheduler_SimpleSchedule( $time );
54
-			$action     = new ActionScheduler_FinishedAction( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
55
-			$complete[] = $source_store->save_action( $action );
41
+		for ($i = 0; $i < 5; $i++) {
42
+			$time     = as_get_datetime_object($i + 1.' minutes');
43
+			$schedule = new ActionScheduler_SimpleSchedule($time);
44
+			$action   = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
45
+			$future[] = $source_store->save_action($action);
46
+
47
+			$time     = as_get_datetime_object($i + 1.' minutes ago');
48
+			$schedule = new ActionScheduler_SimpleSchedule($time);
49
+			$action   = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
50
+			$due[]    = $source_store->save_action($action);
51
+
52
+			$time       = as_get_datetime_object($i + 1.' minutes ago');
53
+			$schedule   = new ActionScheduler_SimpleSchedule($time);
54
+			$action     = new ActionScheduler_FinishedAction(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
55
+			$complete[] = $source_store->save_action($action);
56 56
 		}
57 57
 
58
-		$created = $source_store->query_actions( array( 'per_page' => 0 ) );
59
-		$this->assertCount( 15, $created );
58
+		$created = $source_store->query_actions(array('per_page' => 0));
59
+		$this->assertCount(15, $created);
60 60
 
61
-		$runner->run( 10 );
61
+		$runner->run(10);
62 62
 
63 63
 		// due actions should migrate in the first batch
64 64
 		$migrated = $destination_store->query_actions(
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 				'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
68 68
 			)
69 69
 		);
70
-		$this->assertCount( 5, $migrated );
70
+		$this->assertCount(5, $migrated);
71 71
 
72 72
 		$remaining = $source_store->query_actions(
73 73
 			array(
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
 				'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
76 76
 			)
77 77
 		);
78
-		$this->assertCount( 10, $remaining );
78
+		$this->assertCount(10, $remaining);
79 79
 
80
-		$runner->run( 10 );
80
+		$runner->run(10);
81 81
 
82 82
 		// pending actions should migrate in the second batch
83 83
 		$migrated = $destination_store->query_actions(
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 				'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
87 87
 			)
88 88
 		);
89
-		$this->assertCount( 10, $migrated );
89
+		$this->assertCount(10, $migrated);
90 90
 
91 91
 		$remaining = $source_store->query_actions(
92 92
 			array(
@@ -94,9 +94,9 @@  discard block
 block discarded – undo
94 94
 				'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
95 95
 			)
96 96
 		);
97
-		$this->assertCount( 5, $remaining );
97
+		$this->assertCount(5, $remaining);
98 98
 
99
-		$runner->run( 10 );
99
+		$runner->run(10);
100 100
 
101 101
 		// completed actions should migrate in the third batch
102 102
 		$migrated = $destination_store->query_actions(
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 				'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
106 106
 			)
107 107
 		);
108
-		$this->assertCount( 15, $migrated );
108
+		$this->assertCount(15, $migrated);
109 109
 
110 110
 		$remaining = $source_store->query_actions(
111 111
 			array(
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 				'hook'     => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
114 114
 			)
115 115
 		);
116
-		$this->assertCount( 0, $remaining );
116
+		$this->assertCount(0, $remaining);
117 117
 
118 118
 	}
119 119
 
Please login to merge, or discard this patch.
src/ext/action-scheduler/tests/phpunit/migration/BatchFetcher_Test.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -9,68 +9,68 @@
 block discarded – undo
9 9
  * @group migration
10 10
  */
11 11
 class BatchFetcher_Test extends ActionScheduler_UnitTestCase {
12
-	public function setUp() {
13
-		parent::setUp();
14
-		if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) {
15
-			// register the post type and taxonomy necessary for the store to work
16
-			$store = new PostStore();
17
-			$store->init();
18
-		}
19
-	}
20
-
21
-	public function test_nothing_to_migrate() {
22
-		$store         = new PostStore();
23
-		$batch_fetcher = new BatchFetcher( $store );
24
-
25
-		$actions = $batch_fetcher->fetch();
26
-		$this->assertEmpty( $actions );
27
-	}
28
-
29
-	public function test_get_due_before_future() {
30
-		$store  = new PostStore();
31
-		$due    = array();
32
-		$future = array();
33
-
34
-		for ( $i = 0; $i < 5; $i ++ ) {
35
-			$time     = as_get_datetime_object( $i + 1 . ' minutes' );
36
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
37
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
38
-			$future[] = $store->save_action( $action );
39
-
40
-			$time     = as_get_datetime_object( $i + 1 . ' minutes ago' );
41
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
42
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
43
-			$due[]    = $store->save_action( $action );
44
-		}
45
-
46
-		$batch_fetcher = new BatchFetcher( $store );
47
-
48
-		$actions = $batch_fetcher->fetch();
49
-
50
-		$this->assertEqualSets( $due, $actions );
51
-	}
52
-
53
-	public function test_get_future_before_complete() {
54
-		$store    = new PostStore();
55
-		$future   = array();
56
-		$complete = array();
57
-
58
-		for ( $i = 0; $i < 5; $i ++ ) {
59
-			$time     = as_get_datetime_object( $i + 1 . ' minutes' );
60
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
61
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
62
-			$future[] = $store->save_action( $action );
63
-
64
-			$time       = as_get_datetime_object( $i + 1 . ' minutes ago' );
65
-			$schedule   = new ActionScheduler_SimpleSchedule( $time );
66
-			$action     = new ActionScheduler_FinishedAction( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
67
-			$complete[] = $store->save_action( $action );
68
-		}
69
-
70
-		$batch_fetcher = new BatchFetcher( $store );
71
-
72
-		$actions = $batch_fetcher->fetch();
73
-
74
-		$this->assertEqualSets( $future, $actions );
75
-	}
12
+    public function setUp() {
13
+        parent::setUp();
14
+        if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) {
15
+            // register the post type and taxonomy necessary for the store to work
16
+            $store = new PostStore();
17
+            $store->init();
18
+        }
19
+    }
20
+
21
+    public function test_nothing_to_migrate() {
22
+        $store         = new PostStore();
23
+        $batch_fetcher = new BatchFetcher( $store );
24
+
25
+        $actions = $batch_fetcher->fetch();
26
+        $this->assertEmpty( $actions );
27
+    }
28
+
29
+    public function test_get_due_before_future() {
30
+        $store  = new PostStore();
31
+        $due    = array();
32
+        $future = array();
33
+
34
+        for ( $i = 0; $i < 5; $i ++ ) {
35
+            $time     = as_get_datetime_object( $i + 1 . ' minutes' );
36
+            $schedule = new ActionScheduler_SimpleSchedule( $time );
37
+            $action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
38
+            $future[] = $store->save_action( $action );
39
+
40
+            $time     = as_get_datetime_object( $i + 1 . ' minutes ago' );
41
+            $schedule = new ActionScheduler_SimpleSchedule( $time );
42
+            $action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
43
+            $due[]    = $store->save_action( $action );
44
+        }
45
+
46
+        $batch_fetcher = new BatchFetcher( $store );
47
+
48
+        $actions = $batch_fetcher->fetch();
49
+
50
+        $this->assertEqualSets( $due, $actions );
51
+    }
52
+
53
+    public function test_get_future_before_complete() {
54
+        $store    = new PostStore();
55
+        $future   = array();
56
+        $complete = array();
57
+
58
+        for ( $i = 0; $i < 5; $i ++ ) {
59
+            $time     = as_get_datetime_object( $i + 1 . ' minutes' );
60
+            $schedule = new ActionScheduler_SimpleSchedule( $time );
61
+            $action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
62
+            $future[] = $store->save_action( $action );
63
+
64
+            $time       = as_get_datetime_object( $i + 1 . ' minutes ago' );
65
+            $schedule   = new ActionScheduler_SimpleSchedule( $time );
66
+            $action     = new ActionScheduler_FinishedAction( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
67
+            $complete[] = $store->save_action( $action );
68
+        }
69
+
70
+        $batch_fetcher = new BatchFetcher( $store );
71
+
72
+        $actions = $batch_fetcher->fetch();
73
+
74
+        $this->assertEqualSets( $future, $actions );
75
+    }
76 76
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 class BatchFetcher_Test extends ActionScheduler_UnitTestCase {
12 12
 	public function setUp() {
13 13
 		parent::setUp();
14
-		if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) {
14
+		if ( ! taxonomy_exists(PostStore::GROUP_TAXONOMY)) {
15 15
 			// register the post type and taxonomy necessary for the store to work
16 16
 			$store = new PostStore();
17 17
 			$store->init();
@@ -20,10 +20,10 @@  discard block
 block discarded – undo
20 20
 
21 21
 	public function test_nothing_to_migrate() {
22 22
 		$store         = new PostStore();
23
-		$batch_fetcher = new BatchFetcher( $store );
23
+		$batch_fetcher = new BatchFetcher($store);
24 24
 
25 25
 		$actions = $batch_fetcher->fetch();
26
-		$this->assertEmpty( $actions );
26
+		$this->assertEmpty($actions);
27 27
 	}
28 28
 
29 29
 	public function test_get_due_before_future() {
@@ -31,23 +31,23 @@  discard block
 block discarded – undo
31 31
 		$due    = array();
32 32
 		$future = array();
33 33
 
34
-		for ( $i = 0; $i < 5; $i ++ ) {
35
-			$time     = as_get_datetime_object( $i + 1 . ' minutes' );
36
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
37
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
38
-			$future[] = $store->save_action( $action );
34
+		for ($i = 0; $i < 5; $i++) {
35
+			$time     = as_get_datetime_object($i + 1.' minutes');
36
+			$schedule = new ActionScheduler_SimpleSchedule($time);
37
+			$action   = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
38
+			$future[] = $store->save_action($action);
39 39
 
40
-			$time     = as_get_datetime_object( $i + 1 . ' minutes ago' );
41
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
42
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
43
-			$due[]    = $store->save_action( $action );
40
+			$time     = as_get_datetime_object($i + 1.' minutes ago');
41
+			$schedule = new ActionScheduler_SimpleSchedule($time);
42
+			$action   = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
43
+			$due[]    = $store->save_action($action);
44 44
 		}
45 45
 
46
-		$batch_fetcher = new BatchFetcher( $store );
46
+		$batch_fetcher = new BatchFetcher($store);
47 47
 
48 48
 		$actions = $batch_fetcher->fetch();
49 49
 
50
-		$this->assertEqualSets( $due, $actions );
50
+		$this->assertEqualSets($due, $actions);
51 51
 	}
52 52
 
53 53
 	public function test_get_future_before_complete() {
@@ -55,22 +55,22 @@  discard block
 block discarded – undo
55 55
 		$future   = array();
56 56
 		$complete = array();
57 57
 
58
-		for ( $i = 0; $i < 5; $i ++ ) {
59
-			$time     = as_get_datetime_object( $i + 1 . ' minutes' );
60
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
61
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
62
-			$future[] = $store->save_action( $action );
58
+		for ($i = 0; $i < 5; $i++) {
59
+			$time     = as_get_datetime_object($i + 1.' minutes');
60
+			$schedule = new ActionScheduler_SimpleSchedule($time);
61
+			$action   = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
62
+			$future[] = $store->save_action($action);
63 63
 
64
-			$time       = as_get_datetime_object( $i + 1 . ' minutes ago' );
65
-			$schedule   = new ActionScheduler_SimpleSchedule( $time );
66
-			$action     = new ActionScheduler_FinishedAction( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
67
-			$complete[] = $store->save_action( $action );
64
+			$time       = as_get_datetime_object($i + 1.' minutes ago');
65
+			$schedule   = new ActionScheduler_SimpleSchedule($time);
66
+			$action     = new ActionScheduler_FinishedAction(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
67
+			$complete[] = $store->save_action($action);
68 68
 		}
69 69
 
70
-		$batch_fetcher = new BatchFetcher( $store );
70
+		$batch_fetcher = new BatchFetcher($store);
71 71
 
72 72
 		$actions = $batch_fetcher->fetch();
73 73
 
74
-		$this->assertEqualSets( $future, $actions );
74
+		$this->assertEqualSets($future, $actions);
75 75
 	}
76 76
 }
Please login to merge, or discard this patch.
action-scheduler/tests/phpunit/jobstore/ActionScheduler_DBStore_Test.php 2 patches
Indentation   +546 added lines, -546 removed lines patch added patch discarded remove patch
@@ -9,550 +9,550 @@
 block discarded – undo
9 9
  */
10 10
 class ActionScheduler_DBStore_Test extends AbstractStoreTest {
11 11
 
12
-	public function setUp() {
13
-		global $wpdb;
14
-
15
-		// Delete all actions before each test.
16
-		$wpdb->query( "DELETE FROM {$wpdb->actionscheduler_actions}" );
17
-
18
-		parent::setUp();
19
-	}
20
-
21
-	/**
22
-	 * Get data store for tests.
23
-	 *
24
-	 * @return ActionScheduler_DBStore
25
-	 */
26
-	protected function get_store() {
27
-		return new ActionScheduler_DBStore();
28
-	}
29
-
30
-	public function test_create_action() {
31
-		$time      = as_get_datetime_object();
32
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
33
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
34
-		$store     = new ActionScheduler_DBStore();
35
-		$action_id = $store->save_action( $action );
36
-
37
-		$this->assertNotEmpty( $action_id );
38
-	}
39
-
40
-	public function test_create_action_with_scheduled_date() {
41
-		$time        = as_get_datetime_object( strtotime( '-1 week' ) );
42
-		$action      = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), new ActionScheduler_SimpleSchedule( $time ) );
43
-		$store       = new ActionScheduler_DBStore();
44
-		$action_id   = $store->save_action( $action, $time );
45
-		$action_date = $store->get_date( $action_id );
46
-
47
-		$this->assertEquals( $time->format( 'U' ), $action_date->format( 'U' ) );
48
-	}
49
-
50
-	public function test_retrieve_action() {
51
-		$time      = as_get_datetime_object();
52
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
53
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
54
-		$store     = new ActionScheduler_DBStore();
55
-		$action_id = $store->save_action( $action );
56
-
57
-		$retrieved = $store->fetch_action( $action_id );
58
-		$this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
59
-		$this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
60
-		$this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
61
-		$this->assertEquals( $action->get_group(), $retrieved->get_group() );
62
-	}
63
-
64
-	public function test_cancel_action() {
65
-		$time      = as_get_datetime_object();
66
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
67
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
68
-		$store     = new ActionScheduler_DBStore();
69
-		$action_id = $store->save_action( $action );
70
-		$store->cancel_action( $action_id );
71
-
72
-		$fetched = $store->fetch_action( $action_id );
73
-		$this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
74
-	}
75
-
76
-	public function test_cancel_actions_by_hook() {
77
-		$store   = new ActionScheduler_DBStore();
78
-		$actions = array();
79
-		$hook    = 'by_hook_test';
80
-		for ( $day = 1; $day <= 3; $day++ ) {
81
-			$delta     = sprintf( '+%d day', $day );
82
-			$time      = as_get_datetime_object( $delta );
83
-			$schedule  = new ActionScheduler_SimpleSchedule( $time );
84
-			$action    = new ActionScheduler_Action( $hook, array(), $schedule, 'my_group' );
85
-			$actions[] = $store->save_action( $action );
86
-		}
87
-		$store->cancel_actions_by_hook( $hook );
88
-
89
-		foreach ( $actions as $action_id ) {
90
-			$fetched = $store->fetch_action( $action_id );
91
-			$this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
92
-		}
93
-	}
94
-
95
-	public function test_cancel_actions_by_group() {
96
-		$store   = new ActionScheduler_DBStore();
97
-		$actions = array();
98
-		$group   = 'by_group_test';
99
-		for ( $day = 1; $day <= 3; $day++ ) {
100
-			$delta     = sprintf( '+%d day', $day );
101
-			$time      = as_get_datetime_object( $delta );
102
-			$schedule  = new ActionScheduler_SimpleSchedule( $time );
103
-			$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, $group );
104
-			$actions[] = $store->save_action( $action );
105
-		}
106
-		$store->cancel_actions_by_group( $group );
107
-
108
-		foreach ( $actions as $action_id ) {
109
-			$fetched = $store->fetch_action( $action_id );
110
-			$this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
111
-		}
112
-	}
113
-
114
-	public function test_claim_actions() {
115
-		$created_actions = array();
116
-		$store           = new ActionScheduler_DBStore();
117
-		for ( $i = 3; $i > - 3; $i -- ) {
118
-			$time     = as_get_datetime_object( $i . ' hours' );
119
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
120
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
121
-
122
-			$created_actions[] = $store->save_action( $action );
123
-		}
124
-
125
-		$claim = $store->stake_claim();
126
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
127
-
128
-		$this->assertCount( 3, $claim->get_actions() );
129
-		$this->assertEqualSets( array_slice( $created_actions, 3, 3 ), $claim->get_actions() );
130
-	}
131
-
132
-	public function test_claim_actions_order() {
133
-
134
-		$store           = new ActionScheduler_DBStore();
135
-		$schedule        = new ActionScheduler_SimpleSchedule( as_get_datetime_object( '-1 hour' ) );
136
-		$created_actions = array(
137
-			$store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'my_group' ) ),
138
-			$store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'my_group' ) ),
139
-		);
140
-
141
-		$claim = $store->stake_claim();
142
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
143
-
144
-		// Verify uniqueness of action IDs.
145
-		$this->assertCount( 2, array_unique( $created_actions ) );
146
-
147
-		// Verify the count and order of the actions.
148
-		$claimed_actions = $claim->get_actions();
149
-		$this->assertCount( 2, $claimed_actions );
150
-		$this->assertEquals( $created_actions, $claimed_actions );
151
-
152
-		// Verify the reversed order doesn't pass.
153
-		$reversed_actions = array_reverse( $created_actions );
154
-		$this->assertNotEquals( $reversed_actions, $claimed_actions );
155
-	}
156
-
157
-	public function test_claim_actions_by_hooks() {
158
-		$created_actions = $created_actions_by_hook = array();
159
-		$store           = new ActionScheduler_DBStore();
160
-		$unique_hook_one = 'my_unique_hook_one';
161
-		$unique_hook_two = 'my_unique_hook_two';
162
-		$unique_hooks    = array(
163
-			$unique_hook_one,
164
-			$unique_hook_two,
165
-		);
166
-
167
-		for ( $i = 3; $i > - 3; $i -- ) {
168
-			foreach ( $unique_hooks as $unique_hook ) {
169
-				$time     = as_get_datetime_object( $i . ' hours' );
170
-				$schedule = new ActionScheduler_SimpleSchedule( $time );
171
-				$action   = new ActionScheduler_Action( $unique_hook, array( $i ), $schedule, 'my_group' );
172
-
173
-				$action_id         = $store->save_action( $action );
174
-				$created_actions[] = $created_actions_by_hook[ $unique_hook ][] = $action_id;
175
-			}
176
-		}
177
-
178
-		$claim = $store->stake_claim( 10, null, $unique_hooks );
179
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
180
-		$this->assertCount( 6, $claim->get_actions() );
181
-		$this->assertEqualSets( array_slice( $created_actions, 6, 6 ), $claim->get_actions() );
182
-
183
-		$store->release_claim( $claim );
184
-
185
-		$claim = $store->stake_claim( 10, null, array( $unique_hook_one ) );
186
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
187
-		$this->assertCount( 3, $claim->get_actions() );
188
-		$this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_one ], 3, 3 ), $claim->get_actions() );
189
-
190
-		$store->release_claim( $claim );
191
-
192
-		$claim = $store->stake_claim( 10, null, array( $unique_hook_two ) );
193
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
194
-		$this->assertCount( 3, $claim->get_actions() );
195
-		$this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_two ], 3, 3 ), $claim->get_actions() );
196
-	}
197
-
198
-	public function test_claim_actions_by_group() {
199
-		$created_actions  = array();
200
-		$store            = new ActionScheduler_DBStore();
201
-		$unique_group_one = 'my_unique_group_one';
202
-		$unique_group_two = 'my_unique_group_two';
203
-		$unique_groups    = array(
204
-			$unique_group_one,
205
-			$unique_group_two,
206
-		);
207
-
208
-		for ( $i = 3; $i > - 3; $i -- ) {
209
-			foreach ( $unique_groups as $unique_group ) {
210
-				$time     = as_get_datetime_object( $i . ' hours' );
211
-				$schedule = new ActionScheduler_SimpleSchedule( $time );
212
-				$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, $unique_group );
213
-
214
-				$created_actions[ $unique_group ][] = $store->save_action( $action );
215
-			}
216
-		}
217
-
218
-		$claim = $store->stake_claim( 10, null, array(), $unique_group_one );
219
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
220
-		$this->assertCount( 3, $claim->get_actions() );
221
-		$this->assertEqualSets( array_slice( $created_actions[ $unique_group_one ], 3, 3 ), $claim->get_actions() );
222
-
223
-		$store->release_claim( $claim );
224
-
225
-		$claim = $store->stake_claim( 10, null, array(), $unique_group_two );
226
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
227
-		$this->assertCount( 3, $claim->get_actions() );
228
-		$this->assertEqualSets( array_slice( $created_actions[ $unique_group_two ], 3, 3 ), $claim->get_actions() );
229
-	}
230
-
231
-	public function test_claim_actions_by_hook_and_group() {
232
-		$created_actions = $created_actions_by_hook = array();
233
-		$store           = new ActionScheduler_DBStore();
234
-
235
-		$unique_hook_one = 'my_other_unique_hook_one';
236
-		$unique_hook_two = 'my_other_unique_hook_two';
237
-		$unique_hooks    = array(
238
-			$unique_hook_one,
239
-			$unique_hook_two,
240
-		);
241
-
242
-		$unique_group_one = 'my_other_other_unique_group_one';
243
-		$unique_group_two = 'my_other_unique_group_two';
244
-		$unique_groups    = array(
245
-			$unique_group_one,
246
-			$unique_group_two,
247
-		);
248
-
249
-		for ( $i = 3; $i > - 3; $i -- ) {
250
-			foreach ( $unique_hooks as $unique_hook ) {
251
-				foreach ( $unique_groups as $unique_group ) {
252
-					$time     = as_get_datetime_object( $i . ' hours' );
253
-					$schedule = new ActionScheduler_SimpleSchedule( $time );
254
-					$action   = new ActionScheduler_Action( $unique_hook, array( $i ), $schedule, $unique_group );
255
-
256
-					$action_id                          = $store->save_action( $action );
257
-					$created_actions[ $unique_group ][] = $action_id;
258
-					$created_actions_by_hook[ $unique_hook ][ $unique_group ][] = $action_id;
259
-				}
260
-			}
261
-		}
262
-
263
-		/** Test Both Hooks with Each Group */
264
-
265
-		$claim = $store->stake_claim( 10, null, $unique_hooks, $unique_group_one );
266
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
267
-		$this->assertCount( 6, $claim->get_actions() );
268
-		$this->assertEqualSets( array_slice( $created_actions[ $unique_group_one ], 6, 6 ), $claim->get_actions() );
269
-
270
-		$store->release_claim( $claim );
271
-
272
-		$claim = $store->stake_claim( 10, null, $unique_hooks, $unique_group_two );
273
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
274
-		$this->assertCount( 6, $claim->get_actions() );
275
-		$this->assertEqualSets( array_slice( $created_actions[ $unique_group_two ], 6, 6 ), $claim->get_actions() );
276
-
277
-		$store->release_claim( $claim );
278
-
279
-		/** Test Just One Hook with Group One */
280
-
281
-		$claim = $store->stake_claim( 10, null, array( $unique_hook_one ), $unique_group_one );
282
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
283
-		$this->assertCount( 3, $claim->get_actions() );
284
-		$this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_one ][ $unique_group_one ], 3, 3 ), $claim->get_actions() );
285
-
286
-		$store->release_claim( $claim );
287
-
288
-		$claim = $store->stake_claim( 24, null, array( $unique_hook_two ), $unique_group_one );
289
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
290
-		$this->assertCount( 3, $claim->get_actions() );
291
-		$this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_two ][ $unique_group_one ], 3, 3 ), $claim->get_actions() );
292
-
293
-		$store->release_claim( $claim );
294
-
295
-		/** Test Just One Hook with Group Two */
296
-
297
-		$claim = $store->stake_claim( 10, null, array( $unique_hook_one ), $unique_group_two );
298
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
299
-		$this->assertCount( 3, $claim->get_actions() );
300
-		$this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_one ][ $unique_group_two ], 3, 3 ), $claim->get_actions() );
301
-
302
-		$store->release_claim( $claim );
303
-
304
-		$claim = $store->stake_claim( 24, null, array( $unique_hook_two ), $unique_group_two );
305
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
306
-		$this->assertCount( 3, $claim->get_actions() );
307
-		$this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_two ][ $unique_group_two ], 3, 3 ), $claim->get_actions() );
308
-	}
309
-
310
-	/**
311
-	 * The query used to claim actions explicitly ignores future pending actions, but it
312
-	 * is still possible under unusual conditions (such as if MySQL runs out of temporary
313
-	 * storage space) for such actions to be returned.
314
-	 *
315
-	 * When this happens, we still expect the store to filter them out, otherwise there is
316
-	 * a risk that actions will be unexpectedly processed ahead of time.
317
-	 *
318
-	 * @see https://github.com/woocommerce/action-scheduler/issues/634
319
-	 */
320
-	public function test_claim_filters_out_unexpected_future_actions() {
321
-		$group = __METHOD__;
322
-		$store = new ActionScheduler_DBStore();
323
-
324
-		// Create 4 actions: 2 that are already due (-3hrs and -1hrs) and 2 that are not yet due (+1hr and +3hrs).
325
-		for ( $i = -3; $i <= 3; $i += 2 ) {
326
-			$schedule     = new ActionScheduler_SimpleSchedule( as_get_datetime_object( $i . ' hours' ) );
327
-			$action_ids[] = $store->save_action( new ActionScheduler_Action( 'test_' . $i, array(), $schedule, $group ) );
328
-		}
329
-
330
-		// This callback is used to simulate the unusual conditions whereby MySQL might unexpectedly return future
331
-		// actions, contrary to the conditions used by the store object when staking its claim.
332
-		$simulate_unexpected_db_behavior = function ( $sql ) use ( $action_ids ) {
333
-			global $wpdb;
334
-
335
-			// Look out for the claim update query, ignore all others.
336
-			if (
337
-				0 !== strpos( $sql, "UPDATE $wpdb->actionscheduler_actions" )
338
-				|| ! preg_match( "/claim_id = 0 AND scheduled_date_gmt <= '([0-9:\-\s]{19})'/", $sql, $matches )
339
-				|| count( $matches ) !== 2
340
-			) {
341
-				return $sql;
342
-			}
343
-
344
-			// Now modify the query, forcing it to also return the future actions we created.
345
-			return str_replace( $matches[1], as_get_datetime_object( '+4 hours' )->format( 'Y-m-d H:i:s' ), $sql );
346
-		};
347
-
348
-		add_filter( 'query', $simulate_unexpected_db_behavior );
349
-		$claim           = $store->stake_claim( 10, null, array(), $group );
350
-		$claimed_actions = $claim->get_actions();
351
-		$this->assertCount( 2, $claimed_actions );
352
-
353
-		// Cleanup.
354
-		remove_filter( 'query', $simulate_unexpected_db_behavior );
355
-		$store->release_claim( $claim );
356
-	}
357
-
358
-	public function test_duplicate_claim() {
359
-		$created_actions = array();
360
-		$store           = new ActionScheduler_DBStore();
361
-		for ( $i = 0; $i > - 3; $i -- ) {
362
-			$time     = as_get_datetime_object( $i . ' hours' );
363
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
364
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
365
-
366
-			$created_actions[] = $store->save_action( $action );
367
-		}
368
-
369
-		$claim1 = $store->stake_claim();
370
-		$claim2 = $store->stake_claim();
371
-		$this->assertCount( 3, $claim1->get_actions() );
372
-		$this->assertCount( 0, $claim2->get_actions() );
373
-	}
374
-
375
-	public function test_release_claim() {
376
-		$created_actions = array();
377
-		$store           = new ActionScheduler_DBStore();
378
-		for ( $i = 0; $i > - 3; $i -- ) {
379
-			$time     = as_get_datetime_object( $i . ' hours' );
380
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
381
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
382
-
383
-			$created_actions[] = $store->save_action( $action );
384
-		}
385
-
386
-		$claim1 = $store->stake_claim();
387
-
388
-		$store->release_claim( $claim1 );
389
-
390
-		$claim2 = $store->stake_claim();
391
-		$this->assertCount( 3, $claim2->get_actions() );
392
-	}
393
-
394
-	public function test_search() {
395
-		$created_actions = array();
396
-		$store           = new ActionScheduler_DBStore();
397
-		for ( $i = - 3; $i <= 3; $i ++ ) {
398
-			$time     = as_get_datetime_object( $i . ' hours' );
399
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
400
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
401
-
402
-			$created_actions[] = $store->save_action( $action );
403
-		}
404
-
405
-		$next_no_args = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK );
406
-		$this->assertEquals( $created_actions[0], $next_no_args );
407
-
408
-		$next_with_args = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'args' => array( 1 ) ) );
409
-		$this->assertEquals( $created_actions[4], $next_with_args );
410
-
411
-		$non_existent = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'args' => array( 17 ) ) );
412
-		$this->assertNull( $non_existent );
413
-	}
414
-
415
-	public function test_search_by_group() {
416
-		$store    = new ActionScheduler_DBStore();
417
-		$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( 'tomorrow' ) );
418
-
419
-		$abc = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'abc' ) );
420
-		$def = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'def' ) );
421
-		$ghi = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'ghi' ) );
422
-
423
-		$this->assertEquals( $abc, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'abc' ) ) );
424
-		$this->assertEquals( $def, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'def' ) ) );
425
-		$this->assertEquals( $ghi, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'ghi' ) ) );
426
-	}
427
-
428
-	public function test_get_run_date() {
429
-		$time      = as_get_datetime_object( '-10 minutes' );
430
-		$schedule  = new ActionScheduler_IntervalSchedule( $time, HOUR_IN_SECONDS );
431
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
432
-		$store     = new ActionScheduler_DBStore();
433
-		$action_id = $store->save_action( $action );
434
-
435
-		$this->assertEquals( $time->format( 'U' ), $store->get_date( $action_id )->format( 'U' ) );
436
-
437
-		$action = $store->fetch_action( $action_id );
438
-		$action->execute();
439
-		$now = as_get_datetime_object();
440
-		$store->mark_complete( $action_id );
441
-
442
-		$this->assertEquals( $now->format( 'U' ), $store->get_date( $action_id )->format( 'U' ) );
443
-
444
-		$next          = $action->get_schedule()->get_next( $now );
445
-		$new_action_id = $store->save_action( $action, $next );
446
-
447
-		$this->assertEquals( (int) ( $now->format( 'U' ) ) + HOUR_IN_SECONDS, $store->get_date( $new_action_id )->format( 'U' ) );
448
-	}
449
-
450
-	/**
451
-	 * Test creating a unique action.
452
-	 */
453
-	public function test_create_action_unique() {
454
-		$time     = as_get_datetime_object();
455
-		$hook     = md5( rand() );
456
-		$schedule = new ActionScheduler_SimpleSchedule( $time );
457
-		$store    = new ActionScheduler_DBStore();
458
-		$action   = new ActionScheduler_Action( $hook, array(), $schedule );
459
-
460
-		$action_id = $store->save_action( $action );
461
-		$this->assertNotEquals( 0, $action_id );
462
-		$action_from_db = $store->fetch_action( $action_id );
463
-		$this->assertTrue( is_a( $action_from_db, ActionScheduler_Action::class ) );
464
-
465
-		$action              = new ActionScheduler_Action( $hook, array(), $schedule );
466
-		$action_id_duplicate = $store->save_unique_action( $action );
467
-		$this->assertSame( 0, $action_id_duplicate );
468
-	}
469
-
470
-	/**
471
-	 * Test saving unique actions across different groups. Different groups should be saved, same groups shouldn't.
472
-	 */
473
-	public function test_create_action_unique_with_different_groups() {
474
-		$time     = as_get_datetime_object();
475
-		$hook     = md5( rand() );
476
-		$schedule = new ActionScheduler_SimpleSchedule( $time );
477
-		$store    = new ActionScheduler_DBStore();
478
-		$action   = new ActionScheduler_Action( $hook, array(), $schedule, 'group1' );
479
-
480
-		$action_id      = $store->save_action( $action );
481
-		$action_from_db = $store->fetch_action( $action_id );
482
-		$this->assertNotEquals( 0, $action_id );
483
-		$this->assertTrue( is_a( $action_from_db, ActionScheduler_Action::class ) );
484
-
485
-		$action2          = new ActionScheduler_Action( $hook, array(), $schedule, 'group2' );
486
-		$action_id_group2 = $store->save_unique_action( $action2 );
487
-		$this->assertNotEquals( 0, $action_id_group2 );
488
-		$action_2_from_db = $store->fetch_action( $action_id_group2 );
489
-		$this->assertTrue( is_a( $action_2_from_db, ActionScheduler_Action::class ) );
490
-
491
-		$action3                 = new ActionScheduler_Action( $hook, array(), $schedule, 'group2' );
492
-		$action_id_group2_double = $store->save_unique_action( $action3 );
493
-		$this->assertSame( 0, $action_id_group2_double );
494
-	}
495
-
496
-	/**
497
-	 * Test saving a unique action first, and then successfully scheduling a non-unique action.
498
-	 */
499
-	public function test_create_action_unique_and_then_non_unique() {
500
-		$time     = as_get_datetime_object();
501
-		$hook     = md5( rand() );
502
-		$schedule = new ActionScheduler_SimpleSchedule( $time );
503
-		$store    = new ActionScheduler_DBStore();
504
-		$action   = new ActionScheduler_Action( $hook, array(), $schedule );
505
-
506
-		$action_id = $store->save_unique_action( $action );
507
-		$this->assertNotEquals( 0, $action_id );
508
-		$action_from_db = $store->fetch_action( $action_id );
509
-		$this->assertTrue( is_a( $action_from_db, ActionScheduler_Action::class ) );
510
-
511
-		// Non unique action is scheduled even if the previous one was unique.
512
-		$action              = new ActionScheduler_Action( $hook, array(), $schedule );
513
-		$action_id_duplicate = $store->save_action( $action );
514
-		$this->assertNotEquals( 0, $action_id_duplicate );
515
-		$action_from_db_duplicate = $store->fetch_action( $action_id_duplicate );
516
-		$this->assertTrue( is_a( $action_from_db_duplicate, ActionScheduler_Action::class ) );
517
-	}
518
-
519
-	/**
520
-	 * Test asserting that action when an action is created with empty args, it matches with actions created with args for uniqueness.
521
-	 */
522
-	public function test_create_action_unique_with_empty_array() {
523
-		$time     = as_get_datetime_object();
524
-		$hook     = md5( rand() );
525
-		$schedule = new ActionScheduler_SimpleSchedule( $time );
526
-		$store    = new ActionScheduler_DBStore();
527
-		$action   = new ActionScheduler_Action( $hook, array( 'foo' => 'bar' ), $schedule );
528
-
529
-		$action_id = $store->save_unique_action( $action );
530
-		$this->assertNotEquals( 0, $action_id );
531
-		$action_from_db = $store->fetch_action( $action_id );
532
-		$this->assertTrue( is_a( $action_from_db, ActionScheduler_Action::class ) );
533
-
534
-		$action_with_empty_args = new ActionScheduler_Action( $hook, array(), $schedule );
535
-		$action_id_duplicate    = $store->save_unique_action( $action_with_empty_args );
536
-		$this->assertSame( 0, $action_id_duplicate );
537
-	}
538
-
539
-	/**
540
-	 * Uniqueness does not check for args, so actions with different args can't be scheduled when unique is true.
541
-	 */
542
-	public function test_create_action_unique_with_different_args_still_fail() {
543
-		$time     = as_get_datetime_object();
544
-		$hook     = md5( rand() );
545
-		$schedule = new ActionScheduler_SimpleSchedule( $time );
546
-		$store    = new ActionScheduler_DBStore();
547
-		$action   = new ActionScheduler_Action( $hook, array( 'foo' => 'bar' ), $schedule );
548
-
549
-		$action_id = $store->save_unique_action( $action );
550
-		$this->assertNotEquals( 0, $action_id );
551
-		$action_from_db = $store->fetch_action( $action_id );
552
-		$this->assertTrue( is_a( $action_from_db, ActionScheduler_Action::class ) );
553
-
554
-		$action_with_diff_args = new ActionScheduler_Action( $hook, array( 'foo' => 'bazz' ), $schedule );
555
-		$action_id_duplicate   = $store->save_unique_action( $action_with_diff_args );
556
-		$this->assertSame( 0, $action_id_duplicate );
557
-	}
12
+    public function setUp() {
13
+        global $wpdb;
14
+
15
+        // Delete all actions before each test.
16
+        $wpdb->query( "DELETE FROM {$wpdb->actionscheduler_actions}" );
17
+
18
+        parent::setUp();
19
+    }
20
+
21
+    /**
22
+     * Get data store for tests.
23
+     *
24
+     * @return ActionScheduler_DBStore
25
+     */
26
+    protected function get_store() {
27
+        return new ActionScheduler_DBStore();
28
+    }
29
+
30
+    public function test_create_action() {
31
+        $time      = as_get_datetime_object();
32
+        $schedule  = new ActionScheduler_SimpleSchedule( $time );
33
+        $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
34
+        $store     = new ActionScheduler_DBStore();
35
+        $action_id = $store->save_action( $action );
36
+
37
+        $this->assertNotEmpty( $action_id );
38
+    }
39
+
40
+    public function test_create_action_with_scheduled_date() {
41
+        $time        = as_get_datetime_object( strtotime( '-1 week' ) );
42
+        $action      = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), new ActionScheduler_SimpleSchedule( $time ) );
43
+        $store       = new ActionScheduler_DBStore();
44
+        $action_id   = $store->save_action( $action, $time );
45
+        $action_date = $store->get_date( $action_id );
46
+
47
+        $this->assertEquals( $time->format( 'U' ), $action_date->format( 'U' ) );
48
+    }
49
+
50
+    public function test_retrieve_action() {
51
+        $time      = as_get_datetime_object();
52
+        $schedule  = new ActionScheduler_SimpleSchedule( $time );
53
+        $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
54
+        $store     = new ActionScheduler_DBStore();
55
+        $action_id = $store->save_action( $action );
56
+
57
+        $retrieved = $store->fetch_action( $action_id );
58
+        $this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
59
+        $this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
60
+        $this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
61
+        $this->assertEquals( $action->get_group(), $retrieved->get_group() );
62
+    }
63
+
64
+    public function test_cancel_action() {
65
+        $time      = as_get_datetime_object();
66
+        $schedule  = new ActionScheduler_SimpleSchedule( $time );
67
+        $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
68
+        $store     = new ActionScheduler_DBStore();
69
+        $action_id = $store->save_action( $action );
70
+        $store->cancel_action( $action_id );
71
+
72
+        $fetched = $store->fetch_action( $action_id );
73
+        $this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
74
+    }
75
+
76
+    public function test_cancel_actions_by_hook() {
77
+        $store   = new ActionScheduler_DBStore();
78
+        $actions = array();
79
+        $hook    = 'by_hook_test';
80
+        for ( $day = 1; $day <= 3; $day++ ) {
81
+            $delta     = sprintf( '+%d day', $day );
82
+            $time      = as_get_datetime_object( $delta );
83
+            $schedule  = new ActionScheduler_SimpleSchedule( $time );
84
+            $action    = new ActionScheduler_Action( $hook, array(), $schedule, 'my_group' );
85
+            $actions[] = $store->save_action( $action );
86
+        }
87
+        $store->cancel_actions_by_hook( $hook );
88
+
89
+        foreach ( $actions as $action_id ) {
90
+            $fetched = $store->fetch_action( $action_id );
91
+            $this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
92
+        }
93
+    }
94
+
95
+    public function test_cancel_actions_by_group() {
96
+        $store   = new ActionScheduler_DBStore();
97
+        $actions = array();
98
+        $group   = 'by_group_test';
99
+        for ( $day = 1; $day <= 3; $day++ ) {
100
+            $delta     = sprintf( '+%d day', $day );
101
+            $time      = as_get_datetime_object( $delta );
102
+            $schedule  = new ActionScheduler_SimpleSchedule( $time );
103
+            $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, $group );
104
+            $actions[] = $store->save_action( $action );
105
+        }
106
+        $store->cancel_actions_by_group( $group );
107
+
108
+        foreach ( $actions as $action_id ) {
109
+            $fetched = $store->fetch_action( $action_id );
110
+            $this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
111
+        }
112
+    }
113
+
114
+    public function test_claim_actions() {
115
+        $created_actions = array();
116
+        $store           = new ActionScheduler_DBStore();
117
+        for ( $i = 3; $i > - 3; $i -- ) {
118
+            $time     = as_get_datetime_object( $i . ' hours' );
119
+            $schedule = new ActionScheduler_SimpleSchedule( $time );
120
+            $action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
121
+
122
+            $created_actions[] = $store->save_action( $action );
123
+        }
124
+
125
+        $claim = $store->stake_claim();
126
+        $this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
127
+
128
+        $this->assertCount( 3, $claim->get_actions() );
129
+        $this->assertEqualSets( array_slice( $created_actions, 3, 3 ), $claim->get_actions() );
130
+    }
131
+
132
+    public function test_claim_actions_order() {
133
+
134
+        $store           = new ActionScheduler_DBStore();
135
+        $schedule        = new ActionScheduler_SimpleSchedule( as_get_datetime_object( '-1 hour' ) );
136
+        $created_actions = array(
137
+            $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'my_group' ) ),
138
+            $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'my_group' ) ),
139
+        );
140
+
141
+        $claim = $store->stake_claim();
142
+        $this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
143
+
144
+        // Verify uniqueness of action IDs.
145
+        $this->assertCount( 2, array_unique( $created_actions ) );
146
+
147
+        // Verify the count and order of the actions.
148
+        $claimed_actions = $claim->get_actions();
149
+        $this->assertCount( 2, $claimed_actions );
150
+        $this->assertEquals( $created_actions, $claimed_actions );
151
+
152
+        // Verify the reversed order doesn't pass.
153
+        $reversed_actions = array_reverse( $created_actions );
154
+        $this->assertNotEquals( $reversed_actions, $claimed_actions );
155
+    }
156
+
157
+    public function test_claim_actions_by_hooks() {
158
+        $created_actions = $created_actions_by_hook = array();
159
+        $store           = new ActionScheduler_DBStore();
160
+        $unique_hook_one = 'my_unique_hook_one';
161
+        $unique_hook_two = 'my_unique_hook_two';
162
+        $unique_hooks    = array(
163
+            $unique_hook_one,
164
+            $unique_hook_two,
165
+        );
166
+
167
+        for ( $i = 3; $i > - 3; $i -- ) {
168
+            foreach ( $unique_hooks as $unique_hook ) {
169
+                $time     = as_get_datetime_object( $i . ' hours' );
170
+                $schedule = new ActionScheduler_SimpleSchedule( $time );
171
+                $action   = new ActionScheduler_Action( $unique_hook, array( $i ), $schedule, 'my_group' );
172
+
173
+                $action_id         = $store->save_action( $action );
174
+                $created_actions[] = $created_actions_by_hook[ $unique_hook ][] = $action_id;
175
+            }
176
+        }
177
+
178
+        $claim = $store->stake_claim( 10, null, $unique_hooks );
179
+        $this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
180
+        $this->assertCount( 6, $claim->get_actions() );
181
+        $this->assertEqualSets( array_slice( $created_actions, 6, 6 ), $claim->get_actions() );
182
+
183
+        $store->release_claim( $claim );
184
+
185
+        $claim = $store->stake_claim( 10, null, array( $unique_hook_one ) );
186
+        $this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
187
+        $this->assertCount( 3, $claim->get_actions() );
188
+        $this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_one ], 3, 3 ), $claim->get_actions() );
189
+
190
+        $store->release_claim( $claim );
191
+
192
+        $claim = $store->stake_claim( 10, null, array( $unique_hook_two ) );
193
+        $this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
194
+        $this->assertCount( 3, $claim->get_actions() );
195
+        $this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_two ], 3, 3 ), $claim->get_actions() );
196
+    }
197
+
198
+    public function test_claim_actions_by_group() {
199
+        $created_actions  = array();
200
+        $store            = new ActionScheduler_DBStore();
201
+        $unique_group_one = 'my_unique_group_one';
202
+        $unique_group_two = 'my_unique_group_two';
203
+        $unique_groups    = array(
204
+            $unique_group_one,
205
+            $unique_group_two,
206
+        );
207
+
208
+        for ( $i = 3; $i > - 3; $i -- ) {
209
+            foreach ( $unique_groups as $unique_group ) {
210
+                $time     = as_get_datetime_object( $i . ' hours' );
211
+                $schedule = new ActionScheduler_SimpleSchedule( $time );
212
+                $action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, $unique_group );
213
+
214
+                $created_actions[ $unique_group ][] = $store->save_action( $action );
215
+            }
216
+        }
217
+
218
+        $claim = $store->stake_claim( 10, null, array(), $unique_group_one );
219
+        $this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
220
+        $this->assertCount( 3, $claim->get_actions() );
221
+        $this->assertEqualSets( array_slice( $created_actions[ $unique_group_one ], 3, 3 ), $claim->get_actions() );
222
+
223
+        $store->release_claim( $claim );
224
+
225
+        $claim = $store->stake_claim( 10, null, array(), $unique_group_two );
226
+        $this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
227
+        $this->assertCount( 3, $claim->get_actions() );
228
+        $this->assertEqualSets( array_slice( $created_actions[ $unique_group_two ], 3, 3 ), $claim->get_actions() );
229
+    }
230
+
231
+    public function test_claim_actions_by_hook_and_group() {
232
+        $created_actions = $created_actions_by_hook = array();
233
+        $store           = new ActionScheduler_DBStore();
234
+
235
+        $unique_hook_one = 'my_other_unique_hook_one';
236
+        $unique_hook_two = 'my_other_unique_hook_two';
237
+        $unique_hooks    = array(
238
+            $unique_hook_one,
239
+            $unique_hook_two,
240
+        );
241
+
242
+        $unique_group_one = 'my_other_other_unique_group_one';
243
+        $unique_group_two = 'my_other_unique_group_two';
244
+        $unique_groups    = array(
245
+            $unique_group_one,
246
+            $unique_group_two,
247
+        );
248
+
249
+        for ( $i = 3; $i > - 3; $i -- ) {
250
+            foreach ( $unique_hooks as $unique_hook ) {
251
+                foreach ( $unique_groups as $unique_group ) {
252
+                    $time     = as_get_datetime_object( $i . ' hours' );
253
+                    $schedule = new ActionScheduler_SimpleSchedule( $time );
254
+                    $action   = new ActionScheduler_Action( $unique_hook, array( $i ), $schedule, $unique_group );
255
+
256
+                    $action_id                          = $store->save_action( $action );
257
+                    $created_actions[ $unique_group ][] = $action_id;
258
+                    $created_actions_by_hook[ $unique_hook ][ $unique_group ][] = $action_id;
259
+                }
260
+            }
261
+        }
262
+
263
+        /** Test Both Hooks with Each Group */
264
+
265
+        $claim = $store->stake_claim( 10, null, $unique_hooks, $unique_group_one );
266
+        $this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
267
+        $this->assertCount( 6, $claim->get_actions() );
268
+        $this->assertEqualSets( array_slice( $created_actions[ $unique_group_one ], 6, 6 ), $claim->get_actions() );
269
+
270
+        $store->release_claim( $claim );
271
+
272
+        $claim = $store->stake_claim( 10, null, $unique_hooks, $unique_group_two );
273
+        $this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
274
+        $this->assertCount( 6, $claim->get_actions() );
275
+        $this->assertEqualSets( array_slice( $created_actions[ $unique_group_two ], 6, 6 ), $claim->get_actions() );
276
+
277
+        $store->release_claim( $claim );
278
+
279
+        /** Test Just One Hook with Group One */
280
+
281
+        $claim = $store->stake_claim( 10, null, array( $unique_hook_one ), $unique_group_one );
282
+        $this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
283
+        $this->assertCount( 3, $claim->get_actions() );
284
+        $this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_one ][ $unique_group_one ], 3, 3 ), $claim->get_actions() );
285
+
286
+        $store->release_claim( $claim );
287
+
288
+        $claim = $store->stake_claim( 24, null, array( $unique_hook_two ), $unique_group_one );
289
+        $this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
290
+        $this->assertCount( 3, $claim->get_actions() );
291
+        $this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_two ][ $unique_group_one ], 3, 3 ), $claim->get_actions() );
292
+
293
+        $store->release_claim( $claim );
294
+
295
+        /** Test Just One Hook with Group Two */
296
+
297
+        $claim = $store->stake_claim( 10, null, array( $unique_hook_one ), $unique_group_two );
298
+        $this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
299
+        $this->assertCount( 3, $claim->get_actions() );
300
+        $this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_one ][ $unique_group_two ], 3, 3 ), $claim->get_actions() );
301
+
302
+        $store->release_claim( $claim );
303
+
304
+        $claim = $store->stake_claim( 24, null, array( $unique_hook_two ), $unique_group_two );
305
+        $this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
306
+        $this->assertCount( 3, $claim->get_actions() );
307
+        $this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_two ][ $unique_group_two ], 3, 3 ), $claim->get_actions() );
308
+    }
309
+
310
+    /**
311
+     * The query used to claim actions explicitly ignores future pending actions, but it
312
+     * is still possible under unusual conditions (such as if MySQL runs out of temporary
313
+     * storage space) for such actions to be returned.
314
+     *
315
+     * When this happens, we still expect the store to filter them out, otherwise there is
316
+     * a risk that actions will be unexpectedly processed ahead of time.
317
+     *
318
+     * @see https://github.com/woocommerce/action-scheduler/issues/634
319
+     */
320
+    public function test_claim_filters_out_unexpected_future_actions() {
321
+        $group = __METHOD__;
322
+        $store = new ActionScheduler_DBStore();
323
+
324
+        // Create 4 actions: 2 that are already due (-3hrs and -1hrs) and 2 that are not yet due (+1hr and +3hrs).
325
+        for ( $i = -3; $i <= 3; $i += 2 ) {
326
+            $schedule     = new ActionScheduler_SimpleSchedule( as_get_datetime_object( $i . ' hours' ) );
327
+            $action_ids[] = $store->save_action( new ActionScheduler_Action( 'test_' . $i, array(), $schedule, $group ) );
328
+        }
329
+
330
+        // This callback is used to simulate the unusual conditions whereby MySQL might unexpectedly return future
331
+        // actions, contrary to the conditions used by the store object when staking its claim.
332
+        $simulate_unexpected_db_behavior = function ( $sql ) use ( $action_ids ) {
333
+            global $wpdb;
334
+
335
+            // Look out for the claim update query, ignore all others.
336
+            if (
337
+                0 !== strpos( $sql, "UPDATE $wpdb->actionscheduler_actions" )
338
+                || ! preg_match( "/claim_id = 0 AND scheduled_date_gmt <= '([0-9:\-\s]{19})'/", $sql, $matches )
339
+                || count( $matches ) !== 2
340
+            ) {
341
+                return $sql;
342
+            }
343
+
344
+            // Now modify the query, forcing it to also return the future actions we created.
345
+            return str_replace( $matches[1], as_get_datetime_object( '+4 hours' )->format( 'Y-m-d H:i:s' ), $sql );
346
+        };
347
+
348
+        add_filter( 'query', $simulate_unexpected_db_behavior );
349
+        $claim           = $store->stake_claim( 10, null, array(), $group );
350
+        $claimed_actions = $claim->get_actions();
351
+        $this->assertCount( 2, $claimed_actions );
352
+
353
+        // Cleanup.
354
+        remove_filter( 'query', $simulate_unexpected_db_behavior );
355
+        $store->release_claim( $claim );
356
+    }
357
+
358
+    public function test_duplicate_claim() {
359
+        $created_actions = array();
360
+        $store           = new ActionScheduler_DBStore();
361
+        for ( $i = 0; $i > - 3; $i -- ) {
362
+            $time     = as_get_datetime_object( $i . ' hours' );
363
+            $schedule = new ActionScheduler_SimpleSchedule( $time );
364
+            $action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
365
+
366
+            $created_actions[] = $store->save_action( $action );
367
+        }
368
+
369
+        $claim1 = $store->stake_claim();
370
+        $claim2 = $store->stake_claim();
371
+        $this->assertCount( 3, $claim1->get_actions() );
372
+        $this->assertCount( 0, $claim2->get_actions() );
373
+    }
374
+
375
+    public function test_release_claim() {
376
+        $created_actions = array();
377
+        $store           = new ActionScheduler_DBStore();
378
+        for ( $i = 0; $i > - 3; $i -- ) {
379
+            $time     = as_get_datetime_object( $i . ' hours' );
380
+            $schedule = new ActionScheduler_SimpleSchedule( $time );
381
+            $action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
382
+
383
+            $created_actions[] = $store->save_action( $action );
384
+        }
385
+
386
+        $claim1 = $store->stake_claim();
387
+
388
+        $store->release_claim( $claim1 );
389
+
390
+        $claim2 = $store->stake_claim();
391
+        $this->assertCount( 3, $claim2->get_actions() );
392
+    }
393
+
394
+    public function test_search() {
395
+        $created_actions = array();
396
+        $store           = new ActionScheduler_DBStore();
397
+        for ( $i = - 3; $i <= 3; $i ++ ) {
398
+            $time     = as_get_datetime_object( $i . ' hours' );
399
+            $schedule = new ActionScheduler_SimpleSchedule( $time );
400
+            $action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
401
+
402
+            $created_actions[] = $store->save_action( $action );
403
+        }
404
+
405
+        $next_no_args = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK );
406
+        $this->assertEquals( $created_actions[0], $next_no_args );
407
+
408
+        $next_with_args = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'args' => array( 1 ) ) );
409
+        $this->assertEquals( $created_actions[4], $next_with_args );
410
+
411
+        $non_existent = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'args' => array( 17 ) ) );
412
+        $this->assertNull( $non_existent );
413
+    }
414
+
415
+    public function test_search_by_group() {
416
+        $store    = new ActionScheduler_DBStore();
417
+        $schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( 'tomorrow' ) );
418
+
419
+        $abc = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'abc' ) );
420
+        $def = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'def' ) );
421
+        $ghi = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'ghi' ) );
422
+
423
+        $this->assertEquals( $abc, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'abc' ) ) );
424
+        $this->assertEquals( $def, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'def' ) ) );
425
+        $this->assertEquals( $ghi, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'ghi' ) ) );
426
+    }
427
+
428
+    public function test_get_run_date() {
429
+        $time      = as_get_datetime_object( '-10 minutes' );
430
+        $schedule  = new ActionScheduler_IntervalSchedule( $time, HOUR_IN_SECONDS );
431
+        $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
432
+        $store     = new ActionScheduler_DBStore();
433
+        $action_id = $store->save_action( $action );
434
+
435
+        $this->assertEquals( $time->format( 'U' ), $store->get_date( $action_id )->format( 'U' ) );
436
+
437
+        $action = $store->fetch_action( $action_id );
438
+        $action->execute();
439
+        $now = as_get_datetime_object();
440
+        $store->mark_complete( $action_id );
441
+
442
+        $this->assertEquals( $now->format( 'U' ), $store->get_date( $action_id )->format( 'U' ) );
443
+
444
+        $next          = $action->get_schedule()->get_next( $now );
445
+        $new_action_id = $store->save_action( $action, $next );
446
+
447
+        $this->assertEquals( (int) ( $now->format( 'U' ) ) + HOUR_IN_SECONDS, $store->get_date( $new_action_id )->format( 'U' ) );
448
+    }
449
+
450
+    /**
451
+     * Test creating a unique action.
452
+     */
453
+    public function test_create_action_unique() {
454
+        $time     = as_get_datetime_object();
455
+        $hook     = md5( rand() );
456
+        $schedule = new ActionScheduler_SimpleSchedule( $time );
457
+        $store    = new ActionScheduler_DBStore();
458
+        $action   = new ActionScheduler_Action( $hook, array(), $schedule );
459
+
460
+        $action_id = $store->save_action( $action );
461
+        $this->assertNotEquals( 0, $action_id );
462
+        $action_from_db = $store->fetch_action( $action_id );
463
+        $this->assertTrue( is_a( $action_from_db, ActionScheduler_Action::class ) );
464
+
465
+        $action              = new ActionScheduler_Action( $hook, array(), $schedule );
466
+        $action_id_duplicate = $store->save_unique_action( $action );
467
+        $this->assertSame( 0, $action_id_duplicate );
468
+    }
469
+
470
+    /**
471
+     * Test saving unique actions across different groups. Different groups should be saved, same groups shouldn't.
472
+     */
473
+    public function test_create_action_unique_with_different_groups() {
474
+        $time     = as_get_datetime_object();
475
+        $hook     = md5( rand() );
476
+        $schedule = new ActionScheduler_SimpleSchedule( $time );
477
+        $store    = new ActionScheduler_DBStore();
478
+        $action   = new ActionScheduler_Action( $hook, array(), $schedule, 'group1' );
479
+
480
+        $action_id      = $store->save_action( $action );
481
+        $action_from_db = $store->fetch_action( $action_id );
482
+        $this->assertNotEquals( 0, $action_id );
483
+        $this->assertTrue( is_a( $action_from_db, ActionScheduler_Action::class ) );
484
+
485
+        $action2          = new ActionScheduler_Action( $hook, array(), $schedule, 'group2' );
486
+        $action_id_group2 = $store->save_unique_action( $action2 );
487
+        $this->assertNotEquals( 0, $action_id_group2 );
488
+        $action_2_from_db = $store->fetch_action( $action_id_group2 );
489
+        $this->assertTrue( is_a( $action_2_from_db, ActionScheduler_Action::class ) );
490
+
491
+        $action3                 = new ActionScheduler_Action( $hook, array(), $schedule, 'group2' );
492
+        $action_id_group2_double = $store->save_unique_action( $action3 );
493
+        $this->assertSame( 0, $action_id_group2_double );
494
+    }
495
+
496
+    /**
497
+     * Test saving a unique action first, and then successfully scheduling a non-unique action.
498
+     */
499
+    public function test_create_action_unique_and_then_non_unique() {
500
+        $time     = as_get_datetime_object();
501
+        $hook     = md5( rand() );
502
+        $schedule = new ActionScheduler_SimpleSchedule( $time );
503
+        $store    = new ActionScheduler_DBStore();
504
+        $action   = new ActionScheduler_Action( $hook, array(), $schedule );
505
+
506
+        $action_id = $store->save_unique_action( $action );
507
+        $this->assertNotEquals( 0, $action_id );
508
+        $action_from_db = $store->fetch_action( $action_id );
509
+        $this->assertTrue( is_a( $action_from_db, ActionScheduler_Action::class ) );
510
+
511
+        // Non unique action is scheduled even if the previous one was unique.
512
+        $action              = new ActionScheduler_Action( $hook, array(), $schedule );
513
+        $action_id_duplicate = $store->save_action( $action );
514
+        $this->assertNotEquals( 0, $action_id_duplicate );
515
+        $action_from_db_duplicate = $store->fetch_action( $action_id_duplicate );
516
+        $this->assertTrue( is_a( $action_from_db_duplicate, ActionScheduler_Action::class ) );
517
+    }
518
+
519
+    /**
520
+     * Test asserting that action when an action is created with empty args, it matches with actions created with args for uniqueness.
521
+     */
522
+    public function test_create_action_unique_with_empty_array() {
523
+        $time     = as_get_datetime_object();
524
+        $hook     = md5( rand() );
525
+        $schedule = new ActionScheduler_SimpleSchedule( $time );
526
+        $store    = new ActionScheduler_DBStore();
527
+        $action   = new ActionScheduler_Action( $hook, array( 'foo' => 'bar' ), $schedule );
528
+
529
+        $action_id = $store->save_unique_action( $action );
530
+        $this->assertNotEquals( 0, $action_id );
531
+        $action_from_db = $store->fetch_action( $action_id );
532
+        $this->assertTrue( is_a( $action_from_db, ActionScheduler_Action::class ) );
533
+
534
+        $action_with_empty_args = new ActionScheduler_Action( $hook, array(), $schedule );
535
+        $action_id_duplicate    = $store->save_unique_action( $action_with_empty_args );
536
+        $this->assertSame( 0, $action_id_duplicate );
537
+    }
538
+
539
+    /**
540
+     * Uniqueness does not check for args, so actions with different args can't be scheduled when unique is true.
541
+     */
542
+    public function test_create_action_unique_with_different_args_still_fail() {
543
+        $time     = as_get_datetime_object();
544
+        $hook     = md5( rand() );
545
+        $schedule = new ActionScheduler_SimpleSchedule( $time );
546
+        $store    = new ActionScheduler_DBStore();
547
+        $action   = new ActionScheduler_Action( $hook, array( 'foo' => 'bar' ), $schedule );
548
+
549
+        $action_id = $store->save_unique_action( $action );
550
+        $this->assertNotEquals( 0, $action_id );
551
+        $action_from_db = $store->fetch_action( $action_id );
552
+        $this->assertTrue( is_a( $action_from_db, ActionScheduler_Action::class ) );
553
+
554
+        $action_with_diff_args = new ActionScheduler_Action( $hook, array( 'foo' => 'bazz' ), $schedule );
555
+        $action_id_duplicate   = $store->save_unique_action( $action_with_diff_args );
556
+        $this->assertSame( 0, $action_id_duplicate );
557
+    }
558 558
 }
Please login to merge, or discard this patch.
Spacing   +251 added lines, -251 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 		global $wpdb;
14 14
 
15 15
 		// Delete all actions before each test.
16
-		$wpdb->query( "DELETE FROM {$wpdb->actionscheduler_actions}" );
16
+		$wpdb->query("DELETE FROM {$wpdb->actionscheduler_actions}");
17 17
 
18 18
 		parent::setUp();
19 19
 	}
@@ -29,66 +29,66 @@  discard block
 block discarded – undo
29 29
 
30 30
 	public function test_create_action() {
31 31
 		$time      = as_get_datetime_object();
32
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
33
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
32
+		$schedule  = new ActionScheduler_SimpleSchedule($time);
33
+		$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
34 34
 		$store     = new ActionScheduler_DBStore();
35
-		$action_id = $store->save_action( $action );
35
+		$action_id = $store->save_action($action);
36 36
 
37
-		$this->assertNotEmpty( $action_id );
37
+		$this->assertNotEmpty($action_id);
38 38
 	}
39 39
 
40 40
 	public function test_create_action_with_scheduled_date() {
41
-		$time        = as_get_datetime_object( strtotime( '-1 week' ) );
42
-		$action      = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), new ActionScheduler_SimpleSchedule( $time ) );
41
+		$time        = as_get_datetime_object(strtotime('-1 week'));
42
+		$action      = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), new ActionScheduler_SimpleSchedule($time));
43 43
 		$store       = new ActionScheduler_DBStore();
44
-		$action_id   = $store->save_action( $action, $time );
45
-		$action_date = $store->get_date( $action_id );
44
+		$action_id   = $store->save_action($action, $time);
45
+		$action_date = $store->get_date($action_id);
46 46
 
47
-		$this->assertEquals( $time->format( 'U' ), $action_date->format( 'U' ) );
47
+		$this->assertEquals($time->format('U'), $action_date->format('U'));
48 48
 	}
49 49
 
50 50
 	public function test_retrieve_action() {
51 51
 		$time      = as_get_datetime_object();
52
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
53
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
52
+		$schedule  = new ActionScheduler_SimpleSchedule($time);
53
+		$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group');
54 54
 		$store     = new ActionScheduler_DBStore();
55
-		$action_id = $store->save_action( $action );
55
+		$action_id = $store->save_action($action);
56 56
 
57
-		$retrieved = $store->fetch_action( $action_id );
58
-		$this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
59
-		$this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
60
-		$this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
61
-		$this->assertEquals( $action->get_group(), $retrieved->get_group() );
57
+		$retrieved = $store->fetch_action($action_id);
58
+		$this->assertEquals($action->get_hook(), $retrieved->get_hook());
59
+		$this->assertEqualSets($action->get_args(), $retrieved->get_args());
60
+		$this->assertEquals($action->get_schedule()->get_date()->format('U'), $retrieved->get_schedule()->get_date()->format('U'));
61
+		$this->assertEquals($action->get_group(), $retrieved->get_group());
62 62
 	}
63 63
 
64 64
 	public function test_cancel_action() {
65 65
 		$time      = as_get_datetime_object();
66
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
67
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
66
+		$schedule  = new ActionScheduler_SimpleSchedule($time);
67
+		$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group');
68 68
 		$store     = new ActionScheduler_DBStore();
69
-		$action_id = $store->save_action( $action );
70
-		$store->cancel_action( $action_id );
69
+		$action_id = $store->save_action($action);
70
+		$store->cancel_action($action_id);
71 71
 
72
-		$fetched = $store->fetch_action( $action_id );
73
-		$this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
72
+		$fetched = $store->fetch_action($action_id);
73
+		$this->assertInstanceOf('ActionScheduler_CanceledAction', $fetched);
74 74
 	}
75 75
 
76 76
 	public function test_cancel_actions_by_hook() {
77 77
 		$store   = new ActionScheduler_DBStore();
78 78
 		$actions = array();
79 79
 		$hook    = 'by_hook_test';
80
-		for ( $day = 1; $day <= 3; $day++ ) {
81
-			$delta     = sprintf( '+%d day', $day );
82
-			$time      = as_get_datetime_object( $delta );
83
-			$schedule  = new ActionScheduler_SimpleSchedule( $time );
84
-			$action    = new ActionScheduler_Action( $hook, array(), $schedule, 'my_group' );
85
-			$actions[] = $store->save_action( $action );
80
+		for ($day = 1; $day <= 3; $day++) {
81
+			$delta     = sprintf('+%d day', $day);
82
+			$time      = as_get_datetime_object($delta);
83
+			$schedule  = new ActionScheduler_SimpleSchedule($time);
84
+			$action    = new ActionScheduler_Action($hook, array(), $schedule, 'my_group');
85
+			$actions[] = $store->save_action($action);
86 86
 		}
87
-		$store->cancel_actions_by_hook( $hook );
87
+		$store->cancel_actions_by_hook($hook);
88 88
 
89
-		foreach ( $actions as $action_id ) {
90
-			$fetched = $store->fetch_action( $action_id );
91
-			$this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
89
+		foreach ($actions as $action_id) {
90
+			$fetched = $store->fetch_action($action_id);
91
+			$this->assertInstanceOf('ActionScheduler_CanceledAction', $fetched);
92 92
 		}
93 93
 	}
94 94
 
@@ -96,62 +96,62 @@  discard block
 block discarded – undo
96 96
 		$store   = new ActionScheduler_DBStore();
97 97
 		$actions = array();
98 98
 		$group   = 'by_group_test';
99
-		for ( $day = 1; $day <= 3; $day++ ) {
100
-			$delta     = sprintf( '+%d day', $day );
101
-			$time      = as_get_datetime_object( $delta );
102
-			$schedule  = new ActionScheduler_SimpleSchedule( $time );
103
-			$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, $group );
104
-			$actions[] = $store->save_action( $action );
99
+		for ($day = 1; $day <= 3; $day++) {
100
+			$delta     = sprintf('+%d day', $day);
101
+			$time      = as_get_datetime_object($delta);
102
+			$schedule  = new ActionScheduler_SimpleSchedule($time);
103
+			$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, $group);
104
+			$actions[] = $store->save_action($action);
105 105
 		}
106
-		$store->cancel_actions_by_group( $group );
106
+		$store->cancel_actions_by_group($group);
107 107
 
108
-		foreach ( $actions as $action_id ) {
109
-			$fetched = $store->fetch_action( $action_id );
110
-			$this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
108
+		foreach ($actions as $action_id) {
109
+			$fetched = $store->fetch_action($action_id);
110
+			$this->assertInstanceOf('ActionScheduler_CanceledAction', $fetched);
111 111
 		}
112 112
 	}
113 113
 
114 114
 	public function test_claim_actions() {
115 115
 		$created_actions = array();
116 116
 		$store           = new ActionScheduler_DBStore();
117
-		for ( $i = 3; $i > - 3; $i -- ) {
118
-			$time     = as_get_datetime_object( $i . ' hours' );
119
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
120
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
117
+		for ($i = 3; $i > - 3; $i--) {
118
+			$time     = as_get_datetime_object($i.' hours');
119
+			$schedule = new ActionScheduler_SimpleSchedule($time);
120
+			$action   = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array($i), $schedule, 'my_group');
121 121
 
122
-			$created_actions[] = $store->save_action( $action );
122
+			$created_actions[] = $store->save_action($action);
123 123
 		}
124 124
 
125 125
 		$claim = $store->stake_claim();
126
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
126
+		$this->assertInstanceof('ActionScheduler_ActionClaim', $claim);
127 127
 
128
-		$this->assertCount( 3, $claim->get_actions() );
129
-		$this->assertEqualSets( array_slice( $created_actions, 3, 3 ), $claim->get_actions() );
128
+		$this->assertCount(3, $claim->get_actions());
129
+		$this->assertEqualSets(array_slice($created_actions, 3, 3), $claim->get_actions());
130 130
 	}
131 131
 
132 132
 	public function test_claim_actions_order() {
133 133
 
134 134
 		$store           = new ActionScheduler_DBStore();
135
-		$schedule        = new ActionScheduler_SimpleSchedule( as_get_datetime_object( '-1 hour' ) );
135
+		$schedule        = new ActionScheduler_SimpleSchedule(as_get_datetime_object('-1 hour'));
136 136
 		$created_actions = array(
137
-			$store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'my_group' ) ),
138
-			$store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'my_group' ) ),
137
+			$store->save_action(new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(1), $schedule, 'my_group')),
138
+			$store->save_action(new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(1), $schedule, 'my_group')),
139 139
 		);
140 140
 
141 141
 		$claim = $store->stake_claim();
142
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
142
+		$this->assertInstanceof('ActionScheduler_ActionClaim', $claim);
143 143
 
144 144
 		// Verify uniqueness of action IDs.
145
-		$this->assertCount( 2, array_unique( $created_actions ) );
145
+		$this->assertCount(2, array_unique($created_actions));
146 146
 
147 147
 		// Verify the count and order of the actions.
148 148
 		$claimed_actions = $claim->get_actions();
149
-		$this->assertCount( 2, $claimed_actions );
150
-		$this->assertEquals( $created_actions, $claimed_actions );
149
+		$this->assertCount(2, $claimed_actions);
150
+		$this->assertEquals($created_actions, $claimed_actions);
151 151
 
152 152
 		// Verify the reversed order doesn't pass.
153
-		$reversed_actions = array_reverse( $created_actions );
154
-		$this->assertNotEquals( $reversed_actions, $claimed_actions );
153
+		$reversed_actions = array_reverse($created_actions);
154
+		$this->assertNotEquals($reversed_actions, $claimed_actions);
155 155
 	}
156 156
 
157 157
 	public function test_claim_actions_by_hooks() {
@@ -164,35 +164,35 @@  discard block
 block discarded – undo
164 164
 			$unique_hook_two,
165 165
 		);
166 166
 
167
-		for ( $i = 3; $i > - 3; $i -- ) {
168
-			foreach ( $unique_hooks as $unique_hook ) {
169
-				$time     = as_get_datetime_object( $i . ' hours' );
170
-				$schedule = new ActionScheduler_SimpleSchedule( $time );
171
-				$action   = new ActionScheduler_Action( $unique_hook, array( $i ), $schedule, 'my_group' );
167
+		for ($i = 3; $i > - 3; $i--) {
168
+			foreach ($unique_hooks as $unique_hook) {
169
+				$time     = as_get_datetime_object($i.' hours');
170
+				$schedule = new ActionScheduler_SimpleSchedule($time);
171
+				$action   = new ActionScheduler_Action($unique_hook, array($i), $schedule, 'my_group');
172 172
 
173
-				$action_id         = $store->save_action( $action );
174
-				$created_actions[] = $created_actions_by_hook[ $unique_hook ][] = $action_id;
173
+				$action_id         = $store->save_action($action);
174
+				$created_actions[] = $created_actions_by_hook[$unique_hook][] = $action_id;
175 175
 			}
176 176
 		}
177 177
 
178
-		$claim = $store->stake_claim( 10, null, $unique_hooks );
179
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
180
-		$this->assertCount( 6, $claim->get_actions() );
181
-		$this->assertEqualSets( array_slice( $created_actions, 6, 6 ), $claim->get_actions() );
178
+		$claim = $store->stake_claim(10, null, $unique_hooks);
179
+		$this->assertInstanceof('ActionScheduler_ActionClaim', $claim);
180
+		$this->assertCount(6, $claim->get_actions());
181
+		$this->assertEqualSets(array_slice($created_actions, 6, 6), $claim->get_actions());
182 182
 
183
-		$store->release_claim( $claim );
183
+		$store->release_claim($claim);
184 184
 
185
-		$claim = $store->stake_claim( 10, null, array( $unique_hook_one ) );
186
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
187
-		$this->assertCount( 3, $claim->get_actions() );
188
-		$this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_one ], 3, 3 ), $claim->get_actions() );
185
+		$claim = $store->stake_claim(10, null, array($unique_hook_one));
186
+		$this->assertInstanceof('ActionScheduler_ActionClaim', $claim);
187
+		$this->assertCount(3, $claim->get_actions());
188
+		$this->assertEqualSets(array_slice($created_actions_by_hook[$unique_hook_one], 3, 3), $claim->get_actions());
189 189
 
190
-		$store->release_claim( $claim );
190
+		$store->release_claim($claim);
191 191
 
192
-		$claim = $store->stake_claim( 10, null, array( $unique_hook_two ) );
193
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
194
-		$this->assertCount( 3, $claim->get_actions() );
195
-		$this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_two ], 3, 3 ), $claim->get_actions() );
192
+		$claim = $store->stake_claim(10, null, array($unique_hook_two));
193
+		$this->assertInstanceof('ActionScheduler_ActionClaim', $claim);
194
+		$this->assertCount(3, $claim->get_actions());
195
+		$this->assertEqualSets(array_slice($created_actions_by_hook[$unique_hook_two], 3, 3), $claim->get_actions());
196 196
 	}
197 197
 
198 198
 	public function test_claim_actions_by_group() {
@@ -205,27 +205,27 @@  discard block
 block discarded – undo
205 205
 			$unique_group_two,
206 206
 		);
207 207
 
208
-		for ( $i = 3; $i > - 3; $i -- ) {
209
-			foreach ( $unique_groups as $unique_group ) {
210
-				$time     = as_get_datetime_object( $i . ' hours' );
211
-				$schedule = new ActionScheduler_SimpleSchedule( $time );
212
-				$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, $unique_group );
208
+		for ($i = 3; $i > - 3; $i--) {
209
+			foreach ($unique_groups as $unique_group) {
210
+				$time     = as_get_datetime_object($i.' hours');
211
+				$schedule = new ActionScheduler_SimpleSchedule($time);
212
+				$action   = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array($i), $schedule, $unique_group);
213 213
 
214
-				$created_actions[ $unique_group ][] = $store->save_action( $action );
214
+				$created_actions[$unique_group][] = $store->save_action($action);
215 215
 			}
216 216
 		}
217 217
 
218
-		$claim = $store->stake_claim( 10, null, array(), $unique_group_one );
219
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
220
-		$this->assertCount( 3, $claim->get_actions() );
221
-		$this->assertEqualSets( array_slice( $created_actions[ $unique_group_one ], 3, 3 ), $claim->get_actions() );
218
+		$claim = $store->stake_claim(10, null, array(), $unique_group_one);
219
+		$this->assertInstanceof('ActionScheduler_ActionClaim', $claim);
220
+		$this->assertCount(3, $claim->get_actions());
221
+		$this->assertEqualSets(array_slice($created_actions[$unique_group_one], 3, 3), $claim->get_actions());
222 222
 
223
-		$store->release_claim( $claim );
223
+		$store->release_claim($claim);
224 224
 
225
-		$claim = $store->stake_claim( 10, null, array(), $unique_group_two );
226
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
227
-		$this->assertCount( 3, $claim->get_actions() );
228
-		$this->assertEqualSets( array_slice( $created_actions[ $unique_group_two ], 3, 3 ), $claim->get_actions() );
225
+		$claim = $store->stake_claim(10, null, array(), $unique_group_two);
226
+		$this->assertInstanceof('ActionScheduler_ActionClaim', $claim);
227
+		$this->assertCount(3, $claim->get_actions());
228
+		$this->assertEqualSets(array_slice($created_actions[$unique_group_two], 3, 3), $claim->get_actions());
229 229
 	}
230 230
 
231 231
 	public function test_claim_actions_by_hook_and_group() {
@@ -246,65 +246,65 @@  discard block
 block discarded – undo
246 246
 			$unique_group_two,
247 247
 		);
248 248
 
249
-		for ( $i = 3; $i > - 3; $i -- ) {
250
-			foreach ( $unique_hooks as $unique_hook ) {
251
-				foreach ( $unique_groups as $unique_group ) {
252
-					$time     = as_get_datetime_object( $i . ' hours' );
253
-					$schedule = new ActionScheduler_SimpleSchedule( $time );
254
-					$action   = new ActionScheduler_Action( $unique_hook, array( $i ), $schedule, $unique_group );
249
+		for ($i = 3; $i > - 3; $i--) {
250
+			foreach ($unique_hooks as $unique_hook) {
251
+				foreach ($unique_groups as $unique_group) {
252
+					$time     = as_get_datetime_object($i.' hours');
253
+					$schedule = new ActionScheduler_SimpleSchedule($time);
254
+					$action   = new ActionScheduler_Action($unique_hook, array($i), $schedule, $unique_group);
255 255
 
256
-					$action_id                          = $store->save_action( $action );
257
-					$created_actions[ $unique_group ][] = $action_id;
258
-					$created_actions_by_hook[ $unique_hook ][ $unique_group ][] = $action_id;
256
+					$action_id                          = $store->save_action($action);
257
+					$created_actions[$unique_group][] = $action_id;
258
+					$created_actions_by_hook[$unique_hook][$unique_group][] = $action_id;
259 259
 				}
260 260
 			}
261 261
 		}
262 262
 
263 263
 		/** Test Both Hooks with Each Group */
264 264
 
265
-		$claim = $store->stake_claim( 10, null, $unique_hooks, $unique_group_one );
266
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
267
-		$this->assertCount( 6, $claim->get_actions() );
268
-		$this->assertEqualSets( array_slice( $created_actions[ $unique_group_one ], 6, 6 ), $claim->get_actions() );
265
+		$claim = $store->stake_claim(10, null, $unique_hooks, $unique_group_one);
266
+		$this->assertInstanceof('ActionScheduler_ActionClaim', $claim);
267
+		$this->assertCount(6, $claim->get_actions());
268
+		$this->assertEqualSets(array_slice($created_actions[$unique_group_one], 6, 6), $claim->get_actions());
269 269
 
270
-		$store->release_claim( $claim );
270
+		$store->release_claim($claim);
271 271
 
272
-		$claim = $store->stake_claim( 10, null, $unique_hooks, $unique_group_two );
273
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
274
-		$this->assertCount( 6, $claim->get_actions() );
275
-		$this->assertEqualSets( array_slice( $created_actions[ $unique_group_two ], 6, 6 ), $claim->get_actions() );
272
+		$claim = $store->stake_claim(10, null, $unique_hooks, $unique_group_two);
273
+		$this->assertInstanceof('ActionScheduler_ActionClaim', $claim);
274
+		$this->assertCount(6, $claim->get_actions());
275
+		$this->assertEqualSets(array_slice($created_actions[$unique_group_two], 6, 6), $claim->get_actions());
276 276
 
277
-		$store->release_claim( $claim );
277
+		$store->release_claim($claim);
278 278
 
279 279
 		/** Test Just One Hook with Group One */
280 280
 
281
-		$claim = $store->stake_claim( 10, null, array( $unique_hook_one ), $unique_group_one );
282
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
283
-		$this->assertCount( 3, $claim->get_actions() );
284
-		$this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_one ][ $unique_group_one ], 3, 3 ), $claim->get_actions() );
281
+		$claim = $store->stake_claim(10, null, array($unique_hook_one), $unique_group_one);
282
+		$this->assertInstanceof('ActionScheduler_ActionClaim', $claim);
283
+		$this->assertCount(3, $claim->get_actions());
284
+		$this->assertEqualSets(array_slice($created_actions_by_hook[$unique_hook_one][$unique_group_one], 3, 3), $claim->get_actions());
285 285
 
286
-		$store->release_claim( $claim );
286
+		$store->release_claim($claim);
287 287
 
288
-		$claim = $store->stake_claim( 24, null, array( $unique_hook_two ), $unique_group_one );
289
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
290
-		$this->assertCount( 3, $claim->get_actions() );
291
-		$this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_two ][ $unique_group_one ], 3, 3 ), $claim->get_actions() );
288
+		$claim = $store->stake_claim(24, null, array($unique_hook_two), $unique_group_one);
289
+		$this->assertInstanceof('ActionScheduler_ActionClaim', $claim);
290
+		$this->assertCount(3, $claim->get_actions());
291
+		$this->assertEqualSets(array_slice($created_actions_by_hook[$unique_hook_two][$unique_group_one], 3, 3), $claim->get_actions());
292 292
 
293
-		$store->release_claim( $claim );
293
+		$store->release_claim($claim);
294 294
 
295 295
 		/** Test Just One Hook with Group Two */
296 296
 
297
-		$claim = $store->stake_claim( 10, null, array( $unique_hook_one ), $unique_group_two );
298
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
299
-		$this->assertCount( 3, $claim->get_actions() );
300
-		$this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_one ][ $unique_group_two ], 3, 3 ), $claim->get_actions() );
297
+		$claim = $store->stake_claim(10, null, array($unique_hook_one), $unique_group_two);
298
+		$this->assertInstanceof('ActionScheduler_ActionClaim', $claim);
299
+		$this->assertCount(3, $claim->get_actions());
300
+		$this->assertEqualSets(array_slice($created_actions_by_hook[$unique_hook_one][$unique_group_two], 3, 3), $claim->get_actions());
301 301
 
302
-		$store->release_claim( $claim );
302
+		$store->release_claim($claim);
303 303
 
304
-		$claim = $store->stake_claim( 24, null, array( $unique_hook_two ), $unique_group_two );
305
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
306
-		$this->assertCount( 3, $claim->get_actions() );
307
-		$this->assertEqualSets( array_slice( $created_actions_by_hook[ $unique_hook_two ][ $unique_group_two ], 3, 3 ), $claim->get_actions() );
304
+		$claim = $store->stake_claim(24, null, array($unique_hook_two), $unique_group_two);
305
+		$this->assertInstanceof('ActionScheduler_ActionClaim', $claim);
306
+		$this->assertCount(3, $claim->get_actions());
307
+		$this->assertEqualSets(array_slice($created_actions_by_hook[$unique_hook_two][$unique_group_two], 3, 3), $claim->get_actions());
308 308
 	}
309 309
 
310 310
 	/**
@@ -322,129 +322,129 @@  discard block
 block discarded – undo
322 322
 		$store = new ActionScheduler_DBStore();
323 323
 
324 324
 		// Create 4 actions: 2 that are already due (-3hrs and -1hrs) and 2 that are not yet due (+1hr and +3hrs).
325
-		for ( $i = -3; $i <= 3; $i += 2 ) {
326
-			$schedule     = new ActionScheduler_SimpleSchedule( as_get_datetime_object( $i . ' hours' ) );
327
-			$action_ids[] = $store->save_action( new ActionScheduler_Action( 'test_' . $i, array(), $schedule, $group ) );
325
+		for ($i = -3; $i <= 3; $i += 2) {
326
+			$schedule     = new ActionScheduler_SimpleSchedule(as_get_datetime_object($i.' hours'));
327
+			$action_ids[] = $store->save_action(new ActionScheduler_Action('test_'.$i, array(), $schedule, $group));
328 328
 		}
329 329
 
330 330
 		// This callback is used to simulate the unusual conditions whereby MySQL might unexpectedly return future
331 331
 		// actions, contrary to the conditions used by the store object when staking its claim.
332
-		$simulate_unexpected_db_behavior = function ( $sql ) use ( $action_ids ) {
332
+		$simulate_unexpected_db_behavior = function($sql) use ($action_ids) {
333 333
 			global $wpdb;
334 334
 
335 335
 			// Look out for the claim update query, ignore all others.
336 336
 			if (
337
-				0 !== strpos( $sql, "UPDATE $wpdb->actionscheduler_actions" )
338
-				|| ! preg_match( "/claim_id = 0 AND scheduled_date_gmt <= '([0-9:\-\s]{19})'/", $sql, $matches )
339
-				|| count( $matches ) !== 2
337
+				0 !== strpos($sql, "UPDATE $wpdb->actionscheduler_actions")
338
+				|| ! preg_match("/claim_id = 0 AND scheduled_date_gmt <= '([0-9:\-\s]{19})'/", $sql, $matches)
339
+				|| count($matches) !== 2
340 340
 			) {
341 341
 				return $sql;
342 342
 			}
343 343
 
344 344
 			// Now modify the query, forcing it to also return the future actions we created.
345
-			return str_replace( $matches[1], as_get_datetime_object( '+4 hours' )->format( 'Y-m-d H:i:s' ), $sql );
345
+			return str_replace($matches[1], as_get_datetime_object('+4 hours')->format('Y-m-d H:i:s'), $sql);
346 346
 		};
347 347
 
348
-		add_filter( 'query', $simulate_unexpected_db_behavior );
349
-		$claim           = $store->stake_claim( 10, null, array(), $group );
348
+		add_filter('query', $simulate_unexpected_db_behavior);
349
+		$claim           = $store->stake_claim(10, null, array(), $group);
350 350
 		$claimed_actions = $claim->get_actions();
351
-		$this->assertCount( 2, $claimed_actions );
351
+		$this->assertCount(2, $claimed_actions);
352 352
 
353 353
 		// Cleanup.
354
-		remove_filter( 'query', $simulate_unexpected_db_behavior );
355
-		$store->release_claim( $claim );
354
+		remove_filter('query', $simulate_unexpected_db_behavior);
355
+		$store->release_claim($claim);
356 356
 	}
357 357
 
358 358
 	public function test_duplicate_claim() {
359 359
 		$created_actions = array();
360 360
 		$store           = new ActionScheduler_DBStore();
361
-		for ( $i = 0; $i > - 3; $i -- ) {
362
-			$time     = as_get_datetime_object( $i . ' hours' );
363
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
364
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
361
+		for ($i = 0; $i > - 3; $i--) {
362
+			$time     = as_get_datetime_object($i.' hours');
363
+			$schedule = new ActionScheduler_SimpleSchedule($time);
364
+			$action   = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array($i), $schedule, 'my_group');
365 365
 
366
-			$created_actions[] = $store->save_action( $action );
366
+			$created_actions[] = $store->save_action($action);
367 367
 		}
368 368
 
369 369
 		$claim1 = $store->stake_claim();
370 370
 		$claim2 = $store->stake_claim();
371
-		$this->assertCount( 3, $claim1->get_actions() );
372
-		$this->assertCount( 0, $claim2->get_actions() );
371
+		$this->assertCount(3, $claim1->get_actions());
372
+		$this->assertCount(0, $claim2->get_actions());
373 373
 	}
374 374
 
375 375
 	public function test_release_claim() {
376 376
 		$created_actions = array();
377 377
 		$store           = new ActionScheduler_DBStore();
378
-		for ( $i = 0; $i > - 3; $i -- ) {
379
-			$time     = as_get_datetime_object( $i . ' hours' );
380
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
381
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
378
+		for ($i = 0; $i > - 3; $i--) {
379
+			$time     = as_get_datetime_object($i.' hours');
380
+			$schedule = new ActionScheduler_SimpleSchedule($time);
381
+			$action   = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array($i), $schedule, 'my_group');
382 382
 
383
-			$created_actions[] = $store->save_action( $action );
383
+			$created_actions[] = $store->save_action($action);
384 384
 		}
385 385
 
386 386
 		$claim1 = $store->stake_claim();
387 387
 
388
-		$store->release_claim( $claim1 );
388
+		$store->release_claim($claim1);
389 389
 
390 390
 		$claim2 = $store->stake_claim();
391
-		$this->assertCount( 3, $claim2->get_actions() );
391
+		$this->assertCount(3, $claim2->get_actions());
392 392
 	}
393 393
 
394 394
 	public function test_search() {
395 395
 		$created_actions = array();
396 396
 		$store           = new ActionScheduler_DBStore();
397
-		for ( $i = - 3; $i <= 3; $i ++ ) {
398
-			$time     = as_get_datetime_object( $i . ' hours' );
399
-			$schedule = new ActionScheduler_SimpleSchedule( $time );
400
-			$action   = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
397
+		for ($i = - 3; $i <= 3; $i++) {
398
+			$time     = as_get_datetime_object($i.' hours');
399
+			$schedule = new ActionScheduler_SimpleSchedule($time);
400
+			$action   = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array($i), $schedule, 'my_group');
401 401
 
402
-			$created_actions[] = $store->save_action( $action );
402
+			$created_actions[] = $store->save_action($action);
403 403
 		}
404 404
 
405
-		$next_no_args = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK );
406
-		$this->assertEquals( $created_actions[0], $next_no_args );
405
+		$next_no_args = $store->find_action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK);
406
+		$this->assertEquals($created_actions[0], $next_no_args);
407 407
 
408
-		$next_with_args = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'args' => array( 1 ) ) );
409
-		$this->assertEquals( $created_actions[4], $next_with_args );
408
+		$next_with_args = $store->find_action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array('args' => array(1)));
409
+		$this->assertEquals($created_actions[4], $next_with_args);
410 410
 
411
-		$non_existent = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'args' => array( 17 ) ) );
412
-		$this->assertNull( $non_existent );
411
+		$non_existent = $store->find_action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array('args' => array(17)));
412
+		$this->assertNull($non_existent);
413 413
 	}
414 414
 
415 415
 	public function test_search_by_group() {
416 416
 		$store    = new ActionScheduler_DBStore();
417
-		$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( 'tomorrow' ) );
417
+		$schedule = new ActionScheduler_SimpleSchedule(as_get_datetime_object('tomorrow'));
418 418
 
419
-		$abc = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'abc' ) );
420
-		$def = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'def' ) );
421
-		$ghi = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'ghi' ) );
419
+		$abc = $store->save_action(new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(1), $schedule, 'abc'));
420
+		$def = $store->save_action(new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(1), $schedule, 'def'));
421
+		$ghi = $store->save_action(new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(1), $schedule, 'ghi'));
422 422
 
423
-		$this->assertEquals( $abc, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'abc' ) ) );
424
-		$this->assertEquals( $def, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'def' ) ) );
425
-		$this->assertEquals( $ghi, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'ghi' ) ) );
423
+		$this->assertEquals($abc, $store->find_action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array('group' => 'abc')));
424
+		$this->assertEquals($def, $store->find_action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array('group' => 'def')));
425
+		$this->assertEquals($ghi, $store->find_action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array('group' => 'ghi')));
426 426
 	}
427 427
 
428 428
 	public function test_get_run_date() {
429
-		$time      = as_get_datetime_object( '-10 minutes' );
430
-		$schedule  = new ActionScheduler_IntervalSchedule( $time, HOUR_IN_SECONDS );
431
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
429
+		$time      = as_get_datetime_object('-10 minutes');
430
+		$schedule  = new ActionScheduler_IntervalSchedule($time, HOUR_IN_SECONDS);
431
+		$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
432 432
 		$store     = new ActionScheduler_DBStore();
433
-		$action_id = $store->save_action( $action );
433
+		$action_id = $store->save_action($action);
434 434
 
435
-		$this->assertEquals( $time->format( 'U' ), $store->get_date( $action_id )->format( 'U' ) );
435
+		$this->assertEquals($time->format('U'), $store->get_date($action_id)->format('U'));
436 436
 
437
-		$action = $store->fetch_action( $action_id );
437
+		$action = $store->fetch_action($action_id);
438 438
 		$action->execute();
439 439
 		$now = as_get_datetime_object();
440
-		$store->mark_complete( $action_id );
440
+		$store->mark_complete($action_id);
441 441
 
442
-		$this->assertEquals( $now->format( 'U' ), $store->get_date( $action_id )->format( 'U' ) );
442
+		$this->assertEquals($now->format('U'), $store->get_date($action_id)->format('U'));
443 443
 
444
-		$next          = $action->get_schedule()->get_next( $now );
445
-		$new_action_id = $store->save_action( $action, $next );
444
+		$next          = $action->get_schedule()->get_next($now);
445
+		$new_action_id = $store->save_action($action, $next);
446 446
 
447
-		$this->assertEquals( (int) ( $now->format( 'U' ) ) + HOUR_IN_SECONDS, $store->get_date( $new_action_id )->format( 'U' ) );
447
+		$this->assertEquals((int) ($now->format('U')) + HOUR_IN_SECONDS, $store->get_date($new_action_id)->format('U'));
448 448
 	}
449 449
 
450 450
 	/**
@@ -452,19 +452,19 @@  discard block
 block discarded – undo
452 452
 	 */
453 453
 	public function test_create_action_unique() {
454 454
 		$time     = as_get_datetime_object();
455
-		$hook     = md5( rand() );
456
-		$schedule = new ActionScheduler_SimpleSchedule( $time );
455
+		$hook     = md5(rand());
456
+		$schedule = new ActionScheduler_SimpleSchedule($time);
457 457
 		$store    = new ActionScheduler_DBStore();
458
-		$action   = new ActionScheduler_Action( $hook, array(), $schedule );
458
+		$action   = new ActionScheduler_Action($hook, array(), $schedule);
459 459
 
460
-		$action_id = $store->save_action( $action );
461
-		$this->assertNotEquals( 0, $action_id );
462
-		$action_from_db = $store->fetch_action( $action_id );
463
-		$this->assertTrue( is_a( $action_from_db, ActionScheduler_Action::class ) );
460
+		$action_id = $store->save_action($action);
461
+		$this->assertNotEquals(0, $action_id);
462
+		$action_from_db = $store->fetch_action($action_id);
463
+		$this->assertTrue(is_a($action_from_db, ActionScheduler_Action::class));
464 464
 
465
-		$action              = new ActionScheduler_Action( $hook, array(), $schedule );
466
-		$action_id_duplicate = $store->save_unique_action( $action );
467
-		$this->assertSame( 0, $action_id_duplicate );
465
+		$action              = new ActionScheduler_Action($hook, array(), $schedule);
466
+		$action_id_duplicate = $store->save_unique_action($action);
467
+		$this->assertSame(0, $action_id_duplicate);
468 468
 	}
469 469
 
470 470
 	/**
@@ -472,25 +472,25 @@  discard block
 block discarded – undo
472 472
 	 */
473 473
 	public function test_create_action_unique_with_different_groups() {
474 474
 		$time     = as_get_datetime_object();
475
-		$hook     = md5( rand() );
476
-		$schedule = new ActionScheduler_SimpleSchedule( $time );
475
+		$hook     = md5(rand());
476
+		$schedule = new ActionScheduler_SimpleSchedule($time);
477 477
 		$store    = new ActionScheduler_DBStore();
478
-		$action   = new ActionScheduler_Action( $hook, array(), $schedule, 'group1' );
479
-
480
-		$action_id      = $store->save_action( $action );
481
-		$action_from_db = $store->fetch_action( $action_id );
482
-		$this->assertNotEquals( 0, $action_id );
483
-		$this->assertTrue( is_a( $action_from_db, ActionScheduler_Action::class ) );
484
-
485
-		$action2          = new ActionScheduler_Action( $hook, array(), $schedule, 'group2' );
486
-		$action_id_group2 = $store->save_unique_action( $action2 );
487
-		$this->assertNotEquals( 0, $action_id_group2 );
488
-		$action_2_from_db = $store->fetch_action( $action_id_group2 );
489
-		$this->assertTrue( is_a( $action_2_from_db, ActionScheduler_Action::class ) );
490
-
491
-		$action3                 = new ActionScheduler_Action( $hook, array(), $schedule, 'group2' );
492
-		$action_id_group2_double = $store->save_unique_action( $action3 );
493
-		$this->assertSame( 0, $action_id_group2_double );
478
+		$action   = new ActionScheduler_Action($hook, array(), $schedule, 'group1');
479
+
480
+		$action_id      = $store->save_action($action);
481
+		$action_from_db = $store->fetch_action($action_id);
482
+		$this->assertNotEquals(0, $action_id);
483
+		$this->assertTrue(is_a($action_from_db, ActionScheduler_Action::class));
484
+
485
+		$action2          = new ActionScheduler_Action($hook, array(), $schedule, 'group2');
486
+		$action_id_group2 = $store->save_unique_action($action2);
487
+		$this->assertNotEquals(0, $action_id_group2);
488
+		$action_2_from_db = $store->fetch_action($action_id_group2);
489
+		$this->assertTrue(is_a($action_2_from_db, ActionScheduler_Action::class));
490
+
491
+		$action3                 = new ActionScheduler_Action($hook, array(), $schedule, 'group2');
492
+		$action_id_group2_double = $store->save_unique_action($action3);
493
+		$this->assertSame(0, $action_id_group2_double);
494 494
 	}
495 495
 
496 496
 	/**
@@ -498,22 +498,22 @@  discard block
 block discarded – undo
498 498
 	 */
499 499
 	public function test_create_action_unique_and_then_non_unique() {
500 500
 		$time     = as_get_datetime_object();
501
-		$hook     = md5( rand() );
502
-		$schedule = new ActionScheduler_SimpleSchedule( $time );
501
+		$hook     = md5(rand());
502
+		$schedule = new ActionScheduler_SimpleSchedule($time);
503 503
 		$store    = new ActionScheduler_DBStore();
504
-		$action   = new ActionScheduler_Action( $hook, array(), $schedule );
504
+		$action   = new ActionScheduler_Action($hook, array(), $schedule);
505 505
 
506
-		$action_id = $store->save_unique_action( $action );
507
-		$this->assertNotEquals( 0, $action_id );
508
-		$action_from_db = $store->fetch_action( $action_id );
509
-		$this->assertTrue( is_a( $action_from_db, ActionScheduler_Action::class ) );
506
+		$action_id = $store->save_unique_action($action);
507
+		$this->assertNotEquals(0, $action_id);
508
+		$action_from_db = $store->fetch_action($action_id);
509
+		$this->assertTrue(is_a($action_from_db, ActionScheduler_Action::class));
510 510
 
511 511
 		// Non unique action is scheduled even if the previous one was unique.
512
-		$action              = new ActionScheduler_Action( $hook, array(), $schedule );
513
-		$action_id_duplicate = $store->save_action( $action );
514
-		$this->assertNotEquals( 0, $action_id_duplicate );
515
-		$action_from_db_duplicate = $store->fetch_action( $action_id_duplicate );
516
-		$this->assertTrue( is_a( $action_from_db_duplicate, ActionScheduler_Action::class ) );
512
+		$action              = new ActionScheduler_Action($hook, array(), $schedule);
513
+		$action_id_duplicate = $store->save_action($action);
514
+		$this->assertNotEquals(0, $action_id_duplicate);
515
+		$action_from_db_duplicate = $store->fetch_action($action_id_duplicate);
516
+		$this->assertTrue(is_a($action_from_db_duplicate, ActionScheduler_Action::class));
517 517
 	}
518 518
 
519 519
 	/**
@@ -521,19 +521,19 @@  discard block
 block discarded – undo
521 521
 	 */
522 522
 	public function test_create_action_unique_with_empty_array() {
523 523
 		$time     = as_get_datetime_object();
524
-		$hook     = md5( rand() );
525
-		$schedule = new ActionScheduler_SimpleSchedule( $time );
524
+		$hook     = md5(rand());
525
+		$schedule = new ActionScheduler_SimpleSchedule($time);
526 526
 		$store    = new ActionScheduler_DBStore();
527
-		$action   = new ActionScheduler_Action( $hook, array( 'foo' => 'bar' ), $schedule );
527
+		$action   = new ActionScheduler_Action($hook, array('foo' => 'bar'), $schedule);
528 528
 
529
-		$action_id = $store->save_unique_action( $action );
530
-		$this->assertNotEquals( 0, $action_id );
531
-		$action_from_db = $store->fetch_action( $action_id );
532
-		$this->assertTrue( is_a( $action_from_db, ActionScheduler_Action::class ) );
529
+		$action_id = $store->save_unique_action($action);
530
+		$this->assertNotEquals(0, $action_id);
531
+		$action_from_db = $store->fetch_action($action_id);
532
+		$this->assertTrue(is_a($action_from_db, ActionScheduler_Action::class));
533 533
 
534
-		$action_with_empty_args = new ActionScheduler_Action( $hook, array(), $schedule );
535
-		$action_id_duplicate    = $store->save_unique_action( $action_with_empty_args );
536
-		$this->assertSame( 0, $action_id_duplicate );
534
+		$action_with_empty_args = new ActionScheduler_Action($hook, array(), $schedule);
535
+		$action_id_duplicate    = $store->save_unique_action($action_with_empty_args);
536
+		$this->assertSame(0, $action_id_duplicate);
537 537
 	}
538 538
 
539 539
 	/**
@@ -541,18 +541,18 @@  discard block
 block discarded – undo
541 541
 	 */
542 542
 	public function test_create_action_unique_with_different_args_still_fail() {
543 543
 		$time     = as_get_datetime_object();
544
-		$hook     = md5( rand() );
545
-		$schedule = new ActionScheduler_SimpleSchedule( $time );
544
+		$hook     = md5(rand());
545
+		$schedule = new ActionScheduler_SimpleSchedule($time);
546 546
 		$store    = new ActionScheduler_DBStore();
547
-		$action   = new ActionScheduler_Action( $hook, array( 'foo' => 'bar' ), $schedule );
547
+		$action   = new ActionScheduler_Action($hook, array('foo' => 'bar'), $schedule);
548 548
 
549
-		$action_id = $store->save_unique_action( $action );
550
-		$this->assertNotEquals( 0, $action_id );
551
-		$action_from_db = $store->fetch_action( $action_id );
552
-		$this->assertTrue( is_a( $action_from_db, ActionScheduler_Action::class ) );
549
+		$action_id = $store->save_unique_action($action);
550
+		$this->assertNotEquals(0, $action_id);
551
+		$action_from_db = $store->fetch_action($action_id);
552
+		$this->assertTrue(is_a($action_from_db, ActionScheduler_Action::class));
553 553
 
554
-		$action_with_diff_args = new ActionScheduler_Action( $hook, array( 'foo' => 'bazz' ), $schedule );
555
-		$action_id_duplicate   = $store->save_unique_action( $action_with_diff_args );
556
-		$this->assertSame( 0, $action_id_duplicate );
554
+		$action_with_diff_args = new ActionScheduler_Action($hook, array('foo' => 'bazz'), $schedule);
555
+		$action_id_duplicate   = $store->save_unique_action($action_with_diff_args);
556
+		$this->assertSame(0, $action_id_duplicate);
557 557
 	}
558 558
 }
Please login to merge, or discard this patch.
tests/phpunit/jobstore/ActionScheduler_wpPostStore_Test.php 2 patches
Indentation   +453 added lines, -453 removed lines patch added patch discarded remove patch
@@ -9,457 +9,457 @@
 block discarded – undo
9 9
  */
10 10
 class ActionScheduler_wpPostStore_Test extends AbstractStoreTest {
11 11
 
12
-	/**
13
-	 * Get data store for tests.
14
-	 *
15
-	 * @return ActionScheduler_wpPostStore
16
-	 */
17
-	protected function get_store() {
18
-		return new ActionScheduler_wpPostStore();
19
-	}
20
-
21
-	public function test_create_action() {
22
-		$time      = as_get_datetime_object();
23
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
24
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
25
-		$store     = new ActionScheduler_wpPostStore();
26
-		$action_id = $store->save_action( $action );
27
-
28
-		$this->assertNotEmpty( $action_id );
29
-	}
30
-
31
-	public function test_create_action_with_scheduled_date() {
32
-		$time   = as_get_datetime_object( strtotime( '-1 week' ) );
33
-		$action = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), new ActionScheduler_SimpleSchedule( $time ) );
34
-		$store  = new ActionScheduler_wpPostStore();
35
-
36
-		$action_id   = $store->save_action( $action, $time );
37
-		$action_date = $store->get_date( $action_id );
38
-
39
-		$this->assertEquals( $time->getTimestamp(), $action_date->getTimestamp() );
40
-	}
41
-
42
-	public function test_retrieve_action() {
43
-		$time      = as_get_datetime_object();
44
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
45
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
46
-		$store     = new ActionScheduler_wpPostStore();
47
-		$action_id = $store->save_action( $action );
48
-
49
-		$retrieved = $store->fetch_action( $action_id );
50
-		$this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
51
-		$this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
52
-		$this->assertEquals( $action->get_schedule()->get_date()->getTimestamp(), $retrieved->get_schedule()->get_date()->getTimestamp() );
53
-		$this->assertEquals( $action->get_group(), $retrieved->get_group() );
54
-	}
55
-
56
-	/**
57
-	 * @dataProvider provide_bad_args
58
-	 *
59
-	 * @param string $content
60
-	 */
61
-	public function test_action_bad_args( $content ) {
62
-		$store   = new ActionScheduler_wpPostStore();
63
-		$post_id = wp_insert_post(
64
-			array(
65
-				'post_type'    => ActionScheduler_wpPostStore::POST_TYPE,
66
-				'post_status'  => ActionScheduler_Store::STATUS_PENDING,
67
-				'post_content' => $content,
68
-			)
69
-		);
70
-
71
-		$fetched = $store->fetch_action( $post_id );
72
-		$this->assertInstanceOf( 'ActionScheduler_NullSchedule', $fetched->get_schedule() );
73
-	}
74
-
75
-	public function provide_bad_args() {
76
-		return array(
77
-			array( '{"bad_json":true}}' ),
78
-		);
79
-	}
80
-
81
-	public function test_cancel_action() {
82
-		$time      = as_get_datetime_object();
83
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
84
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
85
-		$store     = new ActionScheduler_wpPostStore();
86
-		$action_id = $store->save_action( $action );
87
-		$store->cancel_action( $action_id );
88
-
89
-		$fetched = $store->fetch_action( $action_id );
90
-		$this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
91
-	}
92
-
93
-	public function test_cancel_actions_by_hook() {
94
-		$store   = new ActionScheduler_wpPostStore();
95
-		$actions = array();
96
-		$hook    = 'by_hook_test';
97
-		for ( $day = 1; $day <= 3; $day++ ) {
98
-			$delta     = sprintf( '+%d day', $day );
99
-			$time      = as_get_datetime_object( $delta );
100
-			$schedule  = new ActionScheduler_SimpleSchedule( $time );
101
-			$action    = new ActionScheduler_Action( $hook, array(), $schedule, 'my_group' );
102
-			$actions[] = $store->save_action( $action );
103
-		}
104
-		$store->cancel_actions_by_hook( $hook );
105
-
106
-		foreach ( $actions as $action_id ) {
107
-			$fetched = $store->fetch_action( $action_id );
108
-			$this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
109
-		}
110
-	}
111
-
112
-	public function test_cancel_actions_by_group() {
113
-		$store   = new ActionScheduler_wpPostStore();
114
-		$actions = array();
115
-		$group   = 'by_group_test';
116
-
117
-		for ( $day = 1; $day <= 3; $day++ ) {
118
-			$delta     = sprintf( '+%d day', $day );
119
-			$time      = as_get_datetime_object( $delta );
120
-			$schedule  = new ActionScheduler_SimpleSchedule( $time );
121
-			$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, $group );
122
-			$actions[] = $store->save_action( $action );
123
-		}
124
-		$store->cancel_actions_by_group( $group );
125
-
126
-		foreach ( $actions as $action_id ) {
127
-			$fetched = $store->fetch_action( $action_id );
128
-			$this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
129
-		}
130
-	}
131
-
132
-	public function test_claim_actions() {
133
-		$created_actions = array();
134
-		$store           = new ActionScheduler_wpPostStore();
135
-		for ( $i = 3; $i > -3; $i-- ) {
136
-			$time              = as_get_datetime_object( $i . ' hours' );
137
-			$schedule          = new ActionScheduler_SimpleSchedule( $time );
138
-			$action            = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
139
-			$created_actions[] = $store->save_action( $action );
140
-		}
141
-
142
-		$claim = $store->stake_claim();
143
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
144
-
145
-		$this->assertCount( 3, $claim->get_actions() );
146
-		$this->assertEqualSets( array_slice( $created_actions, 3, 3 ), $claim->get_actions() );
147
-	}
148
-
149
-	public function test_claim_actions_order() {
150
-		$store           = new ActionScheduler_wpPostStore();
151
-		$schedule        = new ActionScheduler_SimpleSchedule( as_get_datetime_object( '-1 hour' ) );
152
-		$created_actions = array(
153
-			$store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'my_group' ) ),
154
-			$store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'my_group' ) ),
155
-		);
156
-
157
-		$claim = $store->stake_claim();
158
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
159
-
160
-		// Verify uniqueness of action IDs.
161
-		$this->assertCount( 2, array_unique( $created_actions ) );
162
-
163
-		// Verify the count and order of the actions.
164
-		$claimed_actions = $claim->get_actions();
165
-		$this->assertCount( 2, $claimed_actions );
166
-		$this->assertEquals( $created_actions, $claimed_actions );
167
-
168
-		// Verify the reversed order doesn't pass.
169
-		$reversed_actions = array_reverse( $created_actions );
170
-		$this->assertNotEquals( $reversed_actions, $claimed_actions );
171
-	}
172
-
173
-	public function test_duplicate_claim() {
174
-		$created_actions = array();
175
-		$store           = new ActionScheduler_wpPostStore();
176
-		for ( $i = 0; $i > -3; $i-- ) {
177
-			$time              = as_get_datetime_object( $i . ' hours' );
178
-			$schedule          = new ActionScheduler_SimpleSchedule( $time );
179
-			$action            = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
180
-			$created_actions[] = $store->save_action( $action );
181
-		}
182
-
183
-		$claim1 = $store->stake_claim();
184
-		$claim2 = $store->stake_claim();
185
-		$this->assertCount( 3, $claim1->get_actions() );
186
-		$this->assertCount( 0, $claim2->get_actions() );
187
-	}
188
-
189
-	public function test_release_claim() {
190
-		$created_actions = array();
191
-		$store           = new ActionScheduler_wpPostStore();
192
-		for ( $i = 0; $i > -3; $i-- ) {
193
-			$time              = as_get_datetime_object( $i . ' hours' );
194
-			$schedule          = new ActionScheduler_SimpleSchedule( $time );
195
-			$action            = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
196
-			$created_actions[] = $store->save_action( $action );
197
-		}
198
-
199
-		$claim1 = $store->stake_claim();
200
-
201
-		$store->release_claim( $claim1 );
202
-
203
-		$claim2 = $store->stake_claim();
204
-		$this->assertCount( 3, $claim2->get_actions() );
205
-	}
206
-
207
-	public function test_search() {
208
-		$created_actions = array();
209
-		$store           = new ActionScheduler_wpPostStore();
210
-		for ( $i = -3; $i <= 3; $i++ ) {
211
-			$time              = as_get_datetime_object( $i . ' hours' );
212
-			$schedule          = new ActionScheduler_SimpleSchedule( $time );
213
-			$action            = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
214
-			$created_actions[] = $store->save_action( $action );
215
-		}
216
-
217
-		$next_no_args = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK );
218
-		$this->assertEquals( $created_actions[0], $next_no_args );
219
-
220
-		$next_with_args = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'args' => array( 1 ) ) );
221
-		$this->assertEquals( $created_actions[4], $next_with_args );
222
-
223
-		$non_existent = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'args' => array( 17 ) ) );
224
-		$this->assertNull( $non_existent );
225
-	}
226
-
227
-	public function test_search_by_group() {
228
-		$store    = new ActionScheduler_wpPostStore();
229
-		$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( 'tomorrow' ) );
230
-		$abc      = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'abc' ) );
231
-		$def      = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'def' ) );
232
-		$ghi      = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'ghi' ) );
233
-
234
-		$this->assertEquals( $abc, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'abc' ) ) );
235
-		$this->assertEquals( $def, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'def' ) ) );
236
-		$this->assertEquals( $ghi, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'ghi' ) ) );
237
-	}
238
-
239
-	public function test_post_author() {
240
-		$current_user = get_current_user_id();
241
-
242
-		$time      = as_get_datetime_object();
243
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
244
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
245
-		$store     = new ActionScheduler_wpPostStore();
246
-		$action_id = $store->save_action( $action );
247
-
248
-		$post = get_post( $action_id );
249
-		$this->assertSame( 0, $post->post_author );
250
-
251
-		$new_user = $this->factory->user->create_object(
252
-			array(
253
-				'user_login' => __FUNCTION__,
254
-				'user_pass'  => md5( rand() ),
255
-			)
256
-		);
257
-		wp_set_current_user( $new_user );
258
-
259
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
260
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
261
-		$action_id = $store->save_action( $action );
262
-		$post      = get_post( $action_id );
263
-		$this->assertSame( 0, $post->post_author );
264
-
265
-		wp_set_current_user( $current_user );
266
-	}
267
-
268
-	/**
269
-	 * @issue 13
270
-	 */
271
-	public function test_post_status_for_recurring_action() {
272
-		$time      = as_get_datetime_object( '10 minutes' );
273
-		$schedule  = new ActionScheduler_IntervalSchedule( $time, HOUR_IN_SECONDS );
274
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
275
-		$store     = new ActionScheduler_wpPostStore();
276
-		$action_id = $store->save_action( $action );
277
-
278
-		$action = $store->fetch_action( $action_id );
279
-		$action->execute();
280
-		$store->mark_complete( $action_id );
281
-
282
-		$next          = $action->get_schedule()->get_next( as_get_datetime_object() );
283
-		$new_action_id = $store->save_action( $action, $next );
284
-
285
-		$this->assertEquals( 'publish', get_post_status( $action_id ) );
286
-		$this->assertEquals( 'pending', get_post_status( $new_action_id ) );
287
-	}
288
-
289
-	public function test_get_run_date() {
290
-		$time      = as_get_datetime_object( '-10 minutes' );
291
-		$schedule  = new ActionScheduler_IntervalSchedule( $time, HOUR_IN_SECONDS );
292
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
293
-		$store     = new ActionScheduler_wpPostStore();
294
-		$action_id = $store->save_action( $action );
295
-
296
-		$this->assertEquals( $store->get_date( $action_id )->getTimestamp(), $time->getTimestamp() );
297
-
298
-		$action = $store->fetch_action( $action_id );
299
-		$action->execute();
300
-		$now = as_get_datetime_object();
301
-		$store->mark_complete( $action_id );
302
-
303
-		$this->assertEquals( $store->get_date( $action_id )->getTimestamp(), $now->getTimestamp(), '', 1 ); // allow timestamp to be 1 second off for older versions of PHP
304
-
305
-		$next          = $action->get_schedule()->get_next( $now );
306
-		$new_action_id = $store->save_action( $action, $next );
307
-
308
-		$this->assertEquals( (int) ( $now->getTimestamp() ) + HOUR_IN_SECONDS, $store->get_date( $new_action_id )->getTimestamp() );
309
-	}
310
-
311
-	public function test_claim_actions_by_hooks() {
312
-		$hook1    = __FUNCTION__ . '_hook_1';
313
-		$hook2    = __FUNCTION__ . '_hook_2';
314
-		$store    = new ActionScheduler_wpPostStore();
315
-		$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( '-1 hour' ) );
316
-
317
-		$action1 = $store->save_action( new ActionScheduler_Action( $hook1, array(), $schedule ) );
318
-		$action2 = $store->save_action( new ActionScheduler_Action( $hook2, array(), $schedule ) );
319
-
320
-		// Claiming no hooks should include all actions.
321
-		$claim = $store->stake_claim( 10 );
322
-		$this->assertCount( 2, $claim->get_actions() );
323
-		$this->assertContains( $action1, $claim->get_actions() );
324
-		$this->assertContains( $action2, $claim->get_actions() );
325
-		$store->release_claim( $claim );
326
-
327
-		// Claiming a hook should claim only actions with that hook
328
-		$claim = $store->stake_claim( 10, null, array( $hook1 ) );
329
-		$this->assertCount( 1, $claim->get_actions() );
330
-		$this->assertContains( $action1, $claim->get_actions() );
331
-		$store->release_claim( $claim );
332
-
333
-		// Claiming two hooks should claim actions with either of those hooks
334
-		$claim = $store->stake_claim( 10, null, array( $hook1, $hook2 ) );
335
-		$this->assertCount( 2, $claim->get_actions() );
336
-		$this->assertContains( $action1, $claim->get_actions() );
337
-		$this->assertContains( $action2, $claim->get_actions() );
338
-		$store->release_claim( $claim );
339
-
340
-		// Claiming two hooks should claim actions with either of those hooks
341
-		$claim = $store->stake_claim( 10, null, array( __METHOD__ . '_hook_3' ) );
342
-		$this->assertCount( 0, $claim->get_actions() );
343
-		$this->assertNotContains( $action1, $claim->get_actions() );
344
-		$this->assertNotContains( $action2, $claim->get_actions() );
345
-		$store->release_claim( $claim );
346
-	}
347
-
348
-	/**
349
-	 * @issue 121
350
-	 */
351
-	public function test_claim_actions_by_group() {
352
-		$group1   = md5( rand() );
353
-		$store    = new ActionScheduler_wpPostStore();
354
-		$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( '-1 hour' ) );
355
-
356
-		$action1 = $store->save_action( new ActionScheduler_Action( __METHOD__, array(), $schedule, $group1 ) );
357
-		$action2 = $store->save_action( new ActionScheduler_Action( __METHOD__, array(), $schedule ) );
358
-
359
-		// Claiming no group should include all actions.
360
-		$claim = $store->stake_claim( 10 );
361
-		$this->assertCount( 2, $claim->get_actions() );
362
-		$this->assertContains( $action1, $claim->get_actions() );
363
-		$this->assertContains( $action2, $claim->get_actions() );
364
-		$store->release_claim( $claim );
365
-
366
-		// Claiming a group should claim only actions in that group.
367
-		$claim = $store->stake_claim( 10, null, array(), $group1 );
368
-		$this->assertCount( 1, $claim->get_actions() );
369
-		$this->assertContains( $action1, $claim->get_actions() );
370
-		$store->release_claim( $claim );
371
-	}
372
-
373
-	public function test_claim_actions_by_hook_and_group() {
374
-		$hook1    = __FUNCTION__ . '_hook_1';
375
-		$hook2    = __FUNCTION__ . '_hook_2';
376
-		$hook3    = __FUNCTION__ . '_hook_3';
377
-		$group1   = 'group_' . md5( rand() );
378
-		$group2   = 'group_' . md5( rand() );
379
-		$store    = new ActionScheduler_wpPostStore();
380
-		$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( '-1 hour' ) );
381
-
382
-		$action1 = $store->save_action( new ActionScheduler_Action( $hook1, array(), $schedule, $group1 ) );
383
-		$action2 = $store->save_action( new ActionScheduler_Action( $hook2, array(), $schedule ) );
384
-		$action3 = $store->save_action( new ActionScheduler_Action( $hook3, array(), $schedule, $group2 ) );
385
-
386
-		// Claiming no hooks or group should include all actions.
387
-		$claim = $store->stake_claim( 10 );
388
-		$this->assertCount( 3, $claim->get_actions() );
389
-		$this->assertContains( $action1, $claim->get_actions() );
390
-		$this->assertContains( $action2, $claim->get_actions() );
391
-		$store->release_claim( $claim );
392
-
393
-		// Claiming a group and hook should claim only actions in that group.
394
-		$claim = $store->stake_claim( 10, null, array( $hook1 ), $group1 );
395
-		$this->assertCount( 1, $claim->get_actions() );
396
-		$this->assertContains( $action1, $claim->get_actions() );
397
-		$store->release_claim( $claim );
398
-
399
-		// Claiming a group and hook should claim only actions with that hook in that group.
400
-		$claim = $store->stake_claim( 10, null, array( $hook2 ), $group1 );
401
-		$this->assertCount( 0, $claim->get_actions() );
402
-		$this->assertNotContains( $action1, $claim->get_actions() );
403
-		$this->assertNotContains( $action2, $claim->get_actions() );
404
-		$store->release_claim( $claim );
405
-
406
-		// Claiming a group and hook should claim only actions with that hook in that group.
407
-		$claim = $store->stake_claim( 10, null, array( $hook1, $hook2 ), $group2 );
408
-		$this->assertCount( 0, $claim->get_actions() );
409
-		$this->assertNotContains( $action1, $claim->get_actions() );
410
-		$this->assertNotContains( $action2, $claim->get_actions() );
411
-		$store->release_claim( $claim );
412
-	}
413
-
414
-	/**
415
-	 * The query used to claim actions explicitly ignores future pending actions, but it
416
-	 * is still possible under unusual conditions (such as if MySQL runs out of temporary
417
-	 * storage space) for such actions to be returned.
418
-	 *
419
-	 * When this happens, we still expect the store to filter them out, otherwise there is
420
-	 * a risk that actions will be unexpectedly processed ahead of time.
421
-	 *
422
-	 * @see https://github.com/woocommerce/action-scheduler/issues/634
423
-	 */
424
-	public function test_claim_filters_out_unexpected_future_actions() {
425
-		$group = __METHOD__;
426
-		$store = new ActionScheduler_wpPostStore();
427
-
428
-		// Create 4 actions: 2 that are already due (-3hrs and -1hrs) and 2 that are not yet due (+1hr and +3hrs).
429
-		for ( $i = -3; $i <= 3; $i += 2 ) {
430
-			$schedule     = new ActionScheduler_SimpleSchedule( as_get_datetime_object( $i . ' hours' ) );
431
-			$action_ids[] = $store->save_action( new ActionScheduler_Action( 'test_' . $i, array(), $schedule, $group ) );
432
-		}
433
-
434
-		// This callback is used to simulate the unusual conditions whereby MySQL might unexpectedly return future
435
-		// actions, contrary to the conditions used by the store object when staking its claim.
436
-		$simulate_unexpected_db_behavior = function ( $sql ) use ( $action_ids ) {
437
-			global $wpdb;
438
-
439
-			$post_type = ActionScheduler_wpPostStore::POST_TYPE;
440
-			$pending   = ActionScheduler_wpPostStore::STATUS_PENDING;
441
-
442
-			// Look out for the claim update query, ignore all others.
443
-			if (
444
-				0 !== strpos( $sql, "UPDATE $wpdb->posts" )
445
-				|| 0 !== strpos( $sql, "WHERE post_type = '$post_type' AND post_status = '$pending' AND post_password = ''" )
446
-				|| ! preg_match( "/AND post_date_gmt <= '([0-9:\-\s]{19})'/", $sql, $matches )
447
-				|| count( $matches ) !== 2
448
-			) {
449
-				return $sql;
450
-			}
451
-
452
-			// Now modify the query, forcing it to also return the future actions we created.
453
-			return str_replace( $matches[1], as_get_datetime_object( '+4 hours' )->format( 'Y-m-d H:i:s' ), $sql );
454
-		};
455
-
456
-		add_filter( 'query', $simulate_unexpected_db_behavior );
457
-		$claim           = $store->stake_claim( 10, null, array(), $group );
458
-		$claimed_actions = $claim->get_actions();
459
-		$this->assertCount( 2, $claimed_actions );
460
-
461
-		// Cleanup.
462
-		remove_filter( 'query', $simulate_unexpected_db_behavior );
463
-		$store->release_claim( $claim );
464
-	}
12
+    /**
13
+     * Get data store for tests.
14
+     *
15
+     * @return ActionScheduler_wpPostStore
16
+     */
17
+    protected function get_store() {
18
+        return new ActionScheduler_wpPostStore();
19
+    }
20
+
21
+    public function test_create_action() {
22
+        $time      = as_get_datetime_object();
23
+        $schedule  = new ActionScheduler_SimpleSchedule( $time );
24
+        $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
25
+        $store     = new ActionScheduler_wpPostStore();
26
+        $action_id = $store->save_action( $action );
27
+
28
+        $this->assertNotEmpty( $action_id );
29
+    }
30
+
31
+    public function test_create_action_with_scheduled_date() {
32
+        $time   = as_get_datetime_object( strtotime( '-1 week' ) );
33
+        $action = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), new ActionScheduler_SimpleSchedule( $time ) );
34
+        $store  = new ActionScheduler_wpPostStore();
35
+
36
+        $action_id   = $store->save_action( $action, $time );
37
+        $action_date = $store->get_date( $action_id );
38
+
39
+        $this->assertEquals( $time->getTimestamp(), $action_date->getTimestamp() );
40
+    }
41
+
42
+    public function test_retrieve_action() {
43
+        $time      = as_get_datetime_object();
44
+        $schedule  = new ActionScheduler_SimpleSchedule( $time );
45
+        $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
46
+        $store     = new ActionScheduler_wpPostStore();
47
+        $action_id = $store->save_action( $action );
48
+
49
+        $retrieved = $store->fetch_action( $action_id );
50
+        $this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
51
+        $this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
52
+        $this->assertEquals( $action->get_schedule()->get_date()->getTimestamp(), $retrieved->get_schedule()->get_date()->getTimestamp() );
53
+        $this->assertEquals( $action->get_group(), $retrieved->get_group() );
54
+    }
55
+
56
+    /**
57
+     * @dataProvider provide_bad_args
58
+     *
59
+     * @param string $content
60
+     */
61
+    public function test_action_bad_args( $content ) {
62
+        $store   = new ActionScheduler_wpPostStore();
63
+        $post_id = wp_insert_post(
64
+            array(
65
+                'post_type'    => ActionScheduler_wpPostStore::POST_TYPE,
66
+                'post_status'  => ActionScheduler_Store::STATUS_PENDING,
67
+                'post_content' => $content,
68
+            )
69
+        );
70
+
71
+        $fetched = $store->fetch_action( $post_id );
72
+        $this->assertInstanceOf( 'ActionScheduler_NullSchedule', $fetched->get_schedule() );
73
+    }
74
+
75
+    public function provide_bad_args() {
76
+        return array(
77
+            array( '{"bad_json":true}}' ),
78
+        );
79
+    }
80
+
81
+    public function test_cancel_action() {
82
+        $time      = as_get_datetime_object();
83
+        $schedule  = new ActionScheduler_SimpleSchedule( $time );
84
+        $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
85
+        $store     = new ActionScheduler_wpPostStore();
86
+        $action_id = $store->save_action( $action );
87
+        $store->cancel_action( $action_id );
88
+
89
+        $fetched = $store->fetch_action( $action_id );
90
+        $this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
91
+    }
92
+
93
+    public function test_cancel_actions_by_hook() {
94
+        $store   = new ActionScheduler_wpPostStore();
95
+        $actions = array();
96
+        $hook    = 'by_hook_test';
97
+        for ( $day = 1; $day <= 3; $day++ ) {
98
+            $delta     = sprintf( '+%d day', $day );
99
+            $time      = as_get_datetime_object( $delta );
100
+            $schedule  = new ActionScheduler_SimpleSchedule( $time );
101
+            $action    = new ActionScheduler_Action( $hook, array(), $schedule, 'my_group' );
102
+            $actions[] = $store->save_action( $action );
103
+        }
104
+        $store->cancel_actions_by_hook( $hook );
105
+
106
+        foreach ( $actions as $action_id ) {
107
+            $fetched = $store->fetch_action( $action_id );
108
+            $this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
109
+        }
110
+    }
111
+
112
+    public function test_cancel_actions_by_group() {
113
+        $store   = new ActionScheduler_wpPostStore();
114
+        $actions = array();
115
+        $group   = 'by_group_test';
116
+
117
+        for ( $day = 1; $day <= 3; $day++ ) {
118
+            $delta     = sprintf( '+%d day', $day );
119
+            $time      = as_get_datetime_object( $delta );
120
+            $schedule  = new ActionScheduler_SimpleSchedule( $time );
121
+            $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, $group );
122
+            $actions[] = $store->save_action( $action );
123
+        }
124
+        $store->cancel_actions_by_group( $group );
125
+
126
+        foreach ( $actions as $action_id ) {
127
+            $fetched = $store->fetch_action( $action_id );
128
+            $this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
129
+        }
130
+    }
131
+
132
+    public function test_claim_actions() {
133
+        $created_actions = array();
134
+        $store           = new ActionScheduler_wpPostStore();
135
+        for ( $i = 3; $i > -3; $i-- ) {
136
+            $time              = as_get_datetime_object( $i . ' hours' );
137
+            $schedule          = new ActionScheduler_SimpleSchedule( $time );
138
+            $action            = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
139
+            $created_actions[] = $store->save_action( $action );
140
+        }
141
+
142
+        $claim = $store->stake_claim();
143
+        $this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
144
+
145
+        $this->assertCount( 3, $claim->get_actions() );
146
+        $this->assertEqualSets( array_slice( $created_actions, 3, 3 ), $claim->get_actions() );
147
+    }
148
+
149
+    public function test_claim_actions_order() {
150
+        $store           = new ActionScheduler_wpPostStore();
151
+        $schedule        = new ActionScheduler_SimpleSchedule( as_get_datetime_object( '-1 hour' ) );
152
+        $created_actions = array(
153
+            $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'my_group' ) ),
154
+            $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'my_group' ) ),
155
+        );
156
+
157
+        $claim = $store->stake_claim();
158
+        $this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
159
+
160
+        // Verify uniqueness of action IDs.
161
+        $this->assertCount( 2, array_unique( $created_actions ) );
162
+
163
+        // Verify the count and order of the actions.
164
+        $claimed_actions = $claim->get_actions();
165
+        $this->assertCount( 2, $claimed_actions );
166
+        $this->assertEquals( $created_actions, $claimed_actions );
167
+
168
+        // Verify the reversed order doesn't pass.
169
+        $reversed_actions = array_reverse( $created_actions );
170
+        $this->assertNotEquals( $reversed_actions, $claimed_actions );
171
+    }
172
+
173
+    public function test_duplicate_claim() {
174
+        $created_actions = array();
175
+        $store           = new ActionScheduler_wpPostStore();
176
+        for ( $i = 0; $i > -3; $i-- ) {
177
+            $time              = as_get_datetime_object( $i . ' hours' );
178
+            $schedule          = new ActionScheduler_SimpleSchedule( $time );
179
+            $action            = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
180
+            $created_actions[] = $store->save_action( $action );
181
+        }
182
+
183
+        $claim1 = $store->stake_claim();
184
+        $claim2 = $store->stake_claim();
185
+        $this->assertCount( 3, $claim1->get_actions() );
186
+        $this->assertCount( 0, $claim2->get_actions() );
187
+    }
188
+
189
+    public function test_release_claim() {
190
+        $created_actions = array();
191
+        $store           = new ActionScheduler_wpPostStore();
192
+        for ( $i = 0; $i > -3; $i-- ) {
193
+            $time              = as_get_datetime_object( $i . ' hours' );
194
+            $schedule          = new ActionScheduler_SimpleSchedule( $time );
195
+            $action            = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
196
+            $created_actions[] = $store->save_action( $action );
197
+        }
198
+
199
+        $claim1 = $store->stake_claim();
200
+
201
+        $store->release_claim( $claim1 );
202
+
203
+        $claim2 = $store->stake_claim();
204
+        $this->assertCount( 3, $claim2->get_actions() );
205
+    }
206
+
207
+    public function test_search() {
208
+        $created_actions = array();
209
+        $store           = new ActionScheduler_wpPostStore();
210
+        for ( $i = -3; $i <= 3; $i++ ) {
211
+            $time              = as_get_datetime_object( $i . ' hours' );
212
+            $schedule          = new ActionScheduler_SimpleSchedule( $time );
213
+            $action            = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
214
+            $created_actions[] = $store->save_action( $action );
215
+        }
216
+
217
+        $next_no_args = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK );
218
+        $this->assertEquals( $created_actions[0], $next_no_args );
219
+
220
+        $next_with_args = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'args' => array( 1 ) ) );
221
+        $this->assertEquals( $created_actions[4], $next_with_args );
222
+
223
+        $non_existent = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'args' => array( 17 ) ) );
224
+        $this->assertNull( $non_existent );
225
+    }
226
+
227
+    public function test_search_by_group() {
228
+        $store    = new ActionScheduler_wpPostStore();
229
+        $schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( 'tomorrow' ) );
230
+        $abc      = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'abc' ) );
231
+        $def      = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'def' ) );
232
+        $ghi      = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'ghi' ) );
233
+
234
+        $this->assertEquals( $abc, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'abc' ) ) );
235
+        $this->assertEquals( $def, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'def' ) ) );
236
+        $this->assertEquals( $ghi, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'ghi' ) ) );
237
+    }
238
+
239
+    public function test_post_author() {
240
+        $current_user = get_current_user_id();
241
+
242
+        $time      = as_get_datetime_object();
243
+        $schedule  = new ActionScheduler_SimpleSchedule( $time );
244
+        $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
245
+        $store     = new ActionScheduler_wpPostStore();
246
+        $action_id = $store->save_action( $action );
247
+
248
+        $post = get_post( $action_id );
249
+        $this->assertSame( 0, $post->post_author );
250
+
251
+        $new_user = $this->factory->user->create_object(
252
+            array(
253
+                'user_login' => __FUNCTION__,
254
+                'user_pass'  => md5( rand() ),
255
+            )
256
+        );
257
+        wp_set_current_user( $new_user );
258
+
259
+        $schedule  = new ActionScheduler_SimpleSchedule( $time );
260
+        $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
261
+        $action_id = $store->save_action( $action );
262
+        $post      = get_post( $action_id );
263
+        $this->assertSame( 0, $post->post_author );
264
+
265
+        wp_set_current_user( $current_user );
266
+    }
267
+
268
+    /**
269
+     * @issue 13
270
+     */
271
+    public function test_post_status_for_recurring_action() {
272
+        $time      = as_get_datetime_object( '10 minutes' );
273
+        $schedule  = new ActionScheduler_IntervalSchedule( $time, HOUR_IN_SECONDS );
274
+        $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
275
+        $store     = new ActionScheduler_wpPostStore();
276
+        $action_id = $store->save_action( $action );
277
+
278
+        $action = $store->fetch_action( $action_id );
279
+        $action->execute();
280
+        $store->mark_complete( $action_id );
281
+
282
+        $next          = $action->get_schedule()->get_next( as_get_datetime_object() );
283
+        $new_action_id = $store->save_action( $action, $next );
284
+
285
+        $this->assertEquals( 'publish', get_post_status( $action_id ) );
286
+        $this->assertEquals( 'pending', get_post_status( $new_action_id ) );
287
+    }
288
+
289
+    public function test_get_run_date() {
290
+        $time      = as_get_datetime_object( '-10 minutes' );
291
+        $schedule  = new ActionScheduler_IntervalSchedule( $time, HOUR_IN_SECONDS );
292
+        $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
293
+        $store     = new ActionScheduler_wpPostStore();
294
+        $action_id = $store->save_action( $action );
295
+
296
+        $this->assertEquals( $store->get_date( $action_id )->getTimestamp(), $time->getTimestamp() );
297
+
298
+        $action = $store->fetch_action( $action_id );
299
+        $action->execute();
300
+        $now = as_get_datetime_object();
301
+        $store->mark_complete( $action_id );
302
+
303
+        $this->assertEquals( $store->get_date( $action_id )->getTimestamp(), $now->getTimestamp(), '', 1 ); // allow timestamp to be 1 second off for older versions of PHP
304
+
305
+        $next          = $action->get_schedule()->get_next( $now );
306
+        $new_action_id = $store->save_action( $action, $next );
307
+
308
+        $this->assertEquals( (int) ( $now->getTimestamp() ) + HOUR_IN_SECONDS, $store->get_date( $new_action_id )->getTimestamp() );
309
+    }
310
+
311
+    public function test_claim_actions_by_hooks() {
312
+        $hook1    = __FUNCTION__ . '_hook_1';
313
+        $hook2    = __FUNCTION__ . '_hook_2';
314
+        $store    = new ActionScheduler_wpPostStore();
315
+        $schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( '-1 hour' ) );
316
+
317
+        $action1 = $store->save_action( new ActionScheduler_Action( $hook1, array(), $schedule ) );
318
+        $action2 = $store->save_action( new ActionScheduler_Action( $hook2, array(), $schedule ) );
319
+
320
+        // Claiming no hooks should include all actions.
321
+        $claim = $store->stake_claim( 10 );
322
+        $this->assertCount( 2, $claim->get_actions() );
323
+        $this->assertContains( $action1, $claim->get_actions() );
324
+        $this->assertContains( $action2, $claim->get_actions() );
325
+        $store->release_claim( $claim );
326
+
327
+        // Claiming a hook should claim only actions with that hook
328
+        $claim = $store->stake_claim( 10, null, array( $hook1 ) );
329
+        $this->assertCount( 1, $claim->get_actions() );
330
+        $this->assertContains( $action1, $claim->get_actions() );
331
+        $store->release_claim( $claim );
332
+
333
+        // Claiming two hooks should claim actions with either of those hooks
334
+        $claim = $store->stake_claim( 10, null, array( $hook1, $hook2 ) );
335
+        $this->assertCount( 2, $claim->get_actions() );
336
+        $this->assertContains( $action1, $claim->get_actions() );
337
+        $this->assertContains( $action2, $claim->get_actions() );
338
+        $store->release_claim( $claim );
339
+
340
+        // Claiming two hooks should claim actions with either of those hooks
341
+        $claim = $store->stake_claim( 10, null, array( __METHOD__ . '_hook_3' ) );
342
+        $this->assertCount( 0, $claim->get_actions() );
343
+        $this->assertNotContains( $action1, $claim->get_actions() );
344
+        $this->assertNotContains( $action2, $claim->get_actions() );
345
+        $store->release_claim( $claim );
346
+    }
347
+
348
+    /**
349
+     * @issue 121
350
+     */
351
+    public function test_claim_actions_by_group() {
352
+        $group1   = md5( rand() );
353
+        $store    = new ActionScheduler_wpPostStore();
354
+        $schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( '-1 hour' ) );
355
+
356
+        $action1 = $store->save_action( new ActionScheduler_Action( __METHOD__, array(), $schedule, $group1 ) );
357
+        $action2 = $store->save_action( new ActionScheduler_Action( __METHOD__, array(), $schedule ) );
358
+
359
+        // Claiming no group should include all actions.
360
+        $claim = $store->stake_claim( 10 );
361
+        $this->assertCount( 2, $claim->get_actions() );
362
+        $this->assertContains( $action1, $claim->get_actions() );
363
+        $this->assertContains( $action2, $claim->get_actions() );
364
+        $store->release_claim( $claim );
365
+
366
+        // Claiming a group should claim only actions in that group.
367
+        $claim = $store->stake_claim( 10, null, array(), $group1 );
368
+        $this->assertCount( 1, $claim->get_actions() );
369
+        $this->assertContains( $action1, $claim->get_actions() );
370
+        $store->release_claim( $claim );
371
+    }
372
+
373
+    public function test_claim_actions_by_hook_and_group() {
374
+        $hook1    = __FUNCTION__ . '_hook_1';
375
+        $hook2    = __FUNCTION__ . '_hook_2';
376
+        $hook3    = __FUNCTION__ . '_hook_3';
377
+        $group1   = 'group_' . md5( rand() );
378
+        $group2   = 'group_' . md5( rand() );
379
+        $store    = new ActionScheduler_wpPostStore();
380
+        $schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( '-1 hour' ) );
381
+
382
+        $action1 = $store->save_action( new ActionScheduler_Action( $hook1, array(), $schedule, $group1 ) );
383
+        $action2 = $store->save_action( new ActionScheduler_Action( $hook2, array(), $schedule ) );
384
+        $action3 = $store->save_action( new ActionScheduler_Action( $hook3, array(), $schedule, $group2 ) );
385
+
386
+        // Claiming no hooks or group should include all actions.
387
+        $claim = $store->stake_claim( 10 );
388
+        $this->assertCount( 3, $claim->get_actions() );
389
+        $this->assertContains( $action1, $claim->get_actions() );
390
+        $this->assertContains( $action2, $claim->get_actions() );
391
+        $store->release_claim( $claim );
392
+
393
+        // Claiming a group and hook should claim only actions in that group.
394
+        $claim = $store->stake_claim( 10, null, array( $hook1 ), $group1 );
395
+        $this->assertCount( 1, $claim->get_actions() );
396
+        $this->assertContains( $action1, $claim->get_actions() );
397
+        $store->release_claim( $claim );
398
+
399
+        // Claiming a group and hook should claim only actions with that hook in that group.
400
+        $claim = $store->stake_claim( 10, null, array( $hook2 ), $group1 );
401
+        $this->assertCount( 0, $claim->get_actions() );
402
+        $this->assertNotContains( $action1, $claim->get_actions() );
403
+        $this->assertNotContains( $action2, $claim->get_actions() );
404
+        $store->release_claim( $claim );
405
+
406
+        // Claiming a group and hook should claim only actions with that hook in that group.
407
+        $claim = $store->stake_claim( 10, null, array( $hook1, $hook2 ), $group2 );
408
+        $this->assertCount( 0, $claim->get_actions() );
409
+        $this->assertNotContains( $action1, $claim->get_actions() );
410
+        $this->assertNotContains( $action2, $claim->get_actions() );
411
+        $store->release_claim( $claim );
412
+    }
413
+
414
+    /**
415
+     * The query used to claim actions explicitly ignores future pending actions, but it
416
+     * is still possible under unusual conditions (such as if MySQL runs out of temporary
417
+     * storage space) for such actions to be returned.
418
+     *
419
+     * When this happens, we still expect the store to filter them out, otherwise there is
420
+     * a risk that actions will be unexpectedly processed ahead of time.
421
+     *
422
+     * @see https://github.com/woocommerce/action-scheduler/issues/634
423
+     */
424
+    public function test_claim_filters_out_unexpected_future_actions() {
425
+        $group = __METHOD__;
426
+        $store = new ActionScheduler_wpPostStore();
427
+
428
+        // Create 4 actions: 2 that are already due (-3hrs and -1hrs) and 2 that are not yet due (+1hr and +3hrs).
429
+        for ( $i = -3; $i <= 3; $i += 2 ) {
430
+            $schedule     = new ActionScheduler_SimpleSchedule( as_get_datetime_object( $i . ' hours' ) );
431
+            $action_ids[] = $store->save_action( new ActionScheduler_Action( 'test_' . $i, array(), $schedule, $group ) );
432
+        }
433
+
434
+        // This callback is used to simulate the unusual conditions whereby MySQL might unexpectedly return future
435
+        // actions, contrary to the conditions used by the store object when staking its claim.
436
+        $simulate_unexpected_db_behavior = function ( $sql ) use ( $action_ids ) {
437
+            global $wpdb;
438
+
439
+            $post_type = ActionScheduler_wpPostStore::POST_TYPE;
440
+            $pending   = ActionScheduler_wpPostStore::STATUS_PENDING;
441
+
442
+            // Look out for the claim update query, ignore all others.
443
+            if (
444
+                0 !== strpos( $sql, "UPDATE $wpdb->posts" )
445
+                || 0 !== strpos( $sql, "WHERE post_type = '$post_type' AND post_status = '$pending' AND post_password = ''" )
446
+                || ! preg_match( "/AND post_date_gmt <= '([0-9:\-\s]{19})'/", $sql, $matches )
447
+                || count( $matches ) !== 2
448
+            ) {
449
+                return $sql;
450
+            }
451
+
452
+            // Now modify the query, forcing it to also return the future actions we created.
453
+            return str_replace( $matches[1], as_get_datetime_object( '+4 hours' )->format( 'Y-m-d H:i:s' ), $sql );
454
+        };
455
+
456
+        add_filter( 'query', $simulate_unexpected_db_behavior );
457
+        $claim           = $store->stake_claim( 10, null, array(), $group );
458
+        $claimed_actions = $claim->get_actions();
459
+        $this->assertCount( 2, $claimed_actions );
460
+
461
+        // Cleanup.
462
+        remove_filter( 'query', $simulate_unexpected_db_behavior );
463
+        $store->release_claim( $claim );
464
+    }
465 465
 }
Please login to merge, or discard this patch.
Spacing   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -20,37 +20,37 @@  discard block
 block discarded – undo
20 20
 
21 21
 	public function test_create_action() {
22 22
 		$time      = as_get_datetime_object();
23
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
24
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
23
+		$schedule  = new ActionScheduler_SimpleSchedule($time);
24
+		$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
25 25
 		$store     = new ActionScheduler_wpPostStore();
26
-		$action_id = $store->save_action( $action );
26
+		$action_id = $store->save_action($action);
27 27
 
28
-		$this->assertNotEmpty( $action_id );
28
+		$this->assertNotEmpty($action_id);
29 29
 	}
30 30
 
31 31
 	public function test_create_action_with_scheduled_date() {
32
-		$time   = as_get_datetime_object( strtotime( '-1 week' ) );
33
-		$action = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), new ActionScheduler_SimpleSchedule( $time ) );
32
+		$time   = as_get_datetime_object(strtotime('-1 week'));
33
+		$action = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), new ActionScheduler_SimpleSchedule($time));
34 34
 		$store  = new ActionScheduler_wpPostStore();
35 35
 
36
-		$action_id   = $store->save_action( $action, $time );
37
-		$action_date = $store->get_date( $action_id );
36
+		$action_id   = $store->save_action($action, $time);
37
+		$action_date = $store->get_date($action_id);
38 38
 
39
-		$this->assertEquals( $time->getTimestamp(), $action_date->getTimestamp() );
39
+		$this->assertEquals($time->getTimestamp(), $action_date->getTimestamp());
40 40
 	}
41 41
 
42 42
 	public function test_retrieve_action() {
43 43
 		$time      = as_get_datetime_object();
44
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
45
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
44
+		$schedule  = new ActionScheduler_SimpleSchedule($time);
45
+		$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group');
46 46
 		$store     = new ActionScheduler_wpPostStore();
47
-		$action_id = $store->save_action( $action );
47
+		$action_id = $store->save_action($action);
48 48
 
49
-		$retrieved = $store->fetch_action( $action_id );
50
-		$this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
51
-		$this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
52
-		$this->assertEquals( $action->get_schedule()->get_date()->getTimestamp(), $retrieved->get_schedule()->get_date()->getTimestamp() );
53
-		$this->assertEquals( $action->get_group(), $retrieved->get_group() );
49
+		$retrieved = $store->fetch_action($action_id);
50
+		$this->assertEquals($action->get_hook(), $retrieved->get_hook());
51
+		$this->assertEqualSets($action->get_args(), $retrieved->get_args());
52
+		$this->assertEquals($action->get_schedule()->get_date()->getTimestamp(), $retrieved->get_schedule()->get_date()->getTimestamp());
53
+		$this->assertEquals($action->get_group(), $retrieved->get_group());
54 54
 	}
55 55
 
56 56
 	/**
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	 *
59 59
 	 * @param string $content
60 60
 	 */
61
-	public function test_action_bad_args( $content ) {
61
+	public function test_action_bad_args($content) {
62 62
 		$store   = new ActionScheduler_wpPostStore();
63 63
 		$post_id = wp_insert_post(
64 64
 			array(
@@ -68,44 +68,44 @@  discard block
 block discarded – undo
68 68
 			)
69 69
 		);
70 70
 
71
-		$fetched = $store->fetch_action( $post_id );
72
-		$this->assertInstanceOf( 'ActionScheduler_NullSchedule', $fetched->get_schedule() );
71
+		$fetched = $store->fetch_action($post_id);
72
+		$this->assertInstanceOf('ActionScheduler_NullSchedule', $fetched->get_schedule());
73 73
 	}
74 74
 
75 75
 	public function provide_bad_args() {
76 76
 		return array(
77
-			array( '{"bad_json":true}}' ),
77
+			array('{"bad_json":true}}'),
78 78
 		);
79 79
 	}
80 80
 
81 81
 	public function test_cancel_action() {
82 82
 		$time      = as_get_datetime_object();
83
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
84
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group' );
83
+		$schedule  = new ActionScheduler_SimpleSchedule($time);
84
+		$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, 'my_group');
85 85
 		$store     = new ActionScheduler_wpPostStore();
86
-		$action_id = $store->save_action( $action );
87
-		$store->cancel_action( $action_id );
86
+		$action_id = $store->save_action($action);
87
+		$store->cancel_action($action_id);
88 88
 
89
-		$fetched = $store->fetch_action( $action_id );
90
-		$this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
89
+		$fetched = $store->fetch_action($action_id);
90
+		$this->assertInstanceOf('ActionScheduler_CanceledAction', $fetched);
91 91
 	}
92 92
 
93 93
 	public function test_cancel_actions_by_hook() {
94 94
 		$store   = new ActionScheduler_wpPostStore();
95 95
 		$actions = array();
96 96
 		$hook    = 'by_hook_test';
97
-		for ( $day = 1; $day <= 3; $day++ ) {
98
-			$delta     = sprintf( '+%d day', $day );
99
-			$time      = as_get_datetime_object( $delta );
100
-			$schedule  = new ActionScheduler_SimpleSchedule( $time );
101
-			$action    = new ActionScheduler_Action( $hook, array(), $schedule, 'my_group' );
102
-			$actions[] = $store->save_action( $action );
97
+		for ($day = 1; $day <= 3; $day++) {
98
+			$delta     = sprintf('+%d day', $day);
99
+			$time      = as_get_datetime_object($delta);
100
+			$schedule  = new ActionScheduler_SimpleSchedule($time);
101
+			$action    = new ActionScheduler_Action($hook, array(), $schedule, 'my_group');
102
+			$actions[] = $store->save_action($action);
103 103
 		}
104
-		$store->cancel_actions_by_hook( $hook );
104
+		$store->cancel_actions_by_hook($hook);
105 105
 
106
-		foreach ( $actions as $action_id ) {
107
-			$fetched = $store->fetch_action( $action_id );
108
-			$this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
106
+		foreach ($actions as $action_id) {
107
+			$fetched = $store->fetch_action($action_id);
108
+			$this->assertInstanceOf('ActionScheduler_CanceledAction', $fetched);
109 109
 		}
110 110
 	}
111 111
 
@@ -114,301 +114,301 @@  discard block
 block discarded – undo
114 114
 		$actions = array();
115 115
 		$group   = 'by_group_test';
116 116
 
117
-		for ( $day = 1; $day <= 3; $day++ ) {
118
-			$delta     = sprintf( '+%d day', $day );
119
-			$time      = as_get_datetime_object( $delta );
120
-			$schedule  = new ActionScheduler_SimpleSchedule( $time );
121
-			$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, $group );
122
-			$actions[] = $store->save_action( $action );
117
+		for ($day = 1; $day <= 3; $day++) {
118
+			$delta     = sprintf('+%d day', $day);
119
+			$time      = as_get_datetime_object($delta);
120
+			$schedule  = new ActionScheduler_SimpleSchedule($time);
121
+			$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule, $group);
122
+			$actions[] = $store->save_action($action);
123 123
 		}
124
-		$store->cancel_actions_by_group( $group );
124
+		$store->cancel_actions_by_group($group);
125 125
 
126
-		foreach ( $actions as $action_id ) {
127
-			$fetched = $store->fetch_action( $action_id );
128
-			$this->assertInstanceOf( 'ActionScheduler_CanceledAction', $fetched );
126
+		foreach ($actions as $action_id) {
127
+			$fetched = $store->fetch_action($action_id);
128
+			$this->assertInstanceOf('ActionScheduler_CanceledAction', $fetched);
129 129
 		}
130 130
 	}
131 131
 
132 132
 	public function test_claim_actions() {
133 133
 		$created_actions = array();
134 134
 		$store           = new ActionScheduler_wpPostStore();
135
-		for ( $i = 3; $i > -3; $i-- ) {
136
-			$time              = as_get_datetime_object( $i . ' hours' );
137
-			$schedule          = new ActionScheduler_SimpleSchedule( $time );
138
-			$action            = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
139
-			$created_actions[] = $store->save_action( $action );
135
+		for ($i = 3; $i > -3; $i--) {
136
+			$time              = as_get_datetime_object($i.' hours');
137
+			$schedule          = new ActionScheduler_SimpleSchedule($time);
138
+			$action            = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array($i), $schedule, 'my_group');
139
+			$created_actions[] = $store->save_action($action);
140 140
 		}
141 141
 
142 142
 		$claim = $store->stake_claim();
143
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
143
+		$this->assertInstanceof('ActionScheduler_ActionClaim', $claim);
144 144
 
145
-		$this->assertCount( 3, $claim->get_actions() );
146
-		$this->assertEqualSets( array_slice( $created_actions, 3, 3 ), $claim->get_actions() );
145
+		$this->assertCount(3, $claim->get_actions());
146
+		$this->assertEqualSets(array_slice($created_actions, 3, 3), $claim->get_actions());
147 147
 	}
148 148
 
149 149
 	public function test_claim_actions_order() {
150 150
 		$store           = new ActionScheduler_wpPostStore();
151
-		$schedule        = new ActionScheduler_SimpleSchedule( as_get_datetime_object( '-1 hour' ) );
151
+		$schedule        = new ActionScheduler_SimpleSchedule(as_get_datetime_object('-1 hour'));
152 152
 		$created_actions = array(
153
-			$store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'my_group' ) ),
154
-			$store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'my_group' ) ),
153
+			$store->save_action(new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(1), $schedule, 'my_group')),
154
+			$store->save_action(new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(1), $schedule, 'my_group')),
155 155
 		);
156 156
 
157 157
 		$claim = $store->stake_claim();
158
-		$this->assertInstanceof( 'ActionScheduler_ActionClaim', $claim );
158
+		$this->assertInstanceof('ActionScheduler_ActionClaim', $claim);
159 159
 
160 160
 		// Verify uniqueness of action IDs.
161
-		$this->assertCount( 2, array_unique( $created_actions ) );
161
+		$this->assertCount(2, array_unique($created_actions));
162 162
 
163 163
 		// Verify the count and order of the actions.
164 164
 		$claimed_actions = $claim->get_actions();
165
-		$this->assertCount( 2, $claimed_actions );
166
-		$this->assertEquals( $created_actions, $claimed_actions );
165
+		$this->assertCount(2, $claimed_actions);
166
+		$this->assertEquals($created_actions, $claimed_actions);
167 167
 
168 168
 		// Verify the reversed order doesn't pass.
169
-		$reversed_actions = array_reverse( $created_actions );
170
-		$this->assertNotEquals( $reversed_actions, $claimed_actions );
169
+		$reversed_actions = array_reverse($created_actions);
170
+		$this->assertNotEquals($reversed_actions, $claimed_actions);
171 171
 	}
172 172
 
173 173
 	public function test_duplicate_claim() {
174 174
 		$created_actions = array();
175 175
 		$store           = new ActionScheduler_wpPostStore();
176
-		for ( $i = 0; $i > -3; $i-- ) {
177
-			$time              = as_get_datetime_object( $i . ' hours' );
178
-			$schedule          = new ActionScheduler_SimpleSchedule( $time );
179
-			$action            = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
180
-			$created_actions[] = $store->save_action( $action );
176
+		for ($i = 0; $i > -3; $i--) {
177
+			$time              = as_get_datetime_object($i.' hours');
178
+			$schedule          = new ActionScheduler_SimpleSchedule($time);
179
+			$action            = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array($i), $schedule, 'my_group');
180
+			$created_actions[] = $store->save_action($action);
181 181
 		}
182 182
 
183 183
 		$claim1 = $store->stake_claim();
184 184
 		$claim2 = $store->stake_claim();
185
-		$this->assertCount( 3, $claim1->get_actions() );
186
-		$this->assertCount( 0, $claim2->get_actions() );
185
+		$this->assertCount(3, $claim1->get_actions());
186
+		$this->assertCount(0, $claim2->get_actions());
187 187
 	}
188 188
 
189 189
 	public function test_release_claim() {
190 190
 		$created_actions = array();
191 191
 		$store           = new ActionScheduler_wpPostStore();
192
-		for ( $i = 0; $i > -3; $i-- ) {
193
-			$time              = as_get_datetime_object( $i . ' hours' );
194
-			$schedule          = new ActionScheduler_SimpleSchedule( $time );
195
-			$action            = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
196
-			$created_actions[] = $store->save_action( $action );
192
+		for ($i = 0; $i > -3; $i--) {
193
+			$time              = as_get_datetime_object($i.' hours');
194
+			$schedule          = new ActionScheduler_SimpleSchedule($time);
195
+			$action            = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array($i), $schedule, 'my_group');
196
+			$created_actions[] = $store->save_action($action);
197 197
 		}
198 198
 
199 199
 		$claim1 = $store->stake_claim();
200 200
 
201
-		$store->release_claim( $claim1 );
201
+		$store->release_claim($claim1);
202 202
 
203 203
 		$claim2 = $store->stake_claim();
204
-		$this->assertCount( 3, $claim2->get_actions() );
204
+		$this->assertCount(3, $claim2->get_actions());
205 205
 	}
206 206
 
207 207
 	public function test_search() {
208 208
 		$created_actions = array();
209 209
 		$store           = new ActionScheduler_wpPostStore();
210
-		for ( $i = -3; $i <= 3; $i++ ) {
211
-			$time              = as_get_datetime_object( $i . ' hours' );
212
-			$schedule          = new ActionScheduler_SimpleSchedule( $time );
213
-			$action            = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( $i ), $schedule, 'my_group' );
214
-			$created_actions[] = $store->save_action( $action );
210
+		for ($i = -3; $i <= 3; $i++) {
211
+			$time              = as_get_datetime_object($i.' hours');
212
+			$schedule          = new ActionScheduler_SimpleSchedule($time);
213
+			$action            = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array($i), $schedule, 'my_group');
214
+			$created_actions[] = $store->save_action($action);
215 215
 		}
216 216
 
217
-		$next_no_args = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK );
218
-		$this->assertEquals( $created_actions[0], $next_no_args );
217
+		$next_no_args = $store->find_action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK);
218
+		$this->assertEquals($created_actions[0], $next_no_args);
219 219
 
220
-		$next_with_args = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'args' => array( 1 ) ) );
221
-		$this->assertEquals( $created_actions[4], $next_with_args );
220
+		$next_with_args = $store->find_action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array('args' => array(1)));
221
+		$this->assertEquals($created_actions[4], $next_with_args);
222 222
 
223
-		$non_existent = $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'args' => array( 17 ) ) );
224
-		$this->assertNull( $non_existent );
223
+		$non_existent = $store->find_action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array('args' => array(17)));
224
+		$this->assertNull($non_existent);
225 225
 	}
226 226
 
227 227
 	public function test_search_by_group() {
228 228
 		$store    = new ActionScheduler_wpPostStore();
229
-		$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( 'tomorrow' ) );
230
-		$abc      = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'abc' ) );
231
-		$def      = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'def' ) );
232
-		$ghi      = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule, 'ghi' ) );
233
-
234
-		$this->assertEquals( $abc, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'abc' ) ) );
235
-		$this->assertEquals( $def, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'def' ) ) );
236
-		$this->assertEquals( $ghi, $store->find_action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 'group' => 'ghi' ) ) );
229
+		$schedule = new ActionScheduler_SimpleSchedule(as_get_datetime_object('tomorrow'));
230
+		$abc      = $store->save_action(new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(1), $schedule, 'abc'));
231
+		$def      = $store->save_action(new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(1), $schedule, 'def'));
232
+		$ghi      = $store->save_action(new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(1), $schedule, 'ghi'));
233
+
234
+		$this->assertEquals($abc, $store->find_action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array('group' => 'abc')));
235
+		$this->assertEquals($def, $store->find_action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array('group' => 'def')));
236
+		$this->assertEquals($ghi, $store->find_action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array('group' => 'ghi')));
237 237
 	}
238 238
 
239 239
 	public function test_post_author() {
240 240
 		$current_user = get_current_user_id();
241 241
 
242 242
 		$time      = as_get_datetime_object();
243
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
244
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
243
+		$schedule  = new ActionScheduler_SimpleSchedule($time);
244
+		$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
245 245
 		$store     = new ActionScheduler_wpPostStore();
246
-		$action_id = $store->save_action( $action );
246
+		$action_id = $store->save_action($action);
247 247
 
248
-		$post = get_post( $action_id );
249
-		$this->assertSame( 0, $post->post_author );
248
+		$post = get_post($action_id);
249
+		$this->assertSame(0, $post->post_author);
250 250
 
251 251
 		$new_user = $this->factory->user->create_object(
252 252
 			array(
253 253
 				'user_login' => __FUNCTION__,
254
-				'user_pass'  => md5( rand() ),
254
+				'user_pass'  => md5(rand()),
255 255
 			)
256 256
 		);
257
-		wp_set_current_user( $new_user );
257
+		wp_set_current_user($new_user);
258 258
 
259
-		$schedule  = new ActionScheduler_SimpleSchedule( $time );
260
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
261
-		$action_id = $store->save_action( $action );
262
-		$post      = get_post( $action_id );
263
-		$this->assertSame( 0, $post->post_author );
259
+		$schedule  = new ActionScheduler_SimpleSchedule($time);
260
+		$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
261
+		$action_id = $store->save_action($action);
262
+		$post      = get_post($action_id);
263
+		$this->assertSame(0, $post->post_author);
264 264
 
265
-		wp_set_current_user( $current_user );
265
+		wp_set_current_user($current_user);
266 266
 	}
267 267
 
268 268
 	/**
269 269
 	 * @issue 13
270 270
 	 */
271 271
 	public function test_post_status_for_recurring_action() {
272
-		$time      = as_get_datetime_object( '10 minutes' );
273
-		$schedule  = new ActionScheduler_IntervalSchedule( $time, HOUR_IN_SECONDS );
274
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
272
+		$time      = as_get_datetime_object('10 minutes');
273
+		$schedule  = new ActionScheduler_IntervalSchedule($time, HOUR_IN_SECONDS);
274
+		$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
275 275
 		$store     = new ActionScheduler_wpPostStore();
276
-		$action_id = $store->save_action( $action );
276
+		$action_id = $store->save_action($action);
277 277
 
278
-		$action = $store->fetch_action( $action_id );
278
+		$action = $store->fetch_action($action_id);
279 279
 		$action->execute();
280
-		$store->mark_complete( $action_id );
280
+		$store->mark_complete($action_id);
281 281
 
282
-		$next          = $action->get_schedule()->get_next( as_get_datetime_object() );
283
-		$new_action_id = $store->save_action( $action, $next );
282
+		$next          = $action->get_schedule()->get_next(as_get_datetime_object());
283
+		$new_action_id = $store->save_action($action, $next);
284 284
 
285
-		$this->assertEquals( 'publish', get_post_status( $action_id ) );
286
-		$this->assertEquals( 'pending', get_post_status( $new_action_id ) );
285
+		$this->assertEquals('publish', get_post_status($action_id));
286
+		$this->assertEquals('pending', get_post_status($new_action_id));
287 287
 	}
288 288
 
289 289
 	public function test_get_run_date() {
290
-		$time      = as_get_datetime_object( '-10 minutes' );
291
-		$schedule  = new ActionScheduler_IntervalSchedule( $time, HOUR_IN_SECONDS );
292
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
290
+		$time      = as_get_datetime_object('-10 minutes');
291
+		$schedule  = new ActionScheduler_IntervalSchedule($time, HOUR_IN_SECONDS);
292
+		$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
293 293
 		$store     = new ActionScheduler_wpPostStore();
294
-		$action_id = $store->save_action( $action );
294
+		$action_id = $store->save_action($action);
295 295
 
296
-		$this->assertEquals( $store->get_date( $action_id )->getTimestamp(), $time->getTimestamp() );
296
+		$this->assertEquals($store->get_date($action_id)->getTimestamp(), $time->getTimestamp());
297 297
 
298
-		$action = $store->fetch_action( $action_id );
298
+		$action = $store->fetch_action($action_id);
299 299
 		$action->execute();
300 300
 		$now = as_get_datetime_object();
301
-		$store->mark_complete( $action_id );
301
+		$store->mark_complete($action_id);
302 302
 
303
-		$this->assertEquals( $store->get_date( $action_id )->getTimestamp(), $now->getTimestamp(), '', 1 ); // allow timestamp to be 1 second off for older versions of PHP
303
+		$this->assertEquals($store->get_date($action_id)->getTimestamp(), $now->getTimestamp(), '', 1); // allow timestamp to be 1 second off for older versions of PHP
304 304
 
305
-		$next          = $action->get_schedule()->get_next( $now );
306
-		$new_action_id = $store->save_action( $action, $next );
305
+		$next          = $action->get_schedule()->get_next($now);
306
+		$new_action_id = $store->save_action($action, $next);
307 307
 
308
-		$this->assertEquals( (int) ( $now->getTimestamp() ) + HOUR_IN_SECONDS, $store->get_date( $new_action_id )->getTimestamp() );
308
+		$this->assertEquals((int) ($now->getTimestamp()) + HOUR_IN_SECONDS, $store->get_date($new_action_id)->getTimestamp());
309 309
 	}
310 310
 
311 311
 	public function test_claim_actions_by_hooks() {
312
-		$hook1    = __FUNCTION__ . '_hook_1';
313
-		$hook2    = __FUNCTION__ . '_hook_2';
312
+		$hook1    = __FUNCTION__.'_hook_1';
313
+		$hook2    = __FUNCTION__.'_hook_2';
314 314
 		$store    = new ActionScheduler_wpPostStore();
315
-		$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( '-1 hour' ) );
315
+		$schedule = new ActionScheduler_SimpleSchedule(as_get_datetime_object('-1 hour'));
316 316
 
317
-		$action1 = $store->save_action( new ActionScheduler_Action( $hook1, array(), $schedule ) );
318
-		$action2 = $store->save_action( new ActionScheduler_Action( $hook2, array(), $schedule ) );
317
+		$action1 = $store->save_action(new ActionScheduler_Action($hook1, array(), $schedule));
318
+		$action2 = $store->save_action(new ActionScheduler_Action($hook2, array(), $schedule));
319 319
 
320 320
 		// Claiming no hooks should include all actions.
321
-		$claim = $store->stake_claim( 10 );
322
-		$this->assertCount( 2, $claim->get_actions() );
323
-		$this->assertContains( $action1, $claim->get_actions() );
324
-		$this->assertContains( $action2, $claim->get_actions() );
325
-		$store->release_claim( $claim );
321
+		$claim = $store->stake_claim(10);
322
+		$this->assertCount(2, $claim->get_actions());
323
+		$this->assertContains($action1, $claim->get_actions());
324
+		$this->assertContains($action2, $claim->get_actions());
325
+		$store->release_claim($claim);
326 326
 
327 327
 		// Claiming a hook should claim only actions with that hook
328
-		$claim = $store->stake_claim( 10, null, array( $hook1 ) );
329
-		$this->assertCount( 1, $claim->get_actions() );
330
-		$this->assertContains( $action1, $claim->get_actions() );
331
-		$store->release_claim( $claim );
328
+		$claim = $store->stake_claim(10, null, array($hook1));
329
+		$this->assertCount(1, $claim->get_actions());
330
+		$this->assertContains($action1, $claim->get_actions());
331
+		$store->release_claim($claim);
332 332
 
333 333
 		// Claiming two hooks should claim actions with either of those hooks
334
-		$claim = $store->stake_claim( 10, null, array( $hook1, $hook2 ) );
335
-		$this->assertCount( 2, $claim->get_actions() );
336
-		$this->assertContains( $action1, $claim->get_actions() );
337
-		$this->assertContains( $action2, $claim->get_actions() );
338
-		$store->release_claim( $claim );
334
+		$claim = $store->stake_claim(10, null, array($hook1, $hook2));
335
+		$this->assertCount(2, $claim->get_actions());
336
+		$this->assertContains($action1, $claim->get_actions());
337
+		$this->assertContains($action2, $claim->get_actions());
338
+		$store->release_claim($claim);
339 339
 
340 340
 		// Claiming two hooks should claim actions with either of those hooks
341
-		$claim = $store->stake_claim( 10, null, array( __METHOD__ . '_hook_3' ) );
342
-		$this->assertCount( 0, $claim->get_actions() );
343
-		$this->assertNotContains( $action1, $claim->get_actions() );
344
-		$this->assertNotContains( $action2, $claim->get_actions() );
345
-		$store->release_claim( $claim );
341
+		$claim = $store->stake_claim(10, null, array(__METHOD__.'_hook_3'));
342
+		$this->assertCount(0, $claim->get_actions());
343
+		$this->assertNotContains($action1, $claim->get_actions());
344
+		$this->assertNotContains($action2, $claim->get_actions());
345
+		$store->release_claim($claim);
346 346
 	}
347 347
 
348 348
 	/**
349 349
 	 * @issue 121
350 350
 	 */
351 351
 	public function test_claim_actions_by_group() {
352
-		$group1   = md5( rand() );
352
+		$group1   = md5(rand());
353 353
 		$store    = new ActionScheduler_wpPostStore();
354
-		$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( '-1 hour' ) );
354
+		$schedule = new ActionScheduler_SimpleSchedule(as_get_datetime_object('-1 hour'));
355 355
 
356
-		$action1 = $store->save_action( new ActionScheduler_Action( __METHOD__, array(), $schedule, $group1 ) );
357
-		$action2 = $store->save_action( new ActionScheduler_Action( __METHOD__, array(), $schedule ) );
356
+		$action1 = $store->save_action(new ActionScheduler_Action(__METHOD__, array(), $schedule, $group1));
357
+		$action2 = $store->save_action(new ActionScheduler_Action(__METHOD__, array(), $schedule));
358 358
 
359 359
 		// Claiming no group should include all actions.
360
-		$claim = $store->stake_claim( 10 );
361
-		$this->assertCount( 2, $claim->get_actions() );
362
-		$this->assertContains( $action1, $claim->get_actions() );
363
-		$this->assertContains( $action2, $claim->get_actions() );
364
-		$store->release_claim( $claim );
360
+		$claim = $store->stake_claim(10);
361
+		$this->assertCount(2, $claim->get_actions());
362
+		$this->assertContains($action1, $claim->get_actions());
363
+		$this->assertContains($action2, $claim->get_actions());
364
+		$store->release_claim($claim);
365 365
 
366 366
 		// Claiming a group should claim only actions in that group.
367
-		$claim = $store->stake_claim( 10, null, array(), $group1 );
368
-		$this->assertCount( 1, $claim->get_actions() );
369
-		$this->assertContains( $action1, $claim->get_actions() );
370
-		$store->release_claim( $claim );
367
+		$claim = $store->stake_claim(10, null, array(), $group1);
368
+		$this->assertCount(1, $claim->get_actions());
369
+		$this->assertContains($action1, $claim->get_actions());
370
+		$store->release_claim($claim);
371 371
 	}
372 372
 
373 373
 	public function test_claim_actions_by_hook_and_group() {
374
-		$hook1    = __FUNCTION__ . '_hook_1';
375
-		$hook2    = __FUNCTION__ . '_hook_2';
376
-		$hook3    = __FUNCTION__ . '_hook_3';
377
-		$group1   = 'group_' . md5( rand() );
378
-		$group2   = 'group_' . md5( rand() );
374
+		$hook1    = __FUNCTION__.'_hook_1';
375
+		$hook2    = __FUNCTION__.'_hook_2';
376
+		$hook3    = __FUNCTION__.'_hook_3';
377
+		$group1   = 'group_'.md5(rand());
378
+		$group2   = 'group_'.md5(rand());
379 379
 		$store    = new ActionScheduler_wpPostStore();
380
-		$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( '-1 hour' ) );
380
+		$schedule = new ActionScheduler_SimpleSchedule(as_get_datetime_object('-1 hour'));
381 381
 
382
-		$action1 = $store->save_action( new ActionScheduler_Action( $hook1, array(), $schedule, $group1 ) );
383
-		$action2 = $store->save_action( new ActionScheduler_Action( $hook2, array(), $schedule ) );
384
-		$action3 = $store->save_action( new ActionScheduler_Action( $hook3, array(), $schedule, $group2 ) );
382
+		$action1 = $store->save_action(new ActionScheduler_Action($hook1, array(), $schedule, $group1));
383
+		$action2 = $store->save_action(new ActionScheduler_Action($hook2, array(), $schedule));
384
+		$action3 = $store->save_action(new ActionScheduler_Action($hook3, array(), $schedule, $group2));
385 385
 
386 386
 		// Claiming no hooks or group should include all actions.
387
-		$claim = $store->stake_claim( 10 );
388
-		$this->assertCount( 3, $claim->get_actions() );
389
-		$this->assertContains( $action1, $claim->get_actions() );
390
-		$this->assertContains( $action2, $claim->get_actions() );
391
-		$store->release_claim( $claim );
387
+		$claim = $store->stake_claim(10);
388
+		$this->assertCount(3, $claim->get_actions());
389
+		$this->assertContains($action1, $claim->get_actions());
390
+		$this->assertContains($action2, $claim->get_actions());
391
+		$store->release_claim($claim);
392 392
 
393 393
 		// Claiming a group and hook should claim only actions in that group.
394
-		$claim = $store->stake_claim( 10, null, array( $hook1 ), $group1 );
395
-		$this->assertCount( 1, $claim->get_actions() );
396
-		$this->assertContains( $action1, $claim->get_actions() );
397
-		$store->release_claim( $claim );
394
+		$claim = $store->stake_claim(10, null, array($hook1), $group1);
395
+		$this->assertCount(1, $claim->get_actions());
396
+		$this->assertContains($action1, $claim->get_actions());
397
+		$store->release_claim($claim);
398 398
 
399 399
 		// Claiming a group and hook should claim only actions with that hook in that group.
400
-		$claim = $store->stake_claim( 10, null, array( $hook2 ), $group1 );
401
-		$this->assertCount( 0, $claim->get_actions() );
402
-		$this->assertNotContains( $action1, $claim->get_actions() );
403
-		$this->assertNotContains( $action2, $claim->get_actions() );
404
-		$store->release_claim( $claim );
400
+		$claim = $store->stake_claim(10, null, array($hook2), $group1);
401
+		$this->assertCount(0, $claim->get_actions());
402
+		$this->assertNotContains($action1, $claim->get_actions());
403
+		$this->assertNotContains($action2, $claim->get_actions());
404
+		$store->release_claim($claim);
405 405
 
406 406
 		// Claiming a group and hook should claim only actions with that hook in that group.
407
-		$claim = $store->stake_claim( 10, null, array( $hook1, $hook2 ), $group2 );
408
-		$this->assertCount( 0, $claim->get_actions() );
409
-		$this->assertNotContains( $action1, $claim->get_actions() );
410
-		$this->assertNotContains( $action2, $claim->get_actions() );
411
-		$store->release_claim( $claim );
407
+		$claim = $store->stake_claim(10, null, array($hook1, $hook2), $group2);
408
+		$this->assertCount(0, $claim->get_actions());
409
+		$this->assertNotContains($action1, $claim->get_actions());
410
+		$this->assertNotContains($action2, $claim->get_actions());
411
+		$store->release_claim($claim);
412 412
 	}
413 413
 
414 414
 	/**
@@ -426,14 +426,14 @@  discard block
 block discarded – undo
426 426
 		$store = new ActionScheduler_wpPostStore();
427 427
 
428 428
 		// Create 4 actions: 2 that are already due (-3hrs and -1hrs) and 2 that are not yet due (+1hr and +3hrs).
429
-		for ( $i = -3; $i <= 3; $i += 2 ) {
430
-			$schedule     = new ActionScheduler_SimpleSchedule( as_get_datetime_object( $i . ' hours' ) );
431
-			$action_ids[] = $store->save_action( new ActionScheduler_Action( 'test_' . $i, array(), $schedule, $group ) );
429
+		for ($i = -3; $i <= 3; $i += 2) {
430
+			$schedule     = new ActionScheduler_SimpleSchedule(as_get_datetime_object($i.' hours'));
431
+			$action_ids[] = $store->save_action(new ActionScheduler_Action('test_'.$i, array(), $schedule, $group));
432 432
 		}
433 433
 
434 434
 		// This callback is used to simulate the unusual conditions whereby MySQL might unexpectedly return future
435 435
 		// actions, contrary to the conditions used by the store object when staking its claim.
436
-		$simulate_unexpected_db_behavior = function ( $sql ) use ( $action_ids ) {
436
+		$simulate_unexpected_db_behavior = function($sql) use ($action_ids) {
437 437
 			global $wpdb;
438 438
 
439 439
 			$post_type = ActionScheduler_wpPostStore::POST_TYPE;
@@ -441,25 +441,25 @@  discard block
 block discarded – undo
441 441
 
442 442
 			// Look out for the claim update query, ignore all others.
443 443
 			if (
444
-				0 !== strpos( $sql, "UPDATE $wpdb->posts" )
445
-				|| 0 !== strpos( $sql, "WHERE post_type = '$post_type' AND post_status = '$pending' AND post_password = ''" )
446
-				|| ! preg_match( "/AND post_date_gmt <= '([0-9:\-\s]{19})'/", $sql, $matches )
447
-				|| count( $matches ) !== 2
444
+				0 !== strpos($sql, "UPDATE $wpdb->posts")
445
+				|| 0 !== strpos($sql, "WHERE post_type = '$post_type' AND post_status = '$pending' AND post_password = ''")
446
+				|| ! preg_match("/AND post_date_gmt <= '([0-9:\-\s]{19})'/", $sql, $matches)
447
+				|| count($matches) !== 2
448 448
 			) {
449 449
 				return $sql;
450 450
 			}
451 451
 
452 452
 			// Now modify the query, forcing it to also return the future actions we created.
453
-			return str_replace( $matches[1], as_get_datetime_object( '+4 hours' )->format( 'Y-m-d H:i:s' ), $sql );
453
+			return str_replace($matches[1], as_get_datetime_object('+4 hours')->format('Y-m-d H:i:s'), $sql);
454 454
 		};
455 455
 
456
-		add_filter( 'query', $simulate_unexpected_db_behavior );
457
-		$claim           = $store->stake_claim( 10, null, array(), $group );
456
+		add_filter('query', $simulate_unexpected_db_behavior);
457
+		$claim           = $store->stake_claim(10, null, array(), $group);
458 458
 		$claimed_actions = $claim->get_actions();
459
-		$this->assertCount( 2, $claimed_actions );
459
+		$this->assertCount(2, $claimed_actions);
460 460
 
461 461
 		// Cleanup.
462
-		remove_filter( 'query', $simulate_unexpected_db_behavior );
463
-		$store->release_claim( $claim );
462
+		remove_filter('query', $simulate_unexpected_db_behavior);
463
+		$store->release_claim($claim);
464 464
 	}
465 465
 }
Please login to merge, or discard this patch.
src/ext/action-scheduler/tests/phpunit/jobstore/AbstractStoreTest.php 2 patches
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -18,101 +18,101 @@
 block discarded – undo
18 18
  */
19 19
 abstract class AbstractStoreTest extends ActionScheduler_UnitTestCase {
20 20
 
21
-	/**
22
-	 * Get data store for tests.
23
-	 *
24
-	 * @return ActionScheduler_Store
25
-	 */
26
-	abstract protected function get_store();
27
-
28
-	public function test_get_status() {
29
-		$time      = as_get_datetime_object( '-10 minutes' );
30
-		$schedule  = new ActionScheduler_IntervalSchedule( $time, HOUR_IN_SECONDS );
31
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
32
-		$store     = $this->get_store();
33
-		$action_id = $store->save_action( $action );
34
-
35
-		$this->assertEquals( ActionScheduler_Store::STATUS_PENDING, $store->get_status( $action_id ) );
36
-
37
-		$store->mark_complete( $action_id );
38
-		$this->assertEquals( ActionScheduler_Store::STATUS_COMPLETE, $store->get_status( $action_id ) );
39
-
40
-		$store->mark_failure( $action_id );
41
-		$this->assertEquals( ActionScheduler_Store::STATUS_FAILED, $store->get_status( $action_id ) );
42
-	}
43
-
44
-	/* Start tests for \ActionScheduler_Store::query_actions() */
45
-
46
-	public function test_query_actions_query_type_arg_invalid_option() {
47
-		$this->expectException( InvalidArgumentException::class );
48
-		$this->get_store()->query_actions( array( 'hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ), 'invalid' );
49
-	}
50
-
51
-	public function test_query_actions_query_type_arg_valid_options() {
52
-		$store    = $this->get_store();
53
-		$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( 'tomorrow' ) );
54
-
55
-		$action_id_1 = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule ) );
56
-		$action_id_2 = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule ) );
57
-
58
-		$this->assertEquals( array( $action_id_1, $action_id_2 ), $store->query_actions( array( 'hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ) ) );
59
-		$this->assertEquals( 2, $store->query_actions( array( 'hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ), 'count' ) );
60
-	}
61
-
62
-	public function test_query_actions_by_single_status() {
63
-		$store    = $this->get_store();
64
-		$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( 'tomorrow' ) );
65
-
66
-		$this->assertSame( 0, $store->query_actions( array( 'status' => ActionScheduler_Store::STATUS_PENDING ), 'count' ) );
67
-
68
-		$action_id_1 = $store->save_action( new ActionScheduler_Action( 'my_hook_1', array( 1 ), $schedule ) );
69
-		$action_id_2 = $store->save_action( new ActionScheduler_Action( 'my_hook_2', array( 1 ), $schedule ) );
70
-		$action_id_3 = $store->save_action( new ActionScheduler_Action( 'my_hook_3', array( 1 ), $schedule ) );
71
-		$store->mark_complete( $action_id_3 );
72
-
73
-		$this->assertEquals( 2, $store->query_actions( array( 'status' => ActionScheduler_Store::STATUS_PENDING ), 'count' ) );
74
-		$this->assertSame( 1, $store->query_actions( array( 'status' => ActionScheduler_Store::STATUS_COMPLETE ), 'count' ) );
75
-	}
76
-
77
-	public function test_query_actions_by_array_status() {
78
-		$store    = $this->get_store();
79
-		$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( 'tomorrow' ) );
80
-
81
-		$this->assertSame(
82
-			0,
83
-			$store->query_actions(
84
-				array(
85
-					'status' => array( ActionScheduler_Store::STATUS_PENDING, ActionScheduler_Store::STATUS_RUNNING ),
86
-				),
87
-				'count'
88
-			)
89
-		);
90
-
91
-		$action_id_1 = $store->save_action( new ActionScheduler_Action( 'my_hook_1', array( 1 ), $schedule ) );
92
-		$action_id_2 = $store->save_action( new ActionScheduler_Action( 'my_hook_2', array( 1 ), $schedule ) );
93
-		$action_id_3 = $store->save_action( new ActionScheduler_Action( 'my_hook_3', array( 1 ), $schedule ) );
94
-		$store->mark_failure( $action_id_3 );
95
-
96
-		$this->assertEquals(
97
-			3,
98
-			$store->query_actions(
99
-				array(
100
-					'status' => array( ActionScheduler_Store::STATUS_PENDING, ActionScheduler_Store::STATUS_FAILED ),
101
-				),
102
-				'count'
103
-			)
104
-		);
105
-		$this->assertEquals(
106
-			2,
107
-			$store->query_actions(
108
-				array(
109
-					'status' => array( ActionScheduler_Store::STATUS_PENDING, ActionScheduler_Store::STATUS_COMPLETE ),
110
-				),
111
-				'count'
112
-			)
113
-		);
114
-	}
115
-
116
-	/* End tests for \ActionScheduler_Store::query_actions() */
21
+    /**
22
+     * Get data store for tests.
23
+     *
24
+     * @return ActionScheduler_Store
25
+     */
26
+    abstract protected function get_store();
27
+
28
+    public function test_get_status() {
29
+        $time      = as_get_datetime_object( '-10 minutes' );
30
+        $schedule  = new ActionScheduler_IntervalSchedule( $time, HOUR_IN_SECONDS );
31
+        $action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
32
+        $store     = $this->get_store();
33
+        $action_id = $store->save_action( $action );
34
+
35
+        $this->assertEquals( ActionScheduler_Store::STATUS_PENDING, $store->get_status( $action_id ) );
36
+
37
+        $store->mark_complete( $action_id );
38
+        $this->assertEquals( ActionScheduler_Store::STATUS_COMPLETE, $store->get_status( $action_id ) );
39
+
40
+        $store->mark_failure( $action_id );
41
+        $this->assertEquals( ActionScheduler_Store::STATUS_FAILED, $store->get_status( $action_id ) );
42
+    }
43
+
44
+    /* Start tests for \ActionScheduler_Store::query_actions() */
45
+
46
+    public function test_query_actions_query_type_arg_invalid_option() {
47
+        $this->expectException( InvalidArgumentException::class );
48
+        $this->get_store()->query_actions( array( 'hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ), 'invalid' );
49
+    }
50
+
51
+    public function test_query_actions_query_type_arg_valid_options() {
52
+        $store    = $this->get_store();
53
+        $schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( 'tomorrow' ) );
54
+
55
+        $action_id_1 = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule ) );
56
+        $action_id_2 = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule ) );
57
+
58
+        $this->assertEquals( array( $action_id_1, $action_id_2 ), $store->query_actions( array( 'hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ) ) );
59
+        $this->assertEquals( 2, $store->query_actions( array( 'hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ), 'count' ) );
60
+    }
61
+
62
+    public function test_query_actions_by_single_status() {
63
+        $store    = $this->get_store();
64
+        $schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( 'tomorrow' ) );
65
+
66
+        $this->assertSame( 0, $store->query_actions( array( 'status' => ActionScheduler_Store::STATUS_PENDING ), 'count' ) );
67
+
68
+        $action_id_1 = $store->save_action( new ActionScheduler_Action( 'my_hook_1', array( 1 ), $schedule ) );
69
+        $action_id_2 = $store->save_action( new ActionScheduler_Action( 'my_hook_2', array( 1 ), $schedule ) );
70
+        $action_id_3 = $store->save_action( new ActionScheduler_Action( 'my_hook_3', array( 1 ), $schedule ) );
71
+        $store->mark_complete( $action_id_3 );
72
+
73
+        $this->assertEquals( 2, $store->query_actions( array( 'status' => ActionScheduler_Store::STATUS_PENDING ), 'count' ) );
74
+        $this->assertSame( 1, $store->query_actions( array( 'status' => ActionScheduler_Store::STATUS_COMPLETE ), 'count' ) );
75
+    }
76
+
77
+    public function test_query_actions_by_array_status() {
78
+        $store    = $this->get_store();
79
+        $schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( 'tomorrow' ) );
80
+
81
+        $this->assertSame(
82
+            0,
83
+            $store->query_actions(
84
+                array(
85
+                    'status' => array( ActionScheduler_Store::STATUS_PENDING, ActionScheduler_Store::STATUS_RUNNING ),
86
+                ),
87
+                'count'
88
+            )
89
+        );
90
+
91
+        $action_id_1 = $store->save_action( new ActionScheduler_Action( 'my_hook_1', array( 1 ), $schedule ) );
92
+        $action_id_2 = $store->save_action( new ActionScheduler_Action( 'my_hook_2', array( 1 ), $schedule ) );
93
+        $action_id_3 = $store->save_action( new ActionScheduler_Action( 'my_hook_3', array( 1 ), $schedule ) );
94
+        $store->mark_failure( $action_id_3 );
95
+
96
+        $this->assertEquals(
97
+            3,
98
+            $store->query_actions(
99
+                array(
100
+                    'status' => array( ActionScheduler_Store::STATUS_PENDING, ActionScheduler_Store::STATUS_FAILED ),
101
+                ),
102
+                'count'
103
+            )
104
+        );
105
+        $this->assertEquals(
106
+            2,
107
+            $store->query_actions(
108
+                array(
109
+                    'status' => array( ActionScheduler_Store::STATUS_PENDING, ActionScheduler_Store::STATUS_COMPLETE ),
110
+                ),
111
+                'count'
112
+            )
113
+        );
114
+    }
115
+
116
+    /* End tests for \ActionScheduler_Store::query_actions() */
117 117
 
118 118
 }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -26,78 +26,78 @@  discard block
 block discarded – undo
26 26
 	abstract protected function get_store();
27 27
 
28 28
 	public function test_get_status() {
29
-		$time      = as_get_datetime_object( '-10 minutes' );
30
-		$schedule  = new ActionScheduler_IntervalSchedule( $time, HOUR_IN_SECONDS );
31
-		$action    = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
29
+		$time      = as_get_datetime_object('-10 minutes');
30
+		$schedule  = new ActionScheduler_IntervalSchedule($time, HOUR_IN_SECONDS);
31
+		$action    = new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule);
32 32
 		$store     = $this->get_store();
33
-		$action_id = $store->save_action( $action );
33
+		$action_id = $store->save_action($action);
34 34
 
35
-		$this->assertEquals( ActionScheduler_Store::STATUS_PENDING, $store->get_status( $action_id ) );
35
+		$this->assertEquals(ActionScheduler_Store::STATUS_PENDING, $store->get_status($action_id));
36 36
 
37
-		$store->mark_complete( $action_id );
38
-		$this->assertEquals( ActionScheduler_Store::STATUS_COMPLETE, $store->get_status( $action_id ) );
37
+		$store->mark_complete($action_id);
38
+		$this->assertEquals(ActionScheduler_Store::STATUS_COMPLETE, $store->get_status($action_id));
39 39
 
40
-		$store->mark_failure( $action_id );
41
-		$this->assertEquals( ActionScheduler_Store::STATUS_FAILED, $store->get_status( $action_id ) );
40
+		$store->mark_failure($action_id);
41
+		$this->assertEquals(ActionScheduler_Store::STATUS_FAILED, $store->get_status($action_id));
42 42
 	}
43 43
 
44 44
 	/* Start tests for \ActionScheduler_Store::query_actions() */
45 45
 
46 46
 	public function test_query_actions_query_type_arg_invalid_option() {
47
-		$this->expectException( InvalidArgumentException::class );
48
-		$this->get_store()->query_actions( array( 'hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ), 'invalid' );
47
+		$this->expectException(InvalidArgumentException::class);
48
+		$this->get_store()->query_actions(array('hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK), 'invalid');
49 49
 	}
50 50
 
51 51
 	public function test_query_actions_query_type_arg_valid_options() {
52 52
 		$store    = $this->get_store();
53
-		$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( 'tomorrow' ) );
53
+		$schedule = new ActionScheduler_SimpleSchedule(as_get_datetime_object('tomorrow'));
54 54
 
55
-		$action_id_1 = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule ) );
56
-		$action_id_2 = $store->save_action( new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array( 1 ), $schedule ) );
55
+		$action_id_1 = $store->save_action(new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(1), $schedule));
56
+		$action_id_2 = $store->save_action(new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(1), $schedule));
57 57
 
58
-		$this->assertEquals( array( $action_id_1, $action_id_2 ), $store->query_actions( array( 'hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ) ) );
59
-		$this->assertEquals( 2, $store->query_actions( array( 'hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ), 'count' ) );
58
+		$this->assertEquals(array($action_id_1, $action_id_2), $store->query_actions(array('hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK)));
59
+		$this->assertEquals(2, $store->query_actions(array('hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK), 'count'));
60 60
 	}
61 61
 
62 62
 	public function test_query_actions_by_single_status() {
63 63
 		$store    = $this->get_store();
64
-		$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( 'tomorrow' ) );
64
+		$schedule = new ActionScheduler_SimpleSchedule(as_get_datetime_object('tomorrow'));
65 65
 
66
-		$this->assertSame( 0, $store->query_actions( array( 'status' => ActionScheduler_Store::STATUS_PENDING ), 'count' ) );
66
+		$this->assertSame(0, $store->query_actions(array('status' => ActionScheduler_Store::STATUS_PENDING), 'count'));
67 67
 
68
-		$action_id_1 = $store->save_action( new ActionScheduler_Action( 'my_hook_1', array( 1 ), $schedule ) );
69
-		$action_id_2 = $store->save_action( new ActionScheduler_Action( 'my_hook_2', array( 1 ), $schedule ) );
70
-		$action_id_3 = $store->save_action( new ActionScheduler_Action( 'my_hook_3', array( 1 ), $schedule ) );
71
-		$store->mark_complete( $action_id_3 );
68
+		$action_id_1 = $store->save_action(new ActionScheduler_Action('my_hook_1', array(1), $schedule));
69
+		$action_id_2 = $store->save_action(new ActionScheduler_Action('my_hook_2', array(1), $schedule));
70
+		$action_id_3 = $store->save_action(new ActionScheduler_Action('my_hook_3', array(1), $schedule));
71
+		$store->mark_complete($action_id_3);
72 72
 
73
-		$this->assertEquals( 2, $store->query_actions( array( 'status' => ActionScheduler_Store::STATUS_PENDING ), 'count' ) );
74
-		$this->assertSame( 1, $store->query_actions( array( 'status' => ActionScheduler_Store::STATUS_COMPLETE ), 'count' ) );
73
+		$this->assertEquals(2, $store->query_actions(array('status' => ActionScheduler_Store::STATUS_PENDING), 'count'));
74
+		$this->assertSame(1, $store->query_actions(array('status' => ActionScheduler_Store::STATUS_COMPLETE), 'count'));
75 75
 	}
76 76
 
77 77
 	public function test_query_actions_by_array_status() {
78 78
 		$store    = $this->get_store();
79
-		$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( 'tomorrow' ) );
79
+		$schedule = new ActionScheduler_SimpleSchedule(as_get_datetime_object('tomorrow'));
80 80
 
81 81
 		$this->assertSame(
82 82
 			0,
83 83
 			$store->query_actions(
84 84
 				array(
85
-					'status' => array( ActionScheduler_Store::STATUS_PENDING, ActionScheduler_Store::STATUS_RUNNING ),
85
+					'status' => array(ActionScheduler_Store::STATUS_PENDING, ActionScheduler_Store::STATUS_RUNNING),
86 86
 				),
87 87
 				'count'
88 88
 			)
89 89
 		);
90 90
 
91
-		$action_id_1 = $store->save_action( new ActionScheduler_Action( 'my_hook_1', array( 1 ), $schedule ) );
92
-		$action_id_2 = $store->save_action( new ActionScheduler_Action( 'my_hook_2', array( 1 ), $schedule ) );
93
-		$action_id_3 = $store->save_action( new ActionScheduler_Action( 'my_hook_3', array( 1 ), $schedule ) );
94
-		$store->mark_failure( $action_id_3 );
91
+		$action_id_1 = $store->save_action(new ActionScheduler_Action('my_hook_1', array(1), $schedule));
92
+		$action_id_2 = $store->save_action(new ActionScheduler_Action('my_hook_2', array(1), $schedule));
93
+		$action_id_3 = $store->save_action(new ActionScheduler_Action('my_hook_3', array(1), $schedule));
94
+		$store->mark_failure($action_id_3);
95 95
 
96 96
 		$this->assertEquals(
97 97
 			3,
98 98
 			$store->query_actions(
99 99
 				array(
100
-					'status' => array( ActionScheduler_Store::STATUS_PENDING, ActionScheduler_Store::STATUS_FAILED ),
100
+					'status' => array(ActionScheduler_Store::STATUS_PENDING, ActionScheduler_Store::STATUS_FAILED),
101 101
 				),
102 102
 				'count'
103 103
 			)
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 			2,
107 107
 			$store->query_actions(
108 108
 				array(
109
-					'status' => array( ActionScheduler_Store::STATUS_PENDING, ActionScheduler_Store::STATUS_COMPLETE ),
109
+					'status' => array(ActionScheduler_Store::STATUS_PENDING, ActionScheduler_Store::STATUS_COMPLETE),
110 110
 				),
111 111
 				'count'
112 112
 			)
Please login to merge, or discard this patch.
tests/phpunit/jobstore/ActionScheduler_DBStoreMigrator_Test.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -7,21 +7,21 @@
 block discarded – undo
7 7
  */
8 8
 class ActionScheduler_DBStoreMigrator_Test extends ActionScheduler_UnitTestCase {
9 9
 
10
-	public function test_create_action_with_last_attempt_date() {
11
-		$scheduled_date    = as_get_datetime_object( strtotime( '-24 hours' ) );
12
-		$last_attempt_date = as_get_datetime_object( strtotime( '-23 hours' ) );
10
+    public function test_create_action_with_last_attempt_date() {
11
+        $scheduled_date    = as_get_datetime_object( strtotime( '-24 hours' ) );
12
+        $last_attempt_date = as_get_datetime_object( strtotime( '-23 hours' ) );
13 13
 
14
-		$action = new ActionScheduler_FinishedAction( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), new ActionScheduler_SimpleSchedule( $scheduled_date ) );
15
-		$store  = new ActionScheduler_DBStoreMigrator();
14
+        $action = new ActionScheduler_FinishedAction( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), new ActionScheduler_SimpleSchedule( $scheduled_date ) );
15
+        $store  = new ActionScheduler_DBStoreMigrator();
16 16
 
17
-		$action_id   = $store->save_action( $action, null, $last_attempt_date );
18
-		$action_date = $store->get_date( $action_id );
17
+        $action_id   = $store->save_action( $action, null, $last_attempt_date );
18
+        $action_date = $store->get_date( $action_id );
19 19
 
20
-		$this->assertEquals( $last_attempt_date->format( 'U' ), $action_date->format( 'U' ) );
20
+        $this->assertEquals( $last_attempt_date->format( 'U' ), $action_date->format( 'U' ) );
21 21
 
22
-		$action_id   = $store->save_action( $action, $scheduled_date, $last_attempt_date );
23
-		$action_date = $store->get_date( $action_id );
22
+        $action_id   = $store->save_action( $action, $scheduled_date, $last_attempt_date );
23
+        $action_date = $store->get_date( $action_id );
24 24
 
25
-		$this->assertEquals( $last_attempt_date->format( 'U' ), $action_date->format( 'U' ) );
26
-	}
25
+        $this->assertEquals( $last_attempt_date->format( 'U' ), $action_date->format( 'U' ) );
26
+    }
27 27
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -8,20 +8,20 @@
 block discarded – undo
8 8
 class ActionScheduler_DBStoreMigrator_Test extends ActionScheduler_UnitTestCase {
9 9
 
10 10
 	public function test_create_action_with_last_attempt_date() {
11
-		$scheduled_date    = as_get_datetime_object( strtotime( '-24 hours' ) );
12
-		$last_attempt_date = as_get_datetime_object( strtotime( '-23 hours' ) );
11
+		$scheduled_date    = as_get_datetime_object(strtotime('-24 hours'));
12
+		$last_attempt_date = as_get_datetime_object(strtotime('-23 hours'));
13 13
 
14
-		$action = new ActionScheduler_FinishedAction( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), new ActionScheduler_SimpleSchedule( $scheduled_date ) );
14
+		$action = new ActionScheduler_FinishedAction(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), new ActionScheduler_SimpleSchedule($scheduled_date));
15 15
 		$store  = new ActionScheduler_DBStoreMigrator();
16 16
 
17
-		$action_id   = $store->save_action( $action, null, $last_attempt_date );
18
-		$action_date = $store->get_date( $action_id );
17
+		$action_id   = $store->save_action($action, null, $last_attempt_date);
18
+		$action_date = $store->get_date($action_id);
19 19
 
20
-		$this->assertEquals( $last_attempt_date->format( 'U' ), $action_date->format( 'U' ) );
20
+		$this->assertEquals($last_attempt_date->format('U'), $action_date->format('U'));
21 21
 
22
-		$action_id   = $store->save_action( $action, $scheduled_date, $last_attempt_date );
23
-		$action_date = $store->get_date( $action_id );
22
+		$action_id   = $store->save_action($action, $scheduled_date, $last_attempt_date);
23
+		$action_date = $store->get_date($action_id);
24 24
 
25
-		$this->assertEquals( $last_attempt_date->format( 'U' ), $action_date->format( 'U' ) );
25
+		$this->assertEquals($last_attempt_date->format('U'), $action_date->format('U'));
26 26
 	}
27 27
 }
Please login to merge, or discard this patch.