@@ -12,265 +12,265 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | class ActionScheduler_HybridStore_Test extends ActionScheduler_UnitTestCase { |
| 15 | - private $demarkation_id = 1000; |
|
| 16 | - |
|
| 17 | - public function setUp() { |
|
| 18 | - parent::setUp(); |
|
| 19 | - if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) { |
|
| 20 | - // register the post type and taxonomy necessary for the store to work |
|
| 21 | - $store = new PostStore(); |
|
| 22 | - $store->init(); |
|
| 23 | - } |
|
| 24 | - update_option( ActionScheduler_HybridStore::DEMARKATION_OPTION, $this->demarkation_id ); |
|
| 25 | - $hybrid = new ActionScheduler_HybridStore(); |
|
| 26 | - $hybrid->set_autoincrement( '', ActionScheduler_StoreSchema::ACTIONS_TABLE ); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - public function tearDown() { |
|
| 30 | - parent::tearDown(); |
|
| 31 | - |
|
| 32 | - // reset the autoincrement index |
|
| 33 | - /** @var \wpdb $wpdb */ |
|
| 34 | - global $wpdb; |
|
| 35 | - $wpdb->query( "TRUNCATE TABLE {$wpdb->actionscheduler_actions}" ); |
|
| 36 | - $wpdb->query( "TRUNCATE TABLE {$wpdb->actionscheduler_logs}" ); |
|
| 37 | - delete_option( ActionScheduler_HybridStore::DEMARKATION_OPTION ); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - public function test_actions_are_migrated_on_find() { |
|
| 41 | - $source_store = new PostStore(); |
|
| 42 | - $destination_store = new ActionScheduler_DBStore(); |
|
| 43 | - $source_logger = new CommentLogger(); |
|
| 44 | - $destination_logger = new ActionScheduler_DBLogger(); |
|
| 45 | - |
|
| 46 | - $config = new Config(); |
|
| 47 | - $config->set_source_store( $source_store ); |
|
| 48 | - $config->set_source_logger( $source_logger ); |
|
| 49 | - $config->set_destination_store( $destination_store ); |
|
| 50 | - $config->set_destination_logger( $destination_logger ); |
|
| 51 | - |
|
| 52 | - $hybrid_store = new ActionScheduler_HybridStore( $config ); |
|
| 53 | - |
|
| 54 | - $time = as_get_datetime_object( '10 minutes ago' ); |
|
| 55 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 56 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 57 | - $source_id = $source_store->save_action( $action ); |
|
| 58 | - |
|
| 59 | - $found = $hybrid_store->find_action( __FUNCTION__, array() ); |
|
| 60 | - |
|
| 61 | - $this->assertNotEquals( $source_id, $found ); |
|
| 62 | - $this->assertGreaterThanOrEqual( $this->demarkation_id, $found ); |
|
| 63 | - |
|
| 64 | - $found_in_source = $source_store->fetch_action( $source_id ); |
|
| 65 | - $this->assertInstanceOf( NullAction::class, $found_in_source ); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function test_actions_are_migrated_on_query() { |
|
| 69 | - $source_store = new PostStore(); |
|
| 70 | - $destination_store = new ActionScheduler_DBStore(); |
|
| 71 | - $source_logger = new CommentLogger(); |
|
| 72 | - $destination_logger = new ActionScheduler_DBLogger(); |
|
| 73 | - |
|
| 74 | - $config = new Config(); |
|
| 75 | - $config->set_source_store( $source_store ); |
|
| 76 | - $config->set_source_logger( $source_logger ); |
|
| 77 | - $config->set_destination_store( $destination_store ); |
|
| 78 | - $config->set_destination_logger( $destination_logger ); |
|
| 79 | - |
|
| 80 | - $hybrid_store = new ActionScheduler_HybridStore( $config ); |
|
| 81 | - |
|
| 82 | - $source_actions = array(); |
|
| 83 | - $destination_actions = array(); |
|
| 84 | - |
|
| 85 | - for ( $i = 0; $i < 10; $i++ ) { |
|
| 86 | - // create in instance in the source store |
|
| 87 | - $time = as_get_datetime_object( ( $i * 10 + 1 ) . ' minutes' ); |
|
| 88 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 89 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 90 | - |
|
| 91 | - $source_actions[] = $source_store->save_action( $action ); |
|
| 92 | - |
|
| 93 | - // create an instance in the destination store |
|
| 94 | - $time = as_get_datetime_object( ( $i * 10 + 5 ) . ' minutes' ); |
|
| 95 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 96 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 97 | - |
|
| 98 | - $destination_actions[] = $destination_store->save_action( $action ); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - $found = $hybrid_store->query_actions( |
|
| 102 | - array( |
|
| 103 | - 'hook' => __FUNCTION__, |
|
| 104 | - 'per_page' => 6, |
|
| 105 | - ) |
|
| 106 | - ); |
|
| 107 | - |
|
| 108 | - $this->assertCount( 6, $found ); |
|
| 109 | - foreach ( $found as $key => $action_id ) { |
|
| 110 | - $this->assertNotContains( $action_id, $source_actions ); |
|
| 111 | - $this->assertGreaterThanOrEqual( $this->demarkation_id, $action_id ); |
|
| 112 | - if ( $key % 2 == 0 ) { // it should have been in the source store |
|
| 113 | - $this->assertNotContains( $action_id, $destination_actions ); |
|
| 114 | - } else { // it should have already been in the destination store |
|
| 115 | - $this->assertContains( $action_id, $destination_actions ); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // six of the original 10 should have migrated to the new store |
|
| 120 | - // even though only three were retrieve in the final query |
|
| 121 | - $found_in_source = $source_store->query_actions( |
|
| 122 | - array( |
|
| 123 | - 'hook' => __FUNCTION__, |
|
| 124 | - 'per_page' => 10, |
|
| 125 | - ) |
|
| 126 | - ); |
|
| 127 | - $this->assertCount( 4, $found_in_source ); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - public function test_actions_are_migrated_on_claim() { |
|
| 131 | - $source_store = new PostStore(); |
|
| 132 | - $destination_store = new ActionScheduler_DBStore(); |
|
| 133 | - $source_logger = new CommentLogger(); |
|
| 134 | - $destination_logger = new ActionScheduler_DBLogger(); |
|
| 135 | - |
|
| 136 | - $config = new Config(); |
|
| 137 | - $config->set_source_store( $source_store ); |
|
| 138 | - $config->set_source_logger( $source_logger ); |
|
| 139 | - $config->set_destination_store( $destination_store ); |
|
| 140 | - $config->set_destination_logger( $destination_logger ); |
|
| 141 | - |
|
| 142 | - $hybrid_store = new ActionScheduler_HybridStore( $config ); |
|
| 143 | - |
|
| 144 | - $source_actions = array(); |
|
| 145 | - $destination_actions = array(); |
|
| 146 | - |
|
| 147 | - for ( $i = 0; $i < 10; $i++ ) { |
|
| 148 | - // create in instance in the source store |
|
| 149 | - $time = as_get_datetime_object( ( $i * 10 + 1 ) . ' minutes ago' ); |
|
| 150 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 151 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 152 | - |
|
| 153 | - $source_actions[] = $source_store->save_action( $action ); |
|
| 154 | - |
|
| 155 | - // create an instance in the destination store |
|
| 156 | - $time = as_get_datetime_object( ( $i * 10 + 5 ) . ' minutes ago' ); |
|
| 157 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 158 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 159 | - |
|
| 160 | - $destination_actions[] = $destination_store->save_action( $action ); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - $claim = $hybrid_store->stake_claim( 6 ); |
|
| 164 | - |
|
| 165 | - $claimed_actions = $claim->get_actions(); |
|
| 166 | - $this->assertCount( 6, $claimed_actions ); |
|
| 167 | - $this->assertCount( 3, array_intersect( $destination_actions, $claimed_actions ) ); |
|
| 168 | - |
|
| 169 | - // six of the original 10 should have migrated to the new store |
|
| 170 | - // even though only three were retrieve in the final claim |
|
| 171 | - $found_in_source = $source_store->query_actions( |
|
| 172 | - array( |
|
| 173 | - 'hook' => __FUNCTION__, |
|
| 174 | - 'per_page' => 10, |
|
| 175 | - ) |
|
| 176 | - ); |
|
| 177 | - $this->assertCount( 4, $found_in_source ); |
|
| 178 | - |
|
| 179 | - $this->assertSame( 0, $source_store->get_claim_count() ); |
|
| 180 | - $this->assertSame( 1, $destination_store->get_claim_count() ); |
|
| 181 | - $this->assertSame( 1, $hybrid_store->get_claim_count() ); |
|
| 182 | - |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - public function test_fetch_respects_demarkation() { |
|
| 186 | - $source_store = new PostStore(); |
|
| 187 | - $destination_store = new ActionScheduler_DBStore(); |
|
| 188 | - $source_logger = new CommentLogger(); |
|
| 189 | - $destination_logger = new ActionScheduler_DBLogger(); |
|
| 190 | - |
|
| 191 | - $config = new Config(); |
|
| 192 | - $config->set_source_store( $source_store ); |
|
| 193 | - $config->set_source_logger( $source_logger ); |
|
| 194 | - $config->set_destination_store( $destination_store ); |
|
| 195 | - $config->set_destination_logger( $destination_logger ); |
|
| 196 | - |
|
| 197 | - $hybrid_store = new ActionScheduler_HybridStore( $config ); |
|
| 198 | - |
|
| 199 | - $source_actions = array(); |
|
| 200 | - $destination_actions = array(); |
|
| 201 | - |
|
| 202 | - for ( $i = 0; $i < 2; $i++ ) { |
|
| 203 | - // create in instance in the source store |
|
| 204 | - $time = as_get_datetime_object( ( $i * 10 + 1 ) . ' minutes ago' ); |
|
| 205 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 206 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 207 | - |
|
| 208 | - $source_actions[] = $source_store->save_action( $action ); |
|
| 209 | - |
|
| 210 | - // create an instance in the destination store |
|
| 211 | - $time = as_get_datetime_object( ( $i * 10 + 5 ) . ' minutes ago' ); |
|
| 212 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 213 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 214 | - |
|
| 215 | - $destination_actions[] = $destination_store->save_action( $action ); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - foreach ( $source_actions as $action_id ) { |
|
| 219 | - $action = $hybrid_store->fetch_action( $action_id ); |
|
| 220 | - $this->assertInstanceOf( ActionScheduler_Action::class, $action ); |
|
| 221 | - $this->assertNotInstanceOf( NullAction::class, $action ); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - foreach ( $destination_actions as $action_id ) { |
|
| 225 | - $action = $hybrid_store->fetch_action( $action_id ); |
|
| 226 | - $this->assertInstanceOf( ActionScheduler_Action::class, $action ); |
|
| 227 | - $this->assertNotInstanceOf( NullAction::class, $action ); |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - public function test_mark_complete_respects_demarkation() { |
|
| 232 | - $source_store = new PostStore(); |
|
| 233 | - $destination_store = new ActionScheduler_DBStore(); |
|
| 234 | - $source_logger = new CommentLogger(); |
|
| 235 | - $destination_logger = new ActionScheduler_DBLogger(); |
|
| 236 | - |
|
| 237 | - $config = new Config(); |
|
| 238 | - $config->set_source_store( $source_store ); |
|
| 239 | - $config->set_source_logger( $source_logger ); |
|
| 240 | - $config->set_destination_store( $destination_store ); |
|
| 241 | - $config->set_destination_logger( $destination_logger ); |
|
| 242 | - |
|
| 243 | - $hybrid_store = new ActionScheduler_HybridStore( $config ); |
|
| 244 | - |
|
| 245 | - $source_actions = array(); |
|
| 246 | - $destination_actions = array(); |
|
| 247 | - |
|
| 248 | - for ( $i = 0; $i < 2; $i++ ) { |
|
| 249 | - // create in instance in the source store |
|
| 250 | - $time = as_get_datetime_object( ( $i * 10 + 1 ) . ' minutes ago' ); |
|
| 251 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 252 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 253 | - |
|
| 254 | - $source_actions[] = $source_store->save_action( $action ); |
|
| 255 | - |
|
| 256 | - // create an instance in the destination store |
|
| 257 | - $time = as_get_datetime_object( ( $i * 10 + 5 ) . ' minutes ago' ); |
|
| 258 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 259 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 260 | - |
|
| 261 | - $destination_actions[] = $destination_store->save_action( $action ); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - foreach ( $source_actions as $action_id ) { |
|
| 265 | - $hybrid_store->mark_complete( $action_id ); |
|
| 266 | - $action = $hybrid_store->fetch_action( $action_id ); |
|
| 267 | - $this->assertInstanceOf( ActionScheduler_FinishedAction::class, $action ); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - foreach ( $destination_actions as $action_id ) { |
|
| 271 | - $hybrid_store->mark_complete( $action_id ); |
|
| 272 | - $action = $hybrid_store->fetch_action( $action_id ); |
|
| 273 | - $this->assertInstanceOf( ActionScheduler_FinishedAction::class, $action ); |
|
| 274 | - } |
|
| 275 | - } |
|
| 15 | + private $demarkation_id = 1000; |
|
| 16 | + |
|
| 17 | + public function setUp() { |
|
| 18 | + parent::setUp(); |
|
| 19 | + if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) { |
|
| 20 | + // register the post type and taxonomy necessary for the store to work |
|
| 21 | + $store = new PostStore(); |
|
| 22 | + $store->init(); |
|
| 23 | + } |
|
| 24 | + update_option( ActionScheduler_HybridStore::DEMARKATION_OPTION, $this->demarkation_id ); |
|
| 25 | + $hybrid = new ActionScheduler_HybridStore(); |
|
| 26 | + $hybrid->set_autoincrement( '', ActionScheduler_StoreSchema::ACTIONS_TABLE ); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + public function tearDown() { |
|
| 30 | + parent::tearDown(); |
|
| 31 | + |
|
| 32 | + // reset the autoincrement index |
|
| 33 | + /** @var \wpdb $wpdb */ |
|
| 34 | + global $wpdb; |
|
| 35 | + $wpdb->query( "TRUNCATE TABLE {$wpdb->actionscheduler_actions}" ); |
|
| 36 | + $wpdb->query( "TRUNCATE TABLE {$wpdb->actionscheduler_logs}" ); |
|
| 37 | + delete_option( ActionScheduler_HybridStore::DEMARKATION_OPTION ); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + public function test_actions_are_migrated_on_find() { |
|
| 41 | + $source_store = new PostStore(); |
|
| 42 | + $destination_store = new ActionScheduler_DBStore(); |
|
| 43 | + $source_logger = new CommentLogger(); |
|
| 44 | + $destination_logger = new ActionScheduler_DBLogger(); |
|
| 45 | + |
|
| 46 | + $config = new Config(); |
|
| 47 | + $config->set_source_store( $source_store ); |
|
| 48 | + $config->set_source_logger( $source_logger ); |
|
| 49 | + $config->set_destination_store( $destination_store ); |
|
| 50 | + $config->set_destination_logger( $destination_logger ); |
|
| 51 | + |
|
| 52 | + $hybrid_store = new ActionScheduler_HybridStore( $config ); |
|
| 53 | + |
|
| 54 | + $time = as_get_datetime_object( '10 minutes ago' ); |
|
| 55 | + $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 56 | + $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 57 | + $source_id = $source_store->save_action( $action ); |
|
| 58 | + |
|
| 59 | + $found = $hybrid_store->find_action( __FUNCTION__, array() ); |
|
| 60 | + |
|
| 61 | + $this->assertNotEquals( $source_id, $found ); |
|
| 62 | + $this->assertGreaterThanOrEqual( $this->demarkation_id, $found ); |
|
| 63 | + |
|
| 64 | + $found_in_source = $source_store->fetch_action( $source_id ); |
|
| 65 | + $this->assertInstanceOf( NullAction::class, $found_in_source ); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function test_actions_are_migrated_on_query() { |
|
| 69 | + $source_store = new PostStore(); |
|
| 70 | + $destination_store = new ActionScheduler_DBStore(); |
|
| 71 | + $source_logger = new CommentLogger(); |
|
| 72 | + $destination_logger = new ActionScheduler_DBLogger(); |
|
| 73 | + |
|
| 74 | + $config = new Config(); |
|
| 75 | + $config->set_source_store( $source_store ); |
|
| 76 | + $config->set_source_logger( $source_logger ); |
|
| 77 | + $config->set_destination_store( $destination_store ); |
|
| 78 | + $config->set_destination_logger( $destination_logger ); |
|
| 79 | + |
|
| 80 | + $hybrid_store = new ActionScheduler_HybridStore( $config ); |
|
| 81 | + |
|
| 82 | + $source_actions = array(); |
|
| 83 | + $destination_actions = array(); |
|
| 84 | + |
|
| 85 | + for ( $i = 0; $i < 10; $i++ ) { |
|
| 86 | + // create in instance in the source store |
|
| 87 | + $time = as_get_datetime_object( ( $i * 10 + 1 ) . ' minutes' ); |
|
| 88 | + $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 89 | + $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 90 | + |
|
| 91 | + $source_actions[] = $source_store->save_action( $action ); |
|
| 92 | + |
|
| 93 | + // create an instance in the destination store |
|
| 94 | + $time = as_get_datetime_object( ( $i * 10 + 5 ) . ' minutes' ); |
|
| 95 | + $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 96 | + $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 97 | + |
|
| 98 | + $destination_actions[] = $destination_store->save_action( $action ); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + $found = $hybrid_store->query_actions( |
|
| 102 | + array( |
|
| 103 | + 'hook' => __FUNCTION__, |
|
| 104 | + 'per_page' => 6, |
|
| 105 | + ) |
|
| 106 | + ); |
|
| 107 | + |
|
| 108 | + $this->assertCount( 6, $found ); |
|
| 109 | + foreach ( $found as $key => $action_id ) { |
|
| 110 | + $this->assertNotContains( $action_id, $source_actions ); |
|
| 111 | + $this->assertGreaterThanOrEqual( $this->demarkation_id, $action_id ); |
|
| 112 | + if ( $key % 2 == 0 ) { // it should have been in the source store |
|
| 113 | + $this->assertNotContains( $action_id, $destination_actions ); |
|
| 114 | + } else { // it should have already been in the destination store |
|
| 115 | + $this->assertContains( $action_id, $destination_actions ); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // six of the original 10 should have migrated to the new store |
|
| 120 | + // even though only three were retrieve in the final query |
|
| 121 | + $found_in_source = $source_store->query_actions( |
|
| 122 | + array( |
|
| 123 | + 'hook' => __FUNCTION__, |
|
| 124 | + 'per_page' => 10, |
|
| 125 | + ) |
|
| 126 | + ); |
|
| 127 | + $this->assertCount( 4, $found_in_source ); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + public function test_actions_are_migrated_on_claim() { |
|
| 131 | + $source_store = new PostStore(); |
|
| 132 | + $destination_store = new ActionScheduler_DBStore(); |
|
| 133 | + $source_logger = new CommentLogger(); |
|
| 134 | + $destination_logger = new ActionScheduler_DBLogger(); |
|
| 135 | + |
|
| 136 | + $config = new Config(); |
|
| 137 | + $config->set_source_store( $source_store ); |
|
| 138 | + $config->set_source_logger( $source_logger ); |
|
| 139 | + $config->set_destination_store( $destination_store ); |
|
| 140 | + $config->set_destination_logger( $destination_logger ); |
|
| 141 | + |
|
| 142 | + $hybrid_store = new ActionScheduler_HybridStore( $config ); |
|
| 143 | + |
|
| 144 | + $source_actions = array(); |
|
| 145 | + $destination_actions = array(); |
|
| 146 | + |
|
| 147 | + for ( $i = 0; $i < 10; $i++ ) { |
|
| 148 | + // create in instance in the source store |
|
| 149 | + $time = as_get_datetime_object( ( $i * 10 + 1 ) . ' minutes ago' ); |
|
| 150 | + $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 151 | + $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 152 | + |
|
| 153 | + $source_actions[] = $source_store->save_action( $action ); |
|
| 154 | + |
|
| 155 | + // create an instance in the destination store |
|
| 156 | + $time = as_get_datetime_object( ( $i * 10 + 5 ) . ' minutes ago' ); |
|
| 157 | + $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 158 | + $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 159 | + |
|
| 160 | + $destination_actions[] = $destination_store->save_action( $action ); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + $claim = $hybrid_store->stake_claim( 6 ); |
|
| 164 | + |
|
| 165 | + $claimed_actions = $claim->get_actions(); |
|
| 166 | + $this->assertCount( 6, $claimed_actions ); |
|
| 167 | + $this->assertCount( 3, array_intersect( $destination_actions, $claimed_actions ) ); |
|
| 168 | + |
|
| 169 | + // six of the original 10 should have migrated to the new store |
|
| 170 | + // even though only three were retrieve in the final claim |
|
| 171 | + $found_in_source = $source_store->query_actions( |
|
| 172 | + array( |
|
| 173 | + 'hook' => __FUNCTION__, |
|
| 174 | + 'per_page' => 10, |
|
| 175 | + ) |
|
| 176 | + ); |
|
| 177 | + $this->assertCount( 4, $found_in_source ); |
|
| 178 | + |
|
| 179 | + $this->assertSame( 0, $source_store->get_claim_count() ); |
|
| 180 | + $this->assertSame( 1, $destination_store->get_claim_count() ); |
|
| 181 | + $this->assertSame( 1, $hybrid_store->get_claim_count() ); |
|
| 182 | + |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + public function test_fetch_respects_demarkation() { |
|
| 186 | + $source_store = new PostStore(); |
|
| 187 | + $destination_store = new ActionScheduler_DBStore(); |
|
| 188 | + $source_logger = new CommentLogger(); |
|
| 189 | + $destination_logger = new ActionScheduler_DBLogger(); |
|
| 190 | + |
|
| 191 | + $config = new Config(); |
|
| 192 | + $config->set_source_store( $source_store ); |
|
| 193 | + $config->set_source_logger( $source_logger ); |
|
| 194 | + $config->set_destination_store( $destination_store ); |
|
| 195 | + $config->set_destination_logger( $destination_logger ); |
|
| 196 | + |
|
| 197 | + $hybrid_store = new ActionScheduler_HybridStore( $config ); |
|
| 198 | + |
|
| 199 | + $source_actions = array(); |
|
| 200 | + $destination_actions = array(); |
|
| 201 | + |
|
| 202 | + for ( $i = 0; $i < 2; $i++ ) { |
|
| 203 | + // create in instance in the source store |
|
| 204 | + $time = as_get_datetime_object( ( $i * 10 + 1 ) . ' minutes ago' ); |
|
| 205 | + $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 206 | + $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 207 | + |
|
| 208 | + $source_actions[] = $source_store->save_action( $action ); |
|
| 209 | + |
|
| 210 | + // create an instance in the destination store |
|
| 211 | + $time = as_get_datetime_object( ( $i * 10 + 5 ) . ' minutes ago' ); |
|
| 212 | + $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 213 | + $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 214 | + |
|
| 215 | + $destination_actions[] = $destination_store->save_action( $action ); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + foreach ( $source_actions as $action_id ) { |
|
| 219 | + $action = $hybrid_store->fetch_action( $action_id ); |
|
| 220 | + $this->assertInstanceOf( ActionScheduler_Action::class, $action ); |
|
| 221 | + $this->assertNotInstanceOf( NullAction::class, $action ); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + foreach ( $destination_actions as $action_id ) { |
|
| 225 | + $action = $hybrid_store->fetch_action( $action_id ); |
|
| 226 | + $this->assertInstanceOf( ActionScheduler_Action::class, $action ); |
|
| 227 | + $this->assertNotInstanceOf( NullAction::class, $action ); |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + public function test_mark_complete_respects_demarkation() { |
|
| 232 | + $source_store = new PostStore(); |
|
| 233 | + $destination_store = new ActionScheduler_DBStore(); |
|
| 234 | + $source_logger = new CommentLogger(); |
|
| 235 | + $destination_logger = new ActionScheduler_DBLogger(); |
|
| 236 | + |
|
| 237 | + $config = new Config(); |
|
| 238 | + $config->set_source_store( $source_store ); |
|
| 239 | + $config->set_source_logger( $source_logger ); |
|
| 240 | + $config->set_destination_store( $destination_store ); |
|
| 241 | + $config->set_destination_logger( $destination_logger ); |
|
| 242 | + |
|
| 243 | + $hybrid_store = new ActionScheduler_HybridStore( $config ); |
|
| 244 | + |
|
| 245 | + $source_actions = array(); |
|
| 246 | + $destination_actions = array(); |
|
| 247 | + |
|
| 248 | + for ( $i = 0; $i < 2; $i++ ) { |
|
| 249 | + // create in instance in the source store |
|
| 250 | + $time = as_get_datetime_object( ( $i * 10 + 1 ) . ' minutes ago' ); |
|
| 251 | + $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 252 | + $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 253 | + |
|
| 254 | + $source_actions[] = $source_store->save_action( $action ); |
|
| 255 | + |
|
| 256 | + // create an instance in the destination store |
|
| 257 | + $time = as_get_datetime_object( ( $i * 10 + 5 ) . ' minutes ago' ); |
|
| 258 | + $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 259 | + $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 260 | + |
|
| 261 | + $destination_actions[] = $destination_store->save_action( $action ); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + foreach ( $source_actions as $action_id ) { |
|
| 265 | + $hybrid_store->mark_complete( $action_id ); |
|
| 266 | + $action = $hybrid_store->fetch_action( $action_id ); |
|
| 267 | + $this->assertInstanceOf( ActionScheduler_FinishedAction::class, $action ); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + foreach ( $destination_actions as $action_id ) { |
|
| 271 | + $hybrid_store->mark_complete( $action_id ); |
|
| 272 | + $action = $hybrid_store->fetch_action( $action_id ); |
|
| 273 | + $this->assertInstanceOf( ActionScheduler_FinishedAction::class, $action ); |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | 276 | } |
@@ -16,14 +16,14 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | public function setUp() { |
| 18 | 18 | parent::setUp(); |
| 19 | - if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) { |
|
| 19 | + if ( ! taxonomy_exists(PostStore::GROUP_TAXONOMY)) { |
|
| 20 | 20 | // register the post type and taxonomy necessary for the store to work |
| 21 | 21 | $store = new PostStore(); |
| 22 | 22 | $store->init(); |
| 23 | 23 | } |
| 24 | - update_option( ActionScheduler_HybridStore::DEMARKATION_OPTION, $this->demarkation_id ); |
|
| 24 | + update_option(ActionScheduler_HybridStore::DEMARKATION_OPTION, $this->demarkation_id); |
|
| 25 | 25 | $hybrid = new ActionScheduler_HybridStore(); |
| 26 | - $hybrid->set_autoincrement( '', ActionScheduler_StoreSchema::ACTIONS_TABLE ); |
|
| 26 | + $hybrid->set_autoincrement('', ActionScheduler_StoreSchema::ACTIONS_TABLE); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | public function tearDown() { |
@@ -32,9 +32,9 @@ discard block |
||
| 32 | 32 | // reset the autoincrement index |
| 33 | 33 | /** @var \wpdb $wpdb */ |
| 34 | 34 | global $wpdb; |
| 35 | - $wpdb->query( "TRUNCATE TABLE {$wpdb->actionscheduler_actions}" ); |
|
| 36 | - $wpdb->query( "TRUNCATE TABLE {$wpdb->actionscheduler_logs}" ); |
|
| 37 | - delete_option( ActionScheduler_HybridStore::DEMARKATION_OPTION ); |
|
| 35 | + $wpdb->query("TRUNCATE TABLE {$wpdb->actionscheduler_actions}"); |
|
| 36 | + $wpdb->query("TRUNCATE TABLE {$wpdb->actionscheduler_logs}"); |
|
| 37 | + delete_option(ActionScheduler_HybridStore::DEMARKATION_OPTION); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | public function test_actions_are_migrated_on_find() { |
@@ -44,25 +44,25 @@ discard block |
||
| 44 | 44 | $destination_logger = new ActionScheduler_DBLogger(); |
| 45 | 45 | |
| 46 | 46 | $config = new Config(); |
| 47 | - $config->set_source_store( $source_store ); |
|
| 48 | - $config->set_source_logger( $source_logger ); |
|
| 49 | - $config->set_destination_store( $destination_store ); |
|
| 50 | - $config->set_destination_logger( $destination_logger ); |
|
| 47 | + $config->set_source_store($source_store); |
|
| 48 | + $config->set_source_logger($source_logger); |
|
| 49 | + $config->set_destination_store($destination_store); |
|
| 50 | + $config->set_destination_logger($destination_logger); |
|
| 51 | 51 | |
| 52 | - $hybrid_store = new ActionScheduler_HybridStore( $config ); |
|
| 52 | + $hybrid_store = new ActionScheduler_HybridStore($config); |
|
| 53 | 53 | |
| 54 | - $time = as_get_datetime_object( '10 minutes ago' ); |
|
| 55 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 56 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 57 | - $source_id = $source_store->save_action( $action ); |
|
| 54 | + $time = as_get_datetime_object('10 minutes ago'); |
|
| 55 | + $schedule = new ActionScheduler_SimpleSchedule($time); |
|
| 56 | + $action = new ActionScheduler_Action(__FUNCTION__, array(), $schedule); |
|
| 57 | + $source_id = $source_store->save_action($action); |
|
| 58 | 58 | |
| 59 | - $found = $hybrid_store->find_action( __FUNCTION__, array() ); |
|
| 59 | + $found = $hybrid_store->find_action(__FUNCTION__, array()); |
|
| 60 | 60 | |
| 61 | - $this->assertNotEquals( $source_id, $found ); |
|
| 62 | - $this->assertGreaterThanOrEqual( $this->demarkation_id, $found ); |
|
| 61 | + $this->assertNotEquals($source_id, $found); |
|
| 62 | + $this->assertGreaterThanOrEqual($this->demarkation_id, $found); |
|
| 63 | 63 | |
| 64 | - $found_in_source = $source_store->fetch_action( $source_id ); |
|
| 65 | - $this->assertInstanceOf( NullAction::class, $found_in_source ); |
|
| 64 | + $found_in_source = $source_store->fetch_action($source_id); |
|
| 65 | + $this->assertInstanceOf(NullAction::class, $found_in_source); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | public function test_actions_are_migrated_on_query() { |
@@ -72,30 +72,30 @@ discard block |
||
| 72 | 72 | $destination_logger = new ActionScheduler_DBLogger(); |
| 73 | 73 | |
| 74 | 74 | $config = new Config(); |
| 75 | - $config->set_source_store( $source_store ); |
|
| 76 | - $config->set_source_logger( $source_logger ); |
|
| 77 | - $config->set_destination_store( $destination_store ); |
|
| 78 | - $config->set_destination_logger( $destination_logger ); |
|
| 75 | + $config->set_source_store($source_store); |
|
| 76 | + $config->set_source_logger($source_logger); |
|
| 77 | + $config->set_destination_store($destination_store); |
|
| 78 | + $config->set_destination_logger($destination_logger); |
|
| 79 | 79 | |
| 80 | - $hybrid_store = new ActionScheduler_HybridStore( $config ); |
|
| 80 | + $hybrid_store = new ActionScheduler_HybridStore($config); |
|
| 81 | 81 | |
| 82 | 82 | $source_actions = array(); |
| 83 | 83 | $destination_actions = array(); |
| 84 | 84 | |
| 85 | - for ( $i = 0; $i < 10; $i++ ) { |
|
| 85 | + for ($i = 0; $i < 10; $i++) { |
|
| 86 | 86 | // create in instance in the source store |
| 87 | - $time = as_get_datetime_object( ( $i * 10 + 1 ) . ' minutes' ); |
|
| 88 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 89 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 87 | + $time = as_get_datetime_object(($i * 10 + 1).' minutes'); |
|
| 88 | + $schedule = new ActionScheduler_SimpleSchedule($time); |
|
| 89 | + $action = new ActionScheduler_Action(__FUNCTION__, array(), $schedule); |
|
| 90 | 90 | |
| 91 | - $source_actions[] = $source_store->save_action( $action ); |
|
| 91 | + $source_actions[] = $source_store->save_action($action); |
|
| 92 | 92 | |
| 93 | 93 | // create an instance in the destination store |
| 94 | - $time = as_get_datetime_object( ( $i * 10 + 5 ) . ' minutes' ); |
|
| 95 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 96 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 94 | + $time = as_get_datetime_object(($i * 10 + 5).' minutes'); |
|
| 95 | + $schedule = new ActionScheduler_SimpleSchedule($time); |
|
| 96 | + $action = new ActionScheduler_Action(__FUNCTION__, array(), $schedule); |
|
| 97 | 97 | |
| 98 | - $destination_actions[] = $destination_store->save_action( $action ); |
|
| 98 | + $destination_actions[] = $destination_store->save_action($action); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | $found = $hybrid_store->query_actions( |
@@ -105,14 +105,14 @@ discard block |
||
| 105 | 105 | ) |
| 106 | 106 | ); |
| 107 | 107 | |
| 108 | - $this->assertCount( 6, $found ); |
|
| 109 | - foreach ( $found as $key => $action_id ) { |
|
| 110 | - $this->assertNotContains( $action_id, $source_actions ); |
|
| 111 | - $this->assertGreaterThanOrEqual( $this->demarkation_id, $action_id ); |
|
| 112 | - if ( $key % 2 == 0 ) { // it should have been in the source store |
|
| 113 | - $this->assertNotContains( $action_id, $destination_actions ); |
|
| 108 | + $this->assertCount(6, $found); |
|
| 109 | + foreach ($found as $key => $action_id) { |
|
| 110 | + $this->assertNotContains($action_id, $source_actions); |
|
| 111 | + $this->assertGreaterThanOrEqual($this->demarkation_id, $action_id); |
|
| 112 | + if ($key % 2 == 0) { // it should have been in the source store |
|
| 113 | + $this->assertNotContains($action_id, $destination_actions); |
|
| 114 | 114 | } else { // it should have already been in the destination store |
| 115 | - $this->assertContains( $action_id, $destination_actions ); |
|
| 115 | + $this->assertContains($action_id, $destination_actions); |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | 'per_page' => 10, |
| 125 | 125 | ) |
| 126 | 126 | ); |
| 127 | - $this->assertCount( 4, $found_in_source ); |
|
| 127 | + $this->assertCount(4, $found_in_source); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | public function test_actions_are_migrated_on_claim() { |
@@ -134,37 +134,37 @@ discard block |
||
| 134 | 134 | $destination_logger = new ActionScheduler_DBLogger(); |
| 135 | 135 | |
| 136 | 136 | $config = new Config(); |
| 137 | - $config->set_source_store( $source_store ); |
|
| 138 | - $config->set_source_logger( $source_logger ); |
|
| 139 | - $config->set_destination_store( $destination_store ); |
|
| 140 | - $config->set_destination_logger( $destination_logger ); |
|
| 137 | + $config->set_source_store($source_store); |
|
| 138 | + $config->set_source_logger($source_logger); |
|
| 139 | + $config->set_destination_store($destination_store); |
|
| 140 | + $config->set_destination_logger($destination_logger); |
|
| 141 | 141 | |
| 142 | - $hybrid_store = new ActionScheduler_HybridStore( $config ); |
|
| 142 | + $hybrid_store = new ActionScheduler_HybridStore($config); |
|
| 143 | 143 | |
| 144 | 144 | $source_actions = array(); |
| 145 | 145 | $destination_actions = array(); |
| 146 | 146 | |
| 147 | - for ( $i = 0; $i < 10; $i++ ) { |
|
| 147 | + for ($i = 0; $i < 10; $i++) { |
|
| 148 | 148 | // create in instance in the source store |
| 149 | - $time = as_get_datetime_object( ( $i * 10 + 1 ) . ' minutes ago' ); |
|
| 150 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 151 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 149 | + $time = as_get_datetime_object(($i * 10 + 1).' minutes ago'); |
|
| 150 | + $schedule = new ActionScheduler_SimpleSchedule($time); |
|
| 151 | + $action = new ActionScheduler_Action(__FUNCTION__, array(), $schedule); |
|
| 152 | 152 | |
| 153 | - $source_actions[] = $source_store->save_action( $action ); |
|
| 153 | + $source_actions[] = $source_store->save_action($action); |
|
| 154 | 154 | |
| 155 | 155 | // create an instance in the destination store |
| 156 | - $time = as_get_datetime_object( ( $i * 10 + 5 ) . ' minutes ago' ); |
|
| 157 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 158 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 156 | + $time = as_get_datetime_object(($i * 10 + 5).' minutes ago'); |
|
| 157 | + $schedule = new ActionScheduler_SimpleSchedule($time); |
|
| 158 | + $action = new ActionScheduler_Action(__FUNCTION__, array(), $schedule); |
|
| 159 | 159 | |
| 160 | - $destination_actions[] = $destination_store->save_action( $action ); |
|
| 160 | + $destination_actions[] = $destination_store->save_action($action); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - $claim = $hybrid_store->stake_claim( 6 ); |
|
| 163 | + $claim = $hybrid_store->stake_claim(6); |
|
| 164 | 164 | |
| 165 | 165 | $claimed_actions = $claim->get_actions(); |
| 166 | - $this->assertCount( 6, $claimed_actions ); |
|
| 167 | - $this->assertCount( 3, array_intersect( $destination_actions, $claimed_actions ) ); |
|
| 166 | + $this->assertCount(6, $claimed_actions); |
|
| 167 | + $this->assertCount(3, array_intersect($destination_actions, $claimed_actions)); |
|
| 168 | 168 | |
| 169 | 169 | // six of the original 10 should have migrated to the new store |
| 170 | 170 | // even though only three were retrieve in the final claim |
@@ -174,11 +174,11 @@ discard block |
||
| 174 | 174 | 'per_page' => 10, |
| 175 | 175 | ) |
| 176 | 176 | ); |
| 177 | - $this->assertCount( 4, $found_in_source ); |
|
| 177 | + $this->assertCount(4, $found_in_source); |
|
| 178 | 178 | |
| 179 | - $this->assertSame( 0, $source_store->get_claim_count() ); |
|
| 180 | - $this->assertSame( 1, $destination_store->get_claim_count() ); |
|
| 181 | - $this->assertSame( 1, $hybrid_store->get_claim_count() ); |
|
| 179 | + $this->assertSame(0, $source_store->get_claim_count()); |
|
| 180 | + $this->assertSame(1, $destination_store->get_claim_count()); |
|
| 181 | + $this->assertSame(1, $hybrid_store->get_claim_count()); |
|
| 182 | 182 | |
| 183 | 183 | } |
| 184 | 184 | |
@@ -189,42 +189,42 @@ discard block |
||
| 189 | 189 | $destination_logger = new ActionScheduler_DBLogger(); |
| 190 | 190 | |
| 191 | 191 | $config = new Config(); |
| 192 | - $config->set_source_store( $source_store ); |
|
| 193 | - $config->set_source_logger( $source_logger ); |
|
| 194 | - $config->set_destination_store( $destination_store ); |
|
| 195 | - $config->set_destination_logger( $destination_logger ); |
|
| 192 | + $config->set_source_store($source_store); |
|
| 193 | + $config->set_source_logger($source_logger); |
|
| 194 | + $config->set_destination_store($destination_store); |
|
| 195 | + $config->set_destination_logger($destination_logger); |
|
| 196 | 196 | |
| 197 | - $hybrid_store = new ActionScheduler_HybridStore( $config ); |
|
| 197 | + $hybrid_store = new ActionScheduler_HybridStore($config); |
|
| 198 | 198 | |
| 199 | 199 | $source_actions = array(); |
| 200 | 200 | $destination_actions = array(); |
| 201 | 201 | |
| 202 | - for ( $i = 0; $i < 2; $i++ ) { |
|
| 202 | + for ($i = 0; $i < 2; $i++) { |
|
| 203 | 203 | // create in instance in the source store |
| 204 | - $time = as_get_datetime_object( ( $i * 10 + 1 ) . ' minutes ago' ); |
|
| 205 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 206 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 204 | + $time = as_get_datetime_object(($i * 10 + 1).' minutes ago'); |
|
| 205 | + $schedule = new ActionScheduler_SimpleSchedule($time); |
|
| 206 | + $action = new ActionScheduler_Action(__FUNCTION__, array(), $schedule); |
|
| 207 | 207 | |
| 208 | - $source_actions[] = $source_store->save_action( $action ); |
|
| 208 | + $source_actions[] = $source_store->save_action($action); |
|
| 209 | 209 | |
| 210 | 210 | // create an instance in the destination store |
| 211 | - $time = as_get_datetime_object( ( $i * 10 + 5 ) . ' minutes ago' ); |
|
| 212 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 213 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 211 | + $time = as_get_datetime_object(($i * 10 + 5).' minutes ago'); |
|
| 212 | + $schedule = new ActionScheduler_SimpleSchedule($time); |
|
| 213 | + $action = new ActionScheduler_Action(__FUNCTION__, array(), $schedule); |
|
| 214 | 214 | |
| 215 | - $destination_actions[] = $destination_store->save_action( $action ); |
|
| 215 | + $destination_actions[] = $destination_store->save_action($action); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - foreach ( $source_actions as $action_id ) { |
|
| 219 | - $action = $hybrid_store->fetch_action( $action_id ); |
|
| 220 | - $this->assertInstanceOf( ActionScheduler_Action::class, $action ); |
|
| 221 | - $this->assertNotInstanceOf( NullAction::class, $action ); |
|
| 218 | + foreach ($source_actions as $action_id) { |
|
| 219 | + $action = $hybrid_store->fetch_action($action_id); |
|
| 220 | + $this->assertInstanceOf(ActionScheduler_Action::class, $action); |
|
| 221 | + $this->assertNotInstanceOf(NullAction::class, $action); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - foreach ( $destination_actions as $action_id ) { |
|
| 225 | - $action = $hybrid_store->fetch_action( $action_id ); |
|
| 226 | - $this->assertInstanceOf( ActionScheduler_Action::class, $action ); |
|
| 227 | - $this->assertNotInstanceOf( NullAction::class, $action ); |
|
| 224 | + foreach ($destination_actions as $action_id) { |
|
| 225 | + $action = $hybrid_store->fetch_action($action_id); |
|
| 226 | + $this->assertInstanceOf(ActionScheduler_Action::class, $action); |
|
| 227 | + $this->assertNotInstanceOf(NullAction::class, $action); |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | |
@@ -235,42 +235,42 @@ discard block |
||
| 235 | 235 | $destination_logger = new ActionScheduler_DBLogger(); |
| 236 | 236 | |
| 237 | 237 | $config = new Config(); |
| 238 | - $config->set_source_store( $source_store ); |
|
| 239 | - $config->set_source_logger( $source_logger ); |
|
| 240 | - $config->set_destination_store( $destination_store ); |
|
| 241 | - $config->set_destination_logger( $destination_logger ); |
|
| 238 | + $config->set_source_store($source_store); |
|
| 239 | + $config->set_source_logger($source_logger); |
|
| 240 | + $config->set_destination_store($destination_store); |
|
| 241 | + $config->set_destination_logger($destination_logger); |
|
| 242 | 242 | |
| 243 | - $hybrid_store = new ActionScheduler_HybridStore( $config ); |
|
| 243 | + $hybrid_store = new ActionScheduler_HybridStore($config); |
|
| 244 | 244 | |
| 245 | 245 | $source_actions = array(); |
| 246 | 246 | $destination_actions = array(); |
| 247 | 247 | |
| 248 | - for ( $i = 0; $i < 2; $i++ ) { |
|
| 248 | + for ($i = 0; $i < 2; $i++) { |
|
| 249 | 249 | // create in instance in the source store |
| 250 | - $time = as_get_datetime_object( ( $i * 10 + 1 ) . ' minutes ago' ); |
|
| 251 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 252 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 250 | + $time = as_get_datetime_object(($i * 10 + 1).' minutes ago'); |
|
| 251 | + $schedule = new ActionScheduler_SimpleSchedule($time); |
|
| 252 | + $action = new ActionScheduler_Action(__FUNCTION__, array(), $schedule); |
|
| 253 | 253 | |
| 254 | - $source_actions[] = $source_store->save_action( $action ); |
|
| 254 | + $source_actions[] = $source_store->save_action($action); |
|
| 255 | 255 | |
| 256 | 256 | // create an instance in the destination store |
| 257 | - $time = as_get_datetime_object( ( $i * 10 + 5 ) . ' minutes ago' ); |
|
| 258 | - $schedule = new ActionScheduler_SimpleSchedule( $time ); |
|
| 259 | - $action = new ActionScheduler_Action( __FUNCTION__, array(), $schedule ); |
|
| 257 | + $time = as_get_datetime_object(($i * 10 + 5).' minutes ago'); |
|
| 258 | + $schedule = new ActionScheduler_SimpleSchedule($time); |
|
| 259 | + $action = new ActionScheduler_Action(__FUNCTION__, array(), $schedule); |
|
| 260 | 260 | |
| 261 | - $destination_actions[] = $destination_store->save_action( $action ); |
|
| 261 | + $destination_actions[] = $destination_store->save_action($action); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - foreach ( $source_actions as $action_id ) { |
|
| 265 | - $hybrid_store->mark_complete( $action_id ); |
|
| 266 | - $action = $hybrid_store->fetch_action( $action_id ); |
|
| 267 | - $this->assertInstanceOf( ActionScheduler_FinishedAction::class, $action ); |
|
| 264 | + foreach ($source_actions as $action_id) { |
|
| 265 | + $hybrid_store->mark_complete($action_id); |
|
| 266 | + $action = $hybrid_store->fetch_action($action_id); |
|
| 267 | + $this->assertInstanceOf(ActionScheduler_FinishedAction::class, $action); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - foreach ( $destination_actions as $action_id ) { |
|
| 271 | - $hybrid_store->mark_complete( $action_id ); |
|
| 272 | - $action = $hybrid_store->fetch_action( $action_id ); |
|
| 273 | - $this->assertInstanceOf( ActionScheduler_FinishedAction::class, $action ); |
|
| 270 | + foreach ($destination_actions as $action_id) { |
|
| 271 | + $hybrid_store->mark_complete($action_id); |
|
| 272 | + $action = $hybrid_store->fetch_action($action_id); |
|
| 273 | + $this->assertInstanceOf(ActionScheduler_FinishedAction::class, $action); |
|
| 274 | 274 | } |
| 275 | 275 | } |
| 276 | 276 | } |
@@ -4,124 +4,124 @@ |
||
| 4 | 4 | * Class as_get_scheduled_actions_Test |
| 5 | 5 | */ |
| 6 | 6 | class as_get_scheduled_actions_Test extends ActionScheduler_UnitTestCase { |
| 7 | - private $hooks = array(); |
|
| 8 | - private $args = array(); |
|
| 9 | - private $groups = array(); |
|
| 7 | + private $hooks = array(); |
|
| 8 | + private $args = array(); |
|
| 9 | + private $groups = array(); |
|
| 10 | 10 | |
| 11 | - public function setUp() { |
|
| 12 | - parent::setUp(); |
|
| 11 | + public function setUp() { |
|
| 12 | + parent::setUp(); |
|
| 13 | 13 | |
| 14 | - $store = ActionScheduler::store(); |
|
| 14 | + $store = ActionScheduler::store(); |
|
| 15 | 15 | |
| 16 | - for ( $i = 0; $i < 10; $i++ ) { |
|
| 17 | - $this->hooks[ $i ] = md5( rand() ); |
|
| 18 | - $this->args[ $i ] = md5( rand() ); |
|
| 19 | - $this->groups[ $i ] = md5( rand() ); |
|
| 20 | - } |
|
| 16 | + for ( $i = 0; $i < 10; $i++ ) { |
|
| 17 | + $this->hooks[ $i ] = md5( rand() ); |
|
| 18 | + $this->args[ $i ] = md5( rand() ); |
|
| 19 | + $this->groups[ $i ] = md5( rand() ); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - for ( $i = 0; $i < 10; $i++ ) { |
|
| 23 | - for ( $j = 0; $j < 10; $j++ ) { |
|
| 24 | - $schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( $j - 3 . 'days' ) ); |
|
| 25 | - $group = $this->groups[ ( $i + $j ) % 10 ]; |
|
| 26 | - $action = new ActionScheduler_Action( $this->hooks[ $i ], array( $this->args[ $j ] ), $schedule, $group ); |
|
| 27 | - $store->save_action( $action ); |
|
| 28 | - } |
|
| 29 | - } |
|
| 30 | - } |
|
| 22 | + for ( $i = 0; $i < 10; $i++ ) { |
|
| 23 | + for ( $j = 0; $j < 10; $j++ ) { |
|
| 24 | + $schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( $j - 3 . 'days' ) ); |
|
| 25 | + $group = $this->groups[ ( $i + $j ) % 10 ]; |
|
| 26 | + $action = new ActionScheduler_Action( $this->hooks[ $i ], array( $this->args[ $j ] ), $schedule, $group ); |
|
| 27 | + $store->save_action( $action ); |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function test_date_queries() { |
|
| 33 | - $actions = as_get_scheduled_actions( |
|
| 34 | - array( |
|
| 35 | - 'date' => as_get_datetime_object( gmdate( 'Y-m-d 00:00:00' ) ), |
|
| 36 | - 'per_page' => -1, |
|
| 37 | - ), |
|
| 38 | - 'ids' |
|
| 39 | - ); |
|
| 40 | - $this->assertCount( 30, $actions ); |
|
| 32 | + public function test_date_queries() { |
|
| 33 | + $actions = as_get_scheduled_actions( |
|
| 34 | + array( |
|
| 35 | + 'date' => as_get_datetime_object( gmdate( 'Y-m-d 00:00:00' ) ), |
|
| 36 | + 'per_page' => -1, |
|
| 37 | + ), |
|
| 38 | + 'ids' |
|
| 39 | + ); |
|
| 40 | + $this->assertCount( 30, $actions ); |
|
| 41 | 41 | |
| 42 | - $actions = as_get_scheduled_actions( |
|
| 43 | - array( |
|
| 44 | - 'date' => as_get_datetime_object( gmdate( 'Y-m-d 00:00:00' ) ), |
|
| 45 | - 'date_compare' => '>=', |
|
| 46 | - 'per_page' => -1, |
|
| 47 | - ), |
|
| 48 | - 'ids' |
|
| 49 | - ); |
|
| 50 | - $this->assertCount( 70, $actions ); |
|
| 51 | - } |
|
| 42 | + $actions = as_get_scheduled_actions( |
|
| 43 | + array( |
|
| 44 | + 'date' => as_get_datetime_object( gmdate( 'Y-m-d 00:00:00' ) ), |
|
| 45 | + 'date_compare' => '>=', |
|
| 46 | + 'per_page' => -1, |
|
| 47 | + ), |
|
| 48 | + 'ids' |
|
| 49 | + ); |
|
| 50 | + $this->assertCount( 70, $actions ); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - public function test_hook_queries() { |
|
| 54 | - $actions = as_get_scheduled_actions( |
|
| 55 | - array( |
|
| 56 | - 'hook' => $this->hooks[2], |
|
| 57 | - 'per_page' => -1, |
|
| 58 | - ), |
|
| 59 | - 'ids' |
|
| 60 | - ); |
|
| 61 | - $this->assertCount( 10, $actions ); |
|
| 53 | + public function test_hook_queries() { |
|
| 54 | + $actions = as_get_scheduled_actions( |
|
| 55 | + array( |
|
| 56 | + 'hook' => $this->hooks[2], |
|
| 57 | + 'per_page' => -1, |
|
| 58 | + ), |
|
| 59 | + 'ids' |
|
| 60 | + ); |
|
| 61 | + $this->assertCount( 10, $actions ); |
|
| 62 | 62 | |
| 63 | - $actions = as_get_scheduled_actions( |
|
| 64 | - array( |
|
| 65 | - 'hook' => $this->hooks[2], |
|
| 66 | - 'date' => as_get_datetime_object( gmdate( 'Y-m-d 00:00:00' ) ), |
|
| 67 | - 'per_page' => -1, |
|
| 68 | - ), |
|
| 69 | - 'ids' |
|
| 70 | - ); |
|
| 71 | - $this->assertCount( 3, $actions ); |
|
| 72 | - } |
|
| 63 | + $actions = as_get_scheduled_actions( |
|
| 64 | + array( |
|
| 65 | + 'hook' => $this->hooks[2], |
|
| 66 | + 'date' => as_get_datetime_object( gmdate( 'Y-m-d 00:00:00' ) ), |
|
| 67 | + 'per_page' => -1, |
|
| 68 | + ), |
|
| 69 | + 'ids' |
|
| 70 | + ); |
|
| 71 | + $this->assertCount( 3, $actions ); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - public function test_args_queries() { |
|
| 75 | - $actions = as_get_scheduled_actions( |
|
| 76 | - array( |
|
| 77 | - 'args' => array( $this->args[5] ), |
|
| 78 | - 'per_page' => -1, |
|
| 79 | - ), |
|
| 80 | - 'ids' |
|
| 81 | - ); |
|
| 82 | - $this->assertCount( 10, $actions ); |
|
| 74 | + public function test_args_queries() { |
|
| 75 | + $actions = as_get_scheduled_actions( |
|
| 76 | + array( |
|
| 77 | + 'args' => array( $this->args[5] ), |
|
| 78 | + 'per_page' => -1, |
|
| 79 | + ), |
|
| 80 | + 'ids' |
|
| 81 | + ); |
|
| 82 | + $this->assertCount( 10, $actions ); |
|
| 83 | 83 | |
| 84 | - $actions = as_get_scheduled_actions( |
|
| 85 | - array( |
|
| 86 | - 'args' => array( $this->args[5] ), |
|
| 87 | - 'hook' => $this->hooks[3], |
|
| 88 | - 'per_page' => -1, |
|
| 89 | - ), |
|
| 90 | - 'ids' |
|
| 91 | - ); |
|
| 92 | - $this->assertCount( 1, $actions ); |
|
| 84 | + $actions = as_get_scheduled_actions( |
|
| 85 | + array( |
|
| 86 | + 'args' => array( $this->args[5] ), |
|
| 87 | + 'hook' => $this->hooks[3], |
|
| 88 | + 'per_page' => -1, |
|
| 89 | + ), |
|
| 90 | + 'ids' |
|
| 91 | + ); |
|
| 92 | + $this->assertCount( 1, $actions ); |
|
| 93 | 93 | |
| 94 | - $actions = as_get_scheduled_actions( |
|
| 95 | - array( |
|
| 96 | - 'args' => array( $this->args[5] ), |
|
| 97 | - 'hook' => $this->hooks[3], |
|
| 98 | - 'date' => as_get_datetime_object( gmdate( 'Y-m-d 00:00:00' ) ), |
|
| 99 | - 'per_page' => -1, |
|
| 100 | - ), |
|
| 101 | - 'ids' |
|
| 102 | - ); |
|
| 103 | - $this->assertCount( 0, $actions ); |
|
| 104 | - } |
|
| 94 | + $actions = as_get_scheduled_actions( |
|
| 95 | + array( |
|
| 96 | + 'args' => array( $this->args[5] ), |
|
| 97 | + 'hook' => $this->hooks[3], |
|
| 98 | + 'date' => as_get_datetime_object( gmdate( 'Y-m-d 00:00:00' ) ), |
|
| 99 | + 'per_page' => -1, |
|
| 100 | + ), |
|
| 101 | + 'ids' |
|
| 102 | + ); |
|
| 103 | + $this->assertCount( 0, $actions ); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - public function test_group_queries() { |
|
| 107 | - $actions = as_get_scheduled_actions( |
|
| 108 | - array( |
|
| 109 | - 'group' => $this->groups[1], |
|
| 110 | - 'per_page' => -1, |
|
| 111 | - ), |
|
| 112 | - 'ids' |
|
| 113 | - ); |
|
| 114 | - $this->assertCount( 10, $actions ); |
|
| 106 | + public function test_group_queries() { |
|
| 107 | + $actions = as_get_scheduled_actions( |
|
| 108 | + array( |
|
| 109 | + 'group' => $this->groups[1], |
|
| 110 | + 'per_page' => -1, |
|
| 111 | + ), |
|
| 112 | + 'ids' |
|
| 113 | + ); |
|
| 114 | + $this->assertCount( 10, $actions ); |
|
| 115 | 115 | |
| 116 | - $actions = as_get_scheduled_actions( |
|
| 117 | - array( |
|
| 118 | - 'group' => $this->groups[1], |
|
| 119 | - 'hook' => $this->hooks[9], |
|
| 120 | - 'per_page' => -1, |
|
| 121 | - ), |
|
| 122 | - 'ids' |
|
| 123 | - ); |
|
| 124 | - $this->assertCount( 1, $actions ); |
|
| 125 | - } |
|
| 116 | + $actions = as_get_scheduled_actions( |
|
| 117 | + array( |
|
| 118 | + 'group' => $this->groups[1], |
|
| 119 | + 'hook' => $this->hooks[9], |
|
| 120 | + 'per_page' => -1, |
|
| 121 | + ), |
|
| 122 | + 'ids' |
|
| 123 | + ); |
|
| 124 | + $this->assertCount( 1, $actions ); |
|
| 125 | + } |
|
| 126 | 126 | } |
| 127 | 127 | |
@@ -13,18 +13,18 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | $store = ActionScheduler::store(); |
| 15 | 15 | |
| 16 | - for ( $i = 0; $i < 10; $i++ ) { |
|
| 17 | - $this->hooks[ $i ] = md5( rand() ); |
|
| 18 | - $this->args[ $i ] = md5( rand() ); |
|
| 19 | - $this->groups[ $i ] = md5( rand() ); |
|
| 16 | + for ($i = 0; $i < 10; $i++) { |
|
| 17 | + $this->hooks[$i] = md5(rand()); |
|
| 18 | + $this->args[$i] = md5(rand()); |
|
| 19 | + $this->groups[$i] = md5(rand()); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - for ( $i = 0; $i < 10; $i++ ) { |
|
| 23 | - for ( $j = 0; $j < 10; $j++ ) { |
|
| 24 | - $schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( $j - 3 . 'days' ) ); |
|
| 25 | - $group = $this->groups[ ( $i + $j ) % 10 ]; |
|
| 26 | - $action = new ActionScheduler_Action( $this->hooks[ $i ], array( $this->args[ $j ] ), $schedule, $group ); |
|
| 27 | - $store->save_action( $action ); |
|
| 22 | + for ($i = 0; $i < 10; $i++) { |
|
| 23 | + for ($j = 0; $j < 10; $j++) { |
|
| 24 | + $schedule = new ActionScheduler_SimpleSchedule(as_get_datetime_object($j - 3.'days')); |
|
| 25 | + $group = $this->groups[($i + $j) % 10]; |
|
| 26 | + $action = new ActionScheduler_Action($this->hooks[$i], array($this->args[$j]), $schedule, $group); |
|
| 27 | + $store->save_action($action); |
|
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | 30 | } |
@@ -32,22 +32,22 @@ discard block |
||
| 32 | 32 | public function test_date_queries() { |
| 33 | 33 | $actions = as_get_scheduled_actions( |
| 34 | 34 | array( |
| 35 | - 'date' => as_get_datetime_object( gmdate( 'Y-m-d 00:00:00' ) ), |
|
| 35 | + 'date' => as_get_datetime_object(gmdate('Y-m-d 00:00:00')), |
|
| 36 | 36 | 'per_page' => -1, |
| 37 | 37 | ), |
| 38 | 38 | 'ids' |
| 39 | 39 | ); |
| 40 | - $this->assertCount( 30, $actions ); |
|
| 40 | + $this->assertCount(30, $actions); |
|
| 41 | 41 | |
| 42 | 42 | $actions = as_get_scheduled_actions( |
| 43 | 43 | array( |
| 44 | - 'date' => as_get_datetime_object( gmdate( 'Y-m-d 00:00:00' ) ), |
|
| 44 | + 'date' => as_get_datetime_object(gmdate('Y-m-d 00:00:00')), |
|
| 45 | 45 | 'date_compare' => '>=', |
| 46 | 46 | 'per_page' => -1, |
| 47 | 47 | ), |
| 48 | 48 | 'ids' |
| 49 | 49 | ); |
| 50 | - $this->assertCount( 70, $actions ); |
|
| 50 | + $this->assertCount(70, $actions); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | public function test_hook_queries() { |
@@ -58,49 +58,49 @@ discard block |
||
| 58 | 58 | ), |
| 59 | 59 | 'ids' |
| 60 | 60 | ); |
| 61 | - $this->assertCount( 10, $actions ); |
|
| 61 | + $this->assertCount(10, $actions); |
|
| 62 | 62 | |
| 63 | 63 | $actions = as_get_scheduled_actions( |
| 64 | 64 | array( |
| 65 | 65 | 'hook' => $this->hooks[2], |
| 66 | - 'date' => as_get_datetime_object( gmdate( 'Y-m-d 00:00:00' ) ), |
|
| 66 | + 'date' => as_get_datetime_object(gmdate('Y-m-d 00:00:00')), |
|
| 67 | 67 | 'per_page' => -1, |
| 68 | 68 | ), |
| 69 | 69 | 'ids' |
| 70 | 70 | ); |
| 71 | - $this->assertCount( 3, $actions ); |
|
| 71 | + $this->assertCount(3, $actions); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | public function test_args_queries() { |
| 75 | 75 | $actions = as_get_scheduled_actions( |
| 76 | 76 | array( |
| 77 | - 'args' => array( $this->args[5] ), |
|
| 77 | + 'args' => array($this->args[5]), |
|
| 78 | 78 | 'per_page' => -1, |
| 79 | 79 | ), |
| 80 | 80 | 'ids' |
| 81 | 81 | ); |
| 82 | - $this->assertCount( 10, $actions ); |
|
| 82 | + $this->assertCount(10, $actions); |
|
| 83 | 83 | |
| 84 | 84 | $actions = as_get_scheduled_actions( |
| 85 | 85 | array( |
| 86 | - 'args' => array( $this->args[5] ), |
|
| 86 | + 'args' => array($this->args[5]), |
|
| 87 | 87 | 'hook' => $this->hooks[3], |
| 88 | 88 | 'per_page' => -1, |
| 89 | 89 | ), |
| 90 | 90 | 'ids' |
| 91 | 91 | ); |
| 92 | - $this->assertCount( 1, $actions ); |
|
| 92 | + $this->assertCount(1, $actions); |
|
| 93 | 93 | |
| 94 | 94 | $actions = as_get_scheduled_actions( |
| 95 | 95 | array( |
| 96 | - 'args' => array( $this->args[5] ), |
|
| 96 | + 'args' => array($this->args[5]), |
|
| 97 | 97 | 'hook' => $this->hooks[3], |
| 98 | - 'date' => as_get_datetime_object( gmdate( 'Y-m-d 00:00:00' ) ), |
|
| 98 | + 'date' => as_get_datetime_object(gmdate('Y-m-d 00:00:00')), |
|
| 99 | 99 | 'per_page' => -1, |
| 100 | 100 | ), |
| 101 | 101 | 'ids' |
| 102 | 102 | ); |
| 103 | - $this->assertCount( 0, $actions ); |
|
| 103 | + $this->assertCount(0, $actions); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | public function test_group_queries() { |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | ), |
| 112 | 112 | 'ids' |
| 113 | 113 | ); |
| 114 | - $this->assertCount( 10, $actions ); |
|
| 114 | + $this->assertCount(10, $actions); |
|
| 115 | 115 | |
| 116 | 116 | $actions = as_get_scheduled_actions( |
| 117 | 117 | array( |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | ), |
| 122 | 122 | 'ids' |
| 123 | 123 | ); |
| 124 | - $this->assertCount( 1, $actions ); |
|
| 124 | + $this->assertCount(1, $actions); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
@@ -5,373 +5,373 @@ |
||
| 5 | 5 | */ |
| 6 | 6 | class Procedural_API_Test extends ActionScheduler_UnitTestCase { |
| 7 | 7 | |
| 8 | - // phpcs:disable Squiz.Commenting.FunctionComment.Missing, Squiz.Commenting.FunctionComment.MissingParamTag |
|
| 9 | - public function test_schedule_action() { |
|
| 10 | - $time = time(); |
|
| 11 | - $hook = md5( rand() ); |
|
| 12 | - $action_id = as_schedule_single_action( $time, $hook ); |
|
| 13 | - |
|
| 14 | - $store = ActionScheduler::store(); |
|
| 15 | - $action = $store->fetch_action( $action_id ); |
|
| 16 | - $this->assertEquals( $time, $action->get_schedule()->get_date()->getTimestamp() ); |
|
| 17 | - $this->assertEquals( $hook, $action->get_hook() ); |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - public function test_recurring_action() { |
|
| 21 | - $time = time(); |
|
| 22 | - $hook = md5( rand() ); |
|
| 23 | - $action_id = as_schedule_recurring_action( $time, HOUR_IN_SECONDS, $hook ); |
|
| 24 | - |
|
| 25 | - $store = ActionScheduler::store(); |
|
| 26 | - $action = $store->fetch_action( $action_id ); |
|
| 27 | - $this->assertEquals( $time, $action->get_schedule()->get_date()->getTimestamp() ); |
|
| 28 | - $this->assertEquals( $time + HOUR_IN_SECONDS + 2, $action->get_schedule()->get_next( as_get_datetime_object( $time + 2 ) )->getTimestamp() ); |
|
| 29 | - $this->assertEquals( $hook, $action->get_hook() ); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - public function test_cron_schedule() { |
|
| 33 | - $time = as_get_datetime_object( '2014-01-01' ); |
|
| 34 | - $hook = md5( rand() ); |
|
| 35 | - $action_id = as_schedule_cron_action( $time->getTimestamp(), '0 0 10 10 *', $hook ); |
|
| 36 | - |
|
| 37 | - $store = ActionScheduler::store(); |
|
| 38 | - $action = $store->fetch_action( $action_id ); |
|
| 39 | - $expected_date = as_get_datetime_object( '2014-10-10' ); |
|
| 40 | - $this->assertEquals( $expected_date->getTimestamp(), $action->get_schedule()->get_date()->getTimestamp() ); |
|
| 41 | - $this->assertEquals( $hook, $action->get_hook() ); |
|
| 42 | - |
|
| 43 | - $expected_date = as_get_datetime_object( '2015-10-10' ); |
|
| 44 | - $this->assertEquals( $expected_date->getTimestamp(), $action->get_schedule()->get_next( as_get_datetime_object( '2015-01-02' ) )->getTimestamp() ); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public function test_get_next() { |
|
| 48 | - $time = as_get_datetime_object( 'tomorrow' ); |
|
| 49 | - $hook = md5( rand() ); |
|
| 50 | - as_schedule_recurring_action( $time->getTimestamp(), HOUR_IN_SECONDS, $hook ); |
|
| 51 | - |
|
| 52 | - $next = as_next_scheduled_action( $hook ); |
|
| 53 | - |
|
| 54 | - $this->assertEquals( $time->getTimestamp(), $next ); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - public function test_get_next_async() { |
|
| 58 | - $hook = md5( rand() ); |
|
| 59 | - $action_id = as_enqueue_async_action( $hook ); |
|
| 60 | - |
|
| 61 | - $next = as_next_scheduled_action( $hook ); |
|
| 62 | - |
|
| 63 | - $this->assertTrue( $next ); |
|
| 64 | - |
|
| 65 | - $store = ActionScheduler::store(); |
|
| 66 | - |
|
| 67 | - // Completed async actions should still return false. |
|
| 68 | - $store->mark_complete( $action_id ); |
|
| 69 | - $next = as_next_scheduled_action( $hook ); |
|
| 70 | - $this->assertFalse( $next ); |
|
| 71 | - |
|
| 72 | - // Failed async actions should still return false. |
|
| 73 | - $store->mark_failure( $action_id ); |
|
| 74 | - $next = as_next_scheduled_action( $hook ); |
|
| 75 | - $this->assertFalse( $next ); |
|
| 76 | - |
|
| 77 | - // Cancelled async actions should still return false. |
|
| 78 | - $store->cancel_action( $action_id ); |
|
| 79 | - $next = as_next_scheduled_action( $hook ); |
|
| 80 | - $this->assertFalse( $next ); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - public function provider_time_hook_args_group() { |
|
| 84 | - $time = time() + 60 * 2; |
|
| 85 | - $hook = md5( rand() ); |
|
| 86 | - $args = array( rand(), rand() ); |
|
| 87 | - $group = 'test_group'; |
|
| 88 | - |
|
| 89 | - return array( |
|
| 90 | - |
|
| 91 | - // Test with no args or group. |
|
| 92 | - array( |
|
| 93 | - 'time' => $time, |
|
| 94 | - 'hook' => $hook, |
|
| 95 | - 'args' => array(), |
|
| 96 | - 'group' => '', |
|
| 97 | - ), |
|
| 98 | - |
|
| 99 | - // Test with args but no group. |
|
| 100 | - array( |
|
| 101 | - 'time' => $time, |
|
| 102 | - 'hook' => $hook, |
|
| 103 | - 'args' => $args, |
|
| 104 | - 'group' => '', |
|
| 105 | - ), |
|
| 106 | - |
|
| 107 | - // Test with group but no args. |
|
| 108 | - array( |
|
| 109 | - 'time' => $time, |
|
| 110 | - 'hook' => $hook, |
|
| 111 | - 'args' => array(), |
|
| 112 | - 'group' => $group, |
|
| 113 | - ), |
|
| 114 | - |
|
| 115 | - // Test with args & group. |
|
| 116 | - array( |
|
| 117 | - 'time' => $time, |
|
| 118 | - 'hook' => $hook, |
|
| 119 | - 'args' => $args, |
|
| 120 | - 'group' => $group, |
|
| 121 | - ), |
|
| 122 | - ); |
|
| 123 | - } |
|
| 8 | + // phpcs:disable Squiz.Commenting.FunctionComment.Missing, Squiz.Commenting.FunctionComment.MissingParamTag |
|
| 9 | + public function test_schedule_action() { |
|
| 10 | + $time = time(); |
|
| 11 | + $hook = md5( rand() ); |
|
| 12 | + $action_id = as_schedule_single_action( $time, $hook ); |
|
| 13 | + |
|
| 14 | + $store = ActionScheduler::store(); |
|
| 15 | + $action = $store->fetch_action( $action_id ); |
|
| 16 | + $this->assertEquals( $time, $action->get_schedule()->get_date()->getTimestamp() ); |
|
| 17 | + $this->assertEquals( $hook, $action->get_hook() ); |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + public function test_recurring_action() { |
|
| 21 | + $time = time(); |
|
| 22 | + $hook = md5( rand() ); |
|
| 23 | + $action_id = as_schedule_recurring_action( $time, HOUR_IN_SECONDS, $hook ); |
|
| 24 | + |
|
| 25 | + $store = ActionScheduler::store(); |
|
| 26 | + $action = $store->fetch_action( $action_id ); |
|
| 27 | + $this->assertEquals( $time, $action->get_schedule()->get_date()->getTimestamp() ); |
|
| 28 | + $this->assertEquals( $time + HOUR_IN_SECONDS + 2, $action->get_schedule()->get_next( as_get_datetime_object( $time + 2 ) )->getTimestamp() ); |
|
| 29 | + $this->assertEquals( $hook, $action->get_hook() ); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + public function test_cron_schedule() { |
|
| 33 | + $time = as_get_datetime_object( '2014-01-01' ); |
|
| 34 | + $hook = md5( rand() ); |
|
| 35 | + $action_id = as_schedule_cron_action( $time->getTimestamp(), '0 0 10 10 *', $hook ); |
|
| 36 | + |
|
| 37 | + $store = ActionScheduler::store(); |
|
| 38 | + $action = $store->fetch_action( $action_id ); |
|
| 39 | + $expected_date = as_get_datetime_object( '2014-10-10' ); |
|
| 40 | + $this->assertEquals( $expected_date->getTimestamp(), $action->get_schedule()->get_date()->getTimestamp() ); |
|
| 41 | + $this->assertEquals( $hook, $action->get_hook() ); |
|
| 42 | + |
|
| 43 | + $expected_date = as_get_datetime_object( '2015-10-10' ); |
|
| 44 | + $this->assertEquals( $expected_date->getTimestamp(), $action->get_schedule()->get_next( as_get_datetime_object( '2015-01-02' ) )->getTimestamp() ); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public function test_get_next() { |
|
| 48 | + $time = as_get_datetime_object( 'tomorrow' ); |
|
| 49 | + $hook = md5( rand() ); |
|
| 50 | + as_schedule_recurring_action( $time->getTimestamp(), HOUR_IN_SECONDS, $hook ); |
|
| 51 | + |
|
| 52 | + $next = as_next_scheduled_action( $hook ); |
|
| 53 | + |
|
| 54 | + $this->assertEquals( $time->getTimestamp(), $next ); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + public function test_get_next_async() { |
|
| 58 | + $hook = md5( rand() ); |
|
| 59 | + $action_id = as_enqueue_async_action( $hook ); |
|
| 60 | + |
|
| 61 | + $next = as_next_scheduled_action( $hook ); |
|
| 62 | + |
|
| 63 | + $this->assertTrue( $next ); |
|
| 64 | + |
|
| 65 | + $store = ActionScheduler::store(); |
|
| 66 | + |
|
| 67 | + // Completed async actions should still return false. |
|
| 68 | + $store->mark_complete( $action_id ); |
|
| 69 | + $next = as_next_scheduled_action( $hook ); |
|
| 70 | + $this->assertFalse( $next ); |
|
| 71 | + |
|
| 72 | + // Failed async actions should still return false. |
|
| 73 | + $store->mark_failure( $action_id ); |
|
| 74 | + $next = as_next_scheduled_action( $hook ); |
|
| 75 | + $this->assertFalse( $next ); |
|
| 76 | + |
|
| 77 | + // Cancelled async actions should still return false. |
|
| 78 | + $store->cancel_action( $action_id ); |
|
| 79 | + $next = as_next_scheduled_action( $hook ); |
|
| 80 | + $this->assertFalse( $next ); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + public function provider_time_hook_args_group() { |
|
| 84 | + $time = time() + 60 * 2; |
|
| 85 | + $hook = md5( rand() ); |
|
| 86 | + $args = array( rand(), rand() ); |
|
| 87 | + $group = 'test_group'; |
|
| 88 | + |
|
| 89 | + return array( |
|
| 90 | + |
|
| 91 | + // Test with no args or group. |
|
| 92 | + array( |
|
| 93 | + 'time' => $time, |
|
| 94 | + 'hook' => $hook, |
|
| 95 | + 'args' => array(), |
|
| 96 | + 'group' => '', |
|
| 97 | + ), |
|
| 98 | + |
|
| 99 | + // Test with args but no group. |
|
| 100 | + array( |
|
| 101 | + 'time' => $time, |
|
| 102 | + 'hook' => $hook, |
|
| 103 | + 'args' => $args, |
|
| 104 | + 'group' => '', |
|
| 105 | + ), |
|
| 106 | + |
|
| 107 | + // Test with group but no args. |
|
| 108 | + array( |
|
| 109 | + 'time' => $time, |
|
| 110 | + 'hook' => $hook, |
|
| 111 | + 'args' => array(), |
|
| 112 | + 'group' => $group, |
|
| 113 | + ), |
|
| 114 | + |
|
| 115 | + // Test with args & group. |
|
| 116 | + array( |
|
| 117 | + 'time' => $time, |
|
| 118 | + 'hook' => $hook, |
|
| 119 | + 'args' => $args, |
|
| 120 | + 'group' => $group, |
|
| 121 | + ), |
|
| 122 | + ); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * @dataProvider provider_time_hook_args_group |
|
| 127 | - */ |
|
| 128 | - public function test_unschedule( $time, $hook, $args, $group ) { |
|
| 125 | + /** |
|
| 126 | + * @dataProvider provider_time_hook_args_group |
|
| 127 | + */ |
|
| 128 | + public function test_unschedule( $time, $hook, $args, $group ) { |
|
| 129 | 129 | |
| 130 | - $action_id_unscheduled = as_schedule_single_action( $time, $hook, $args, $group ); |
|
| 131 | - $action_scheduled_time = $time + 1; |
|
| 132 | - $action_id_scheduled = as_schedule_single_action( $action_scheduled_time, $hook, $args, $group ); |
|
| 130 | + $action_id_unscheduled = as_schedule_single_action( $time, $hook, $args, $group ); |
|
| 131 | + $action_scheduled_time = $time + 1; |
|
| 132 | + $action_id_scheduled = as_schedule_single_action( $action_scheduled_time, $hook, $args, $group ); |
|
| 133 | 133 | |
| 134 | - as_unschedule_action( $hook, $args, $group ); |
|
| 134 | + as_unschedule_action( $hook, $args, $group ); |
|
| 135 | 135 | |
| 136 | - $next = as_next_scheduled_action( $hook, $args, $group ); |
|
| 137 | - $this->assertEquals( $action_scheduled_time, $next ); |
|
| 136 | + $next = as_next_scheduled_action( $hook, $args, $group ); |
|
| 137 | + $this->assertEquals( $action_scheduled_time, $next ); |
|
| 138 | 138 | |
| 139 | - $store = ActionScheduler::store(); |
|
| 140 | - $unscheduled_action = $store->fetch_action( $action_id_unscheduled ); |
|
| 139 | + $store = ActionScheduler::store(); |
|
| 140 | + $unscheduled_action = $store->fetch_action( $action_id_unscheduled ); |
|
| 141 | 141 | |
| 142 | - // Make sure the next scheduled action is unscheduled. |
|
| 143 | - $this->assertEquals( $hook, $unscheduled_action->get_hook() ); |
|
| 144 | - $this->assertEquals( as_get_datetime_object( $time ), $unscheduled_action->get_schedule()->get_date() ); |
|
| 145 | - $this->assertEquals( ActionScheduler_Store::STATUS_CANCELED, $store->get_status( $action_id_unscheduled ) ); |
|
| 146 | - $this->assertNull( $unscheduled_action->get_schedule()->get_next( as_get_datetime_object() ) ); |
|
| 142 | + // Make sure the next scheduled action is unscheduled. |
|
| 143 | + $this->assertEquals( $hook, $unscheduled_action->get_hook() ); |
|
| 144 | + $this->assertEquals( as_get_datetime_object( $time ), $unscheduled_action->get_schedule()->get_date() ); |
|
| 145 | + $this->assertEquals( ActionScheduler_Store::STATUS_CANCELED, $store->get_status( $action_id_unscheduled ) ); |
|
| 146 | + $this->assertNull( $unscheduled_action->get_schedule()->get_next( as_get_datetime_object() ) ); |
|
| 147 | 147 | |
| 148 | - // Make sure other scheduled actions are not unscheduled. |
|
| 149 | - $this->assertEquals( ActionScheduler_Store::STATUS_PENDING, $store->get_status( $action_id_scheduled ) ); |
|
| 150 | - $scheduled_action = $store->fetch_action( $action_id_scheduled ); |
|
| 148 | + // Make sure other scheduled actions are not unscheduled. |
|
| 149 | + $this->assertEquals( ActionScheduler_Store::STATUS_PENDING, $store->get_status( $action_id_scheduled ) ); |
|
| 150 | + $scheduled_action = $store->fetch_action( $action_id_scheduled ); |
|
| 151 | 151 | |
| 152 | - $this->assertEquals( $hook, $scheduled_action->get_hook() ); |
|
| 153 | - $this->assertEquals( $action_scheduled_time, $scheduled_action->get_schedule()->get_date()->getTimestamp() ); |
|
| 154 | - } |
|
| 152 | + $this->assertEquals( $hook, $scheduled_action->get_hook() ); |
|
| 153 | + $this->assertEquals( $action_scheduled_time, $scheduled_action->get_schedule()->get_date()->getTimestamp() ); |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * @dataProvider provider_time_hook_args_group |
|
| 158 | - */ |
|
| 159 | - public function test_unschedule_all( $time, $hook, $args, $group ) { |
|
| 156 | + /** |
|
| 157 | + * @dataProvider provider_time_hook_args_group |
|
| 158 | + */ |
|
| 159 | + public function test_unschedule_all( $time, $hook, $args, $group ) { |
|
| 160 | 160 | |
| 161 | - $hook = md5( $hook ); |
|
| 162 | - $action_ids = array(); |
|
| 161 | + $hook = md5( $hook ); |
|
| 162 | + $action_ids = array(); |
|
| 163 | 163 | |
| 164 | - for ( $i = 0; $i < 3; $i++ ) { |
|
| 165 | - $action_ids[] = as_schedule_single_action( $time, $hook, $args, $group ); |
|
| 166 | - } |
|
| 164 | + for ( $i = 0; $i < 3; $i++ ) { |
|
| 165 | + $action_ids[] = as_schedule_single_action( $time, $hook, $args, $group ); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - as_unschedule_all_actions( $hook, $args, $group ); |
|
| 168 | + as_unschedule_all_actions( $hook, $args, $group ); |
|
| 169 | 169 | |
| 170 | - $next = as_next_scheduled_action( $hook ); |
|
| 171 | - $this->assertFalse( $next ); |
|
| 170 | + $next = as_next_scheduled_action( $hook ); |
|
| 171 | + $this->assertFalse( $next ); |
|
| 172 | 172 | |
| 173 | - $after = as_get_datetime_object( $time ); |
|
| 174 | - $after->modify( '+1 minute' ); |
|
| 173 | + $after = as_get_datetime_object( $time ); |
|
| 174 | + $after->modify( '+1 minute' ); |
|
| 175 | 175 | |
| 176 | - $store = ActionScheduler::store(); |
|
| 176 | + $store = ActionScheduler::store(); |
|
| 177 | 177 | |
| 178 | - foreach ( $action_ids as $action_id ) { |
|
| 179 | - $action = $store->fetch_action( $action_id ); |
|
| 178 | + foreach ( $action_ids as $action_id ) { |
|
| 179 | + $action = $store->fetch_action( $action_id ); |
|
| 180 | 180 | |
| 181 | - $this->assertEquals( $hook, $action->get_hook() ); |
|
| 182 | - $this->assertEquals( as_get_datetime_object( $time ), $action->get_schedule()->get_date() ); |
|
| 183 | - $this->assertEquals( ActionScheduler_Store::STATUS_CANCELED, $store->get_status( $action_id ) ); |
|
| 184 | - $this->assertNull( $action->get_schedule()->get_next( $after ) ); |
|
| 185 | - } |
|
| 186 | - } |
|
| 181 | + $this->assertEquals( $hook, $action->get_hook() ); |
|
| 182 | + $this->assertEquals( as_get_datetime_object( $time ), $action->get_schedule()->get_date() ); |
|
| 183 | + $this->assertEquals( ActionScheduler_Store::STATUS_CANCELED, $store->get_status( $action_id ) ); |
|
| 184 | + $this->assertNull( $action->get_schedule()->get_next( $after ) ); |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - public function test_as_get_datetime_object_default() { |
|
| 188 | + public function test_as_get_datetime_object_default() { |
|
| 189 | 189 | |
| 190 | - $utc_now = new ActionScheduler_DateTime( null, new DateTimeZone( 'UTC' ) ); |
|
| 191 | - $as_now = as_get_datetime_object(); |
|
| 190 | + $utc_now = new ActionScheduler_DateTime( null, new DateTimeZone( 'UTC' ) ); |
|
| 191 | + $as_now = as_get_datetime_object(); |
|
| 192 | 192 | |
| 193 | - // Don't want to use 'U' as timestamps will always be in UTC. |
|
| 194 | - $this->assertEquals( $utc_now->format( 'Y-m-d H:i:s' ), $as_now->format( 'Y-m-d H:i:s' ) ); |
|
| 195 | - } |
|
| 193 | + // Don't want to use 'U' as timestamps will always be in UTC. |
|
| 194 | + $this->assertEquals( $utc_now->format( 'Y-m-d H:i:s' ), $as_now->format( 'Y-m-d H:i:s' ) ); |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - public function test_as_get_datetime_object_relative() { |
|
| 197 | + public function test_as_get_datetime_object_relative() { |
|
| 198 | 198 | |
| 199 | - $utc_tomorrow = new ActionScheduler_DateTime( 'tomorrow', new DateTimeZone( 'UTC' ) ); |
|
| 200 | - $as_tomorrow = as_get_datetime_object( 'tomorrow' ); |
|
| 199 | + $utc_tomorrow = new ActionScheduler_DateTime( 'tomorrow', new DateTimeZone( 'UTC' ) ); |
|
| 200 | + $as_tomorrow = as_get_datetime_object( 'tomorrow' ); |
|
| 201 | 201 | |
| 202 | - $this->assertEquals( $utc_tomorrow->format( 'Y-m-d H:i:s' ), $as_tomorrow->format( 'Y-m-d H:i:s' ) ); |
|
| 202 | + $this->assertEquals( $utc_tomorrow->format( 'Y-m-d H:i:s' ), $as_tomorrow->format( 'Y-m-d H:i:s' ) ); |
|
| 203 | 203 | |
| 204 | - $utc_tomorrow = new ActionScheduler_DateTime( 'yesterday', new DateTimeZone( 'UTC' ) ); |
|
| 205 | - $as_tomorrow = as_get_datetime_object( 'yesterday' ); |
|
| 204 | + $utc_tomorrow = new ActionScheduler_DateTime( 'yesterday', new DateTimeZone( 'UTC' ) ); |
|
| 205 | + $as_tomorrow = as_get_datetime_object( 'yesterday' ); |
|
| 206 | 206 | |
| 207 | - $this->assertEquals( $utc_tomorrow->format( 'Y-m-d H:i:s' ), $as_tomorrow->format( 'Y-m-d H:i:s' ) ); |
|
| 208 | - } |
|
| 207 | + $this->assertEquals( $utc_tomorrow->format( 'Y-m-d H:i:s' ), $as_tomorrow->format( 'Y-m-d H:i:s' ) ); |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - public function test_as_get_datetime_object_fixed() { |
|
| 210 | + public function test_as_get_datetime_object_fixed() { |
|
| 211 | 211 | |
| 212 | - $utc_tomorrow = new ActionScheduler_DateTime( '29 February 2016', new DateTimeZone( 'UTC' ) ); |
|
| 213 | - $as_tomorrow = as_get_datetime_object( '29 February 2016' ); |
|
| 212 | + $utc_tomorrow = new ActionScheduler_DateTime( '29 February 2016', new DateTimeZone( 'UTC' ) ); |
|
| 213 | + $as_tomorrow = as_get_datetime_object( '29 February 2016' ); |
|
| 214 | 214 | |
| 215 | - $this->assertEquals( $utc_tomorrow->format( 'Y-m-d H:i:s' ), $as_tomorrow->format( 'Y-m-d H:i:s' ) ); |
|
| 215 | + $this->assertEquals( $utc_tomorrow->format( 'Y-m-d H:i:s' ), $as_tomorrow->format( 'Y-m-d H:i:s' ) ); |
|
| 216 | 216 | |
| 217 | - $utc_tomorrow = new ActionScheduler_DateTime( '1st January 2024', new DateTimeZone( 'UTC' ) ); |
|
| 218 | - $as_tomorrow = as_get_datetime_object( '1st January 2024' ); |
|
| 217 | + $utc_tomorrow = new ActionScheduler_DateTime( '1st January 2024', new DateTimeZone( 'UTC' ) ); |
|
| 218 | + $as_tomorrow = as_get_datetime_object( '1st January 2024' ); |
|
| 219 | 219 | |
| 220 | - $this->assertEquals( $utc_tomorrow->format( 'Y-m-d H:i:s' ), $as_tomorrow->format( 'Y-m-d H:i:s' ) ); |
|
| 221 | - } |
|
| 220 | + $this->assertEquals( $utc_tomorrow->format( 'Y-m-d H:i:s' ), $as_tomorrow->format( 'Y-m-d H:i:s' ) ); |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - public function test_as_get_datetime_object_timezone() { |
|
| 223 | + public function test_as_get_datetime_object_timezone() { |
|
| 224 | 224 | |
| 225 | - $timezone_au = 'Australia/Brisbane'; |
|
| 226 | - $timezone_default = date_default_timezone_get(); |
|
| 225 | + $timezone_au = 'Australia/Brisbane'; |
|
| 226 | + $timezone_default = date_default_timezone_get(); |
|
| 227 | 227 | |
| 228 | - // phpcs:ignore |
|
| 229 | - date_default_timezone_set( $timezone_au ); |
|
| 228 | + // phpcs:ignore |
|
| 229 | + date_default_timezone_set( $timezone_au ); |
|
| 230 | 230 | |
| 231 | - $au_now = new ActionScheduler_DateTime( null ); |
|
| 232 | - $as_now = as_get_datetime_object(); |
|
| 231 | + $au_now = new ActionScheduler_DateTime( null ); |
|
| 232 | + $as_now = as_get_datetime_object(); |
|
| 233 | 233 | |
| 234 | - // Make sure they're for the same time. |
|
| 235 | - $this->assertEquals( $au_now->getTimestamp(), $as_now->getTimestamp() ); |
|
| 234 | + // Make sure they're for the same time. |
|
| 235 | + $this->assertEquals( $au_now->getTimestamp(), $as_now->getTimestamp() ); |
|
| 236 | 236 | |
| 237 | - // But not in the same timezone, as $as_now should be using UTC. |
|
| 238 | - $this->assertNotEquals( $au_now->format( 'Y-m-d H:i:s' ), $as_now->format( 'Y-m-d H:i:s' ) ); |
|
| 237 | + // But not in the same timezone, as $as_now should be using UTC. |
|
| 238 | + $this->assertNotEquals( $au_now->format( 'Y-m-d H:i:s' ), $as_now->format( 'Y-m-d H:i:s' ) ); |
|
| 239 | 239 | |
| 240 | - $au_now = new ActionScheduler_DateTime( null ); |
|
| 241 | - $as_au_now = as_get_datetime_object(); |
|
| 240 | + $au_now = new ActionScheduler_DateTime( null ); |
|
| 241 | + $as_au_now = as_get_datetime_object(); |
|
| 242 | 242 | |
| 243 | - $this->assertEquals( $au_now->getTimestamp(), $as_now->getTimestamp(), '', 2 ); |
|
| 243 | + $this->assertEquals( $au_now->getTimestamp(), $as_now->getTimestamp(), '', 2 ); |
|
| 244 | 244 | |
| 245 | - // But not in the same timezone, as $as_now should be using UTC. |
|
| 246 | - $this->assertNotEquals( $au_now->format( 'Y-m-d H:i:s' ), $as_now->format( 'Y-m-d H:i:s' ) ); |
|
| 245 | + // But not in the same timezone, as $as_now should be using UTC. |
|
| 246 | + $this->assertNotEquals( $au_now->format( 'Y-m-d H:i:s' ), $as_now->format( 'Y-m-d H:i:s' ) ); |
|
| 247 | 247 | |
| 248 | - // phpcs:ignore |
|
| 249 | - date_default_timezone_set( $timezone_default ); |
|
| 250 | - } |
|
| 248 | + // phpcs:ignore |
|
| 249 | + date_default_timezone_set( $timezone_default ); |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - public function test_as_get_datetime_object_type() { |
|
| 253 | - $f = 'Y-m-d H:i:s'; |
|
| 254 | - $now = as_get_datetime_object(); |
|
| 255 | - $this->assertInstanceOf( 'ActionScheduler_DateTime', $now ); |
|
| 252 | + public function test_as_get_datetime_object_type() { |
|
| 253 | + $f = 'Y-m-d H:i:s'; |
|
| 254 | + $now = as_get_datetime_object(); |
|
| 255 | + $this->assertInstanceOf( 'ActionScheduler_DateTime', $now ); |
|
| 256 | 256 | |
| 257 | - $datetime = new DateTime( 'now', new DateTimeZone( 'UTC' ) ); |
|
| 258 | - $as_datetime = as_get_datetime_object( $datetime ); |
|
| 259 | - $this->assertEquals( $datetime->format( $f ), $as_datetime->format( $f ) ); |
|
| 260 | - } |
|
| 257 | + $datetime = new DateTime( 'now', new DateTimeZone( 'UTC' ) ); |
|
| 258 | + $as_datetime = as_get_datetime_object( $datetime ); |
|
| 259 | + $this->assertEquals( $datetime->format( $f ), $as_datetime->format( $f ) ); |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - public function test_as_has_scheduled_action() { |
|
| 263 | - $store = ActionScheduler::store(); |
|
| 262 | + public function test_as_has_scheduled_action() { |
|
| 263 | + $store = ActionScheduler::store(); |
|
| 264 | 264 | |
| 265 | - $time = as_get_datetime_object( 'tomorrow' ); |
|
| 266 | - $action_id = as_schedule_single_action( $time->getTimestamp(), 'hook_1' ); |
|
| 265 | + $time = as_get_datetime_object( 'tomorrow' ); |
|
| 266 | + $action_id = as_schedule_single_action( $time->getTimestamp(), 'hook_1' ); |
|
| 267 | 267 | |
| 268 | - $this->assertTrue( as_has_scheduled_action( 'hook_1' ) ); |
|
| 269 | - $this->assertFalse( as_has_scheduled_action( 'hook_2' ) ); |
|
| 268 | + $this->assertTrue( as_has_scheduled_action( 'hook_1' ) ); |
|
| 269 | + $this->assertFalse( as_has_scheduled_action( 'hook_2' ) ); |
|
| 270 | 270 | |
| 271 | - // Go to in-progress. |
|
| 272 | - $store->log_execution( $action_id ); |
|
| 273 | - $this->assertTrue( as_has_scheduled_action( 'hook_1' ) ); |
|
| 271 | + // Go to in-progress. |
|
| 272 | + $store->log_execution( $action_id ); |
|
| 273 | + $this->assertTrue( as_has_scheduled_action( 'hook_1' ) ); |
|
| 274 | 274 | |
| 275 | - // Go to complete. |
|
| 276 | - $store->mark_complete( $action_id ); |
|
| 277 | - $this->assertFalse( as_has_scheduled_action( 'hook_1' ) ); |
|
| 275 | + // Go to complete. |
|
| 276 | + $store->mark_complete( $action_id ); |
|
| 277 | + $this->assertFalse( as_has_scheduled_action( 'hook_1' ) ); |
|
| 278 | 278 | |
| 279 | - // Go to failed. |
|
| 280 | - $store->mark_failure( $action_id ); |
|
| 281 | - $this->assertFalse( as_has_scheduled_action( 'hook_1' ) ); |
|
| 282 | - } |
|
| 279 | + // Go to failed. |
|
| 280 | + $store->mark_failure( $action_id ); |
|
| 281 | + $this->assertFalse( as_has_scheduled_action( 'hook_1' ) ); |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - public function test_as_has_scheduled_action_with_args() { |
|
| 285 | - as_schedule_single_action( time(), 'hook_1', array( 'a' ) ); |
|
| 284 | + public function test_as_has_scheduled_action_with_args() { |
|
| 285 | + as_schedule_single_action( time(), 'hook_1', array( 'a' ) ); |
|
| 286 | 286 | |
| 287 | - $this->assertTrue( as_has_scheduled_action( 'hook_1' ) ); |
|
| 288 | - $this->assertFalse( as_has_scheduled_action( 'hook_1', array( 'b' ) ) ); |
|
| 287 | + $this->assertTrue( as_has_scheduled_action( 'hook_1' ) ); |
|
| 288 | + $this->assertFalse( as_has_scheduled_action( 'hook_1', array( 'b' ) ) ); |
|
| 289 | 289 | |
| 290 | - // Test for any args. |
|
| 291 | - $this->assertTrue( as_has_scheduled_action( 'hook_1', array( 'a' ) ) ); |
|
| 292 | - } |
|
| 290 | + // Test for any args. |
|
| 291 | + $this->assertTrue( as_has_scheduled_action( 'hook_1', array( 'a' ) ) ); |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - public function test_as_has_scheduled_action_with_group() { |
|
| 295 | - as_schedule_single_action( time(), 'hook_1', array(), 'group_1' ); |
|
| 294 | + public function test_as_has_scheduled_action_with_group() { |
|
| 295 | + as_schedule_single_action( time(), 'hook_1', array(), 'group_1' ); |
|
| 296 | 296 | |
| 297 | - $this->assertTrue( as_has_scheduled_action( 'hook_1', null, 'group_1' ) ); |
|
| 298 | - $this->assertTrue( as_has_scheduled_action( 'hook_1', array(), 'group_1' ) ); |
|
| 299 | - } |
|
| 300 | - // phpcs:enable |
|
| 297 | + $this->assertTrue( as_has_scheduled_action( 'hook_1', null, 'group_1' ) ); |
|
| 298 | + $this->assertTrue( as_has_scheduled_action( 'hook_1', array(), 'group_1' ) ); |
|
| 299 | + } |
|
| 300 | + // phpcs:enable |
|
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * Test as_enqueue_async_action with unique param. |
|
| 304 | - */ |
|
| 305 | - public function test_as_enqueue_async_action_unique() { |
|
| 306 | - $this->set_action_scheduler_store( new ActionScheduler_DBStore() ); |
|
| 302 | + /** |
|
| 303 | + * Test as_enqueue_async_action with unique param. |
|
| 304 | + */ |
|
| 305 | + public function test_as_enqueue_async_action_unique() { |
|
| 306 | + $this->set_action_scheduler_store( new ActionScheduler_DBStore() ); |
|
| 307 | 307 | |
| 308 | - $action_id = as_enqueue_async_action( 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 309 | - $this->assertValidAction( $action_id ); |
|
| 308 | + $action_id = as_enqueue_async_action( 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 309 | + $this->assertValidAction( $action_id ); |
|
| 310 | 310 | |
| 311 | - $action_id_duplicate = as_enqueue_async_action( 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 312 | - $this->assertSame( 0, $action_id_duplicate ); |
|
| 313 | - } |
|
| 311 | + $action_id_duplicate = as_enqueue_async_action( 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 312 | + $this->assertSame( 0, $action_id_duplicate ); |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - /** |
|
| 316 | - * Test as_schedule_single_action with unique param. |
|
| 317 | - */ |
|
| 318 | - public function test_as_schedule_single_action_unique() { |
|
| 319 | - $this->set_action_scheduler_store( new ActionScheduler_DBStore() ); |
|
| 320 | - |
|
| 321 | - $action_id = as_schedule_single_action( time(), 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 322 | - $this->assertValidAction( $action_id ); |
|
| 323 | - |
|
| 324 | - $action_id_duplicate = as_schedule_single_action( time(), 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 325 | - $this->assertSame( 0, $action_id_duplicate ); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * Test as_schedule_recurring_action with unique param. |
|
| 330 | - */ |
|
| 331 | - public function test_as_schedule_recurring_action_unique() { |
|
| 332 | - $this->set_action_scheduler_store( new ActionScheduler_DBStore() ); |
|
| 333 | - |
|
| 334 | - $action_id = as_schedule_recurring_action( time(), MINUTE_IN_SECONDS, 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 335 | - $this->assertValidAction( $action_id ); |
|
| 336 | - |
|
| 337 | - $action_id_duplicate = as_schedule_recurring_action( time(), MINUTE_IN_SECONDS, 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 338 | - $this->assertSame( 0, $action_id_duplicate ); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Test as_schedule_cron with unique param. |
|
| 343 | - */ |
|
| 344 | - public function test_as_schedule_cron_action() { |
|
| 345 | - $this->set_action_scheduler_store( new ActionScheduler_DBStore() ); |
|
| 346 | - |
|
| 347 | - $action_id = as_schedule_cron_action( time(), '0 0 * * *', 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 348 | - $this->assertValidAction( $action_id ); |
|
| 349 | - |
|
| 350 | - $action_id_duplicate = as_schedule_cron_action( time(), '0 0 * * *', 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 351 | - $this->assertSame( 0, $action_id_duplicate ); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * Helper method to set actions scheduler store. |
|
| 356 | - * |
|
| 357 | - * @param ActionScheduler_Store $store Store instance to set. |
|
| 358 | - */ |
|
| 359 | - private function set_action_scheduler_store( $store ) { |
|
| 360 | - $store_factory_setter = function () use ( $store ) { |
|
| 361 | - self::$store = $store; |
|
| 362 | - }; |
|
| 363 | - $binded_store_factory_setter = Closure::bind( $store_factory_setter, null, ActionScheduler_Store::class ); |
|
| 364 | - $binded_store_factory_setter(); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * Helper method to assert valid action. |
|
| 369 | - * |
|
| 370 | - * @param int $action_id Action ID to assert. |
|
| 371 | - */ |
|
| 372 | - private function assertValidAction( $action_id ) { |
|
| 373 | - $this->assertNotEquals( 0, $action_id ); |
|
| 374 | - $action = ActionScheduler::store()->fetch_action( $action_id ); |
|
| 375 | - $this->assertInstanceOf( 'ActionScheduler_Action', $action ); |
|
| 376 | - } |
|
| 315 | + /** |
|
| 316 | + * Test as_schedule_single_action with unique param. |
|
| 317 | + */ |
|
| 318 | + public function test_as_schedule_single_action_unique() { |
|
| 319 | + $this->set_action_scheduler_store( new ActionScheduler_DBStore() ); |
|
| 320 | + |
|
| 321 | + $action_id = as_schedule_single_action( time(), 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 322 | + $this->assertValidAction( $action_id ); |
|
| 323 | + |
|
| 324 | + $action_id_duplicate = as_schedule_single_action( time(), 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 325 | + $this->assertSame( 0, $action_id_duplicate ); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * Test as_schedule_recurring_action with unique param. |
|
| 330 | + */ |
|
| 331 | + public function test_as_schedule_recurring_action_unique() { |
|
| 332 | + $this->set_action_scheduler_store( new ActionScheduler_DBStore() ); |
|
| 333 | + |
|
| 334 | + $action_id = as_schedule_recurring_action( time(), MINUTE_IN_SECONDS, 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 335 | + $this->assertValidAction( $action_id ); |
|
| 336 | + |
|
| 337 | + $action_id_duplicate = as_schedule_recurring_action( time(), MINUTE_IN_SECONDS, 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 338 | + $this->assertSame( 0, $action_id_duplicate ); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Test as_schedule_cron with unique param. |
|
| 343 | + */ |
|
| 344 | + public function test_as_schedule_cron_action() { |
|
| 345 | + $this->set_action_scheduler_store( new ActionScheduler_DBStore() ); |
|
| 346 | + |
|
| 347 | + $action_id = as_schedule_cron_action( time(), '0 0 * * *', 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 348 | + $this->assertValidAction( $action_id ); |
|
| 349 | + |
|
| 350 | + $action_id_duplicate = as_schedule_cron_action( time(), '0 0 * * *', 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 351 | + $this->assertSame( 0, $action_id_duplicate ); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * Helper method to set actions scheduler store. |
|
| 356 | + * |
|
| 357 | + * @param ActionScheduler_Store $store Store instance to set. |
|
| 358 | + */ |
|
| 359 | + private function set_action_scheduler_store( $store ) { |
|
| 360 | + $store_factory_setter = function () use ( $store ) { |
|
| 361 | + self::$store = $store; |
|
| 362 | + }; |
|
| 363 | + $binded_store_factory_setter = Closure::bind( $store_factory_setter, null, ActionScheduler_Store::class ); |
|
| 364 | + $binded_store_factory_setter(); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * Helper method to assert valid action. |
|
| 369 | + * |
|
| 370 | + * @param int $action_id Action ID to assert. |
|
| 371 | + */ |
|
| 372 | + private function assertValidAction( $action_id ) { |
|
| 373 | + $this->assertNotEquals( 0, $action_id ); |
|
| 374 | + $action = ActionScheduler::store()->fetch_action( $action_id ); |
|
| 375 | + $this->assertInstanceOf( 'ActionScheduler_Action', $action ); |
|
| 376 | + } |
|
| 377 | 377 | } |
@@ -8,82 +8,82 @@ discard block |
||
| 8 | 8 | // phpcs:disable Squiz.Commenting.FunctionComment.Missing, Squiz.Commenting.FunctionComment.MissingParamTag |
| 9 | 9 | public function test_schedule_action() { |
| 10 | 10 | $time = time(); |
| 11 | - $hook = md5( rand() ); |
|
| 12 | - $action_id = as_schedule_single_action( $time, $hook ); |
|
| 11 | + $hook = md5(rand()); |
|
| 12 | + $action_id = as_schedule_single_action($time, $hook); |
|
| 13 | 13 | |
| 14 | 14 | $store = ActionScheduler::store(); |
| 15 | - $action = $store->fetch_action( $action_id ); |
|
| 16 | - $this->assertEquals( $time, $action->get_schedule()->get_date()->getTimestamp() ); |
|
| 17 | - $this->assertEquals( $hook, $action->get_hook() ); |
|
| 15 | + $action = $store->fetch_action($action_id); |
|
| 16 | + $this->assertEquals($time, $action->get_schedule()->get_date()->getTimestamp()); |
|
| 17 | + $this->assertEquals($hook, $action->get_hook()); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public function test_recurring_action() { |
| 21 | 21 | $time = time(); |
| 22 | - $hook = md5( rand() ); |
|
| 23 | - $action_id = as_schedule_recurring_action( $time, HOUR_IN_SECONDS, $hook ); |
|
| 22 | + $hook = md5(rand()); |
|
| 23 | + $action_id = as_schedule_recurring_action($time, HOUR_IN_SECONDS, $hook); |
|
| 24 | 24 | |
| 25 | 25 | $store = ActionScheduler::store(); |
| 26 | - $action = $store->fetch_action( $action_id ); |
|
| 27 | - $this->assertEquals( $time, $action->get_schedule()->get_date()->getTimestamp() ); |
|
| 28 | - $this->assertEquals( $time + HOUR_IN_SECONDS + 2, $action->get_schedule()->get_next( as_get_datetime_object( $time + 2 ) )->getTimestamp() ); |
|
| 29 | - $this->assertEquals( $hook, $action->get_hook() ); |
|
| 26 | + $action = $store->fetch_action($action_id); |
|
| 27 | + $this->assertEquals($time, $action->get_schedule()->get_date()->getTimestamp()); |
|
| 28 | + $this->assertEquals($time + HOUR_IN_SECONDS + 2, $action->get_schedule()->get_next(as_get_datetime_object($time + 2))->getTimestamp()); |
|
| 29 | + $this->assertEquals($hook, $action->get_hook()); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function test_cron_schedule() { |
| 33 | - $time = as_get_datetime_object( '2014-01-01' ); |
|
| 34 | - $hook = md5( rand() ); |
|
| 35 | - $action_id = as_schedule_cron_action( $time->getTimestamp(), '0 0 10 10 *', $hook ); |
|
| 33 | + $time = as_get_datetime_object('2014-01-01'); |
|
| 34 | + $hook = md5(rand()); |
|
| 35 | + $action_id = as_schedule_cron_action($time->getTimestamp(), '0 0 10 10 *', $hook); |
|
| 36 | 36 | |
| 37 | 37 | $store = ActionScheduler::store(); |
| 38 | - $action = $store->fetch_action( $action_id ); |
|
| 39 | - $expected_date = as_get_datetime_object( '2014-10-10' ); |
|
| 40 | - $this->assertEquals( $expected_date->getTimestamp(), $action->get_schedule()->get_date()->getTimestamp() ); |
|
| 41 | - $this->assertEquals( $hook, $action->get_hook() ); |
|
| 38 | + $action = $store->fetch_action($action_id); |
|
| 39 | + $expected_date = as_get_datetime_object('2014-10-10'); |
|
| 40 | + $this->assertEquals($expected_date->getTimestamp(), $action->get_schedule()->get_date()->getTimestamp()); |
|
| 41 | + $this->assertEquals($hook, $action->get_hook()); |
|
| 42 | 42 | |
| 43 | - $expected_date = as_get_datetime_object( '2015-10-10' ); |
|
| 44 | - $this->assertEquals( $expected_date->getTimestamp(), $action->get_schedule()->get_next( as_get_datetime_object( '2015-01-02' ) )->getTimestamp() ); |
|
| 43 | + $expected_date = as_get_datetime_object('2015-10-10'); |
|
| 44 | + $this->assertEquals($expected_date->getTimestamp(), $action->get_schedule()->get_next(as_get_datetime_object('2015-01-02'))->getTimestamp()); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | public function test_get_next() { |
| 48 | - $time = as_get_datetime_object( 'tomorrow' ); |
|
| 49 | - $hook = md5( rand() ); |
|
| 50 | - as_schedule_recurring_action( $time->getTimestamp(), HOUR_IN_SECONDS, $hook ); |
|
| 48 | + $time = as_get_datetime_object('tomorrow'); |
|
| 49 | + $hook = md5(rand()); |
|
| 50 | + as_schedule_recurring_action($time->getTimestamp(), HOUR_IN_SECONDS, $hook); |
|
| 51 | 51 | |
| 52 | - $next = as_next_scheduled_action( $hook ); |
|
| 52 | + $next = as_next_scheduled_action($hook); |
|
| 53 | 53 | |
| 54 | - $this->assertEquals( $time->getTimestamp(), $next ); |
|
| 54 | + $this->assertEquals($time->getTimestamp(), $next); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | public function test_get_next_async() { |
| 58 | - $hook = md5( rand() ); |
|
| 59 | - $action_id = as_enqueue_async_action( $hook ); |
|
| 58 | + $hook = md5(rand()); |
|
| 59 | + $action_id = as_enqueue_async_action($hook); |
|
| 60 | 60 | |
| 61 | - $next = as_next_scheduled_action( $hook ); |
|
| 61 | + $next = as_next_scheduled_action($hook); |
|
| 62 | 62 | |
| 63 | - $this->assertTrue( $next ); |
|
| 63 | + $this->assertTrue($next); |
|
| 64 | 64 | |
| 65 | 65 | $store = ActionScheduler::store(); |
| 66 | 66 | |
| 67 | 67 | // Completed async actions should still return false. |
| 68 | - $store->mark_complete( $action_id ); |
|
| 69 | - $next = as_next_scheduled_action( $hook ); |
|
| 70 | - $this->assertFalse( $next ); |
|
| 68 | + $store->mark_complete($action_id); |
|
| 69 | + $next = as_next_scheduled_action($hook); |
|
| 70 | + $this->assertFalse($next); |
|
| 71 | 71 | |
| 72 | 72 | // Failed async actions should still return false. |
| 73 | - $store->mark_failure( $action_id ); |
|
| 74 | - $next = as_next_scheduled_action( $hook ); |
|
| 75 | - $this->assertFalse( $next ); |
|
| 73 | + $store->mark_failure($action_id); |
|
| 74 | + $next = as_next_scheduled_action($hook); |
|
| 75 | + $this->assertFalse($next); |
|
| 76 | 76 | |
| 77 | 77 | // Cancelled async actions should still return false. |
| 78 | - $store->cancel_action( $action_id ); |
|
| 79 | - $next = as_next_scheduled_action( $hook ); |
|
| 80 | - $this->assertFalse( $next ); |
|
| 78 | + $store->cancel_action($action_id); |
|
| 79 | + $next = as_next_scheduled_action($hook); |
|
| 80 | + $this->assertFalse($next); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | public function provider_time_hook_args_group() { |
| 84 | 84 | $time = time() + 60 * 2; |
| 85 | - $hook = md5( rand() ); |
|
| 86 | - $args = array( rand(), rand() ); |
|
| 85 | + $hook = md5(rand()); |
|
| 86 | + $args = array(rand(), rand()); |
|
| 87 | 87 | $group = 'test_group'; |
| 88 | 88 | |
| 89 | 89 | return array( |
@@ -125,99 +125,99 @@ discard block |
||
| 125 | 125 | /** |
| 126 | 126 | * @dataProvider provider_time_hook_args_group |
| 127 | 127 | */ |
| 128 | - public function test_unschedule( $time, $hook, $args, $group ) { |
|
| 128 | + public function test_unschedule($time, $hook, $args, $group) { |
|
| 129 | 129 | |
| 130 | - $action_id_unscheduled = as_schedule_single_action( $time, $hook, $args, $group ); |
|
| 130 | + $action_id_unscheduled = as_schedule_single_action($time, $hook, $args, $group); |
|
| 131 | 131 | $action_scheduled_time = $time + 1; |
| 132 | - $action_id_scheduled = as_schedule_single_action( $action_scheduled_time, $hook, $args, $group ); |
|
| 132 | + $action_id_scheduled = as_schedule_single_action($action_scheduled_time, $hook, $args, $group); |
|
| 133 | 133 | |
| 134 | - as_unschedule_action( $hook, $args, $group ); |
|
| 134 | + as_unschedule_action($hook, $args, $group); |
|
| 135 | 135 | |
| 136 | - $next = as_next_scheduled_action( $hook, $args, $group ); |
|
| 137 | - $this->assertEquals( $action_scheduled_time, $next ); |
|
| 136 | + $next = as_next_scheduled_action($hook, $args, $group); |
|
| 137 | + $this->assertEquals($action_scheduled_time, $next); |
|
| 138 | 138 | |
| 139 | 139 | $store = ActionScheduler::store(); |
| 140 | - $unscheduled_action = $store->fetch_action( $action_id_unscheduled ); |
|
| 140 | + $unscheduled_action = $store->fetch_action($action_id_unscheduled); |
|
| 141 | 141 | |
| 142 | 142 | // Make sure the next scheduled action is unscheduled. |
| 143 | - $this->assertEquals( $hook, $unscheduled_action->get_hook() ); |
|
| 144 | - $this->assertEquals( as_get_datetime_object( $time ), $unscheduled_action->get_schedule()->get_date() ); |
|
| 145 | - $this->assertEquals( ActionScheduler_Store::STATUS_CANCELED, $store->get_status( $action_id_unscheduled ) ); |
|
| 146 | - $this->assertNull( $unscheduled_action->get_schedule()->get_next( as_get_datetime_object() ) ); |
|
| 143 | + $this->assertEquals($hook, $unscheduled_action->get_hook()); |
|
| 144 | + $this->assertEquals(as_get_datetime_object($time), $unscheduled_action->get_schedule()->get_date()); |
|
| 145 | + $this->assertEquals(ActionScheduler_Store::STATUS_CANCELED, $store->get_status($action_id_unscheduled)); |
|
| 146 | + $this->assertNull($unscheduled_action->get_schedule()->get_next(as_get_datetime_object())); |
|
| 147 | 147 | |
| 148 | 148 | // Make sure other scheduled actions are not unscheduled. |
| 149 | - $this->assertEquals( ActionScheduler_Store::STATUS_PENDING, $store->get_status( $action_id_scheduled ) ); |
|
| 150 | - $scheduled_action = $store->fetch_action( $action_id_scheduled ); |
|
| 149 | + $this->assertEquals(ActionScheduler_Store::STATUS_PENDING, $store->get_status($action_id_scheduled)); |
|
| 150 | + $scheduled_action = $store->fetch_action($action_id_scheduled); |
|
| 151 | 151 | |
| 152 | - $this->assertEquals( $hook, $scheduled_action->get_hook() ); |
|
| 153 | - $this->assertEquals( $action_scheduled_time, $scheduled_action->get_schedule()->get_date()->getTimestamp() ); |
|
| 152 | + $this->assertEquals($hook, $scheduled_action->get_hook()); |
|
| 153 | + $this->assertEquals($action_scheduled_time, $scheduled_action->get_schedule()->get_date()->getTimestamp()); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
| 157 | 157 | * @dataProvider provider_time_hook_args_group |
| 158 | 158 | */ |
| 159 | - public function test_unschedule_all( $time, $hook, $args, $group ) { |
|
| 159 | + public function test_unschedule_all($time, $hook, $args, $group) { |
|
| 160 | 160 | |
| 161 | - $hook = md5( $hook ); |
|
| 161 | + $hook = md5($hook); |
|
| 162 | 162 | $action_ids = array(); |
| 163 | 163 | |
| 164 | - for ( $i = 0; $i < 3; $i++ ) { |
|
| 165 | - $action_ids[] = as_schedule_single_action( $time, $hook, $args, $group ); |
|
| 164 | + for ($i = 0; $i < 3; $i++) { |
|
| 165 | + $action_ids[] = as_schedule_single_action($time, $hook, $args, $group); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - as_unschedule_all_actions( $hook, $args, $group ); |
|
| 168 | + as_unschedule_all_actions($hook, $args, $group); |
|
| 169 | 169 | |
| 170 | - $next = as_next_scheduled_action( $hook ); |
|
| 171 | - $this->assertFalse( $next ); |
|
| 170 | + $next = as_next_scheduled_action($hook); |
|
| 171 | + $this->assertFalse($next); |
|
| 172 | 172 | |
| 173 | - $after = as_get_datetime_object( $time ); |
|
| 174 | - $after->modify( '+1 minute' ); |
|
| 173 | + $after = as_get_datetime_object($time); |
|
| 174 | + $after->modify('+1 minute'); |
|
| 175 | 175 | |
| 176 | 176 | $store = ActionScheduler::store(); |
| 177 | 177 | |
| 178 | - foreach ( $action_ids as $action_id ) { |
|
| 179 | - $action = $store->fetch_action( $action_id ); |
|
| 178 | + foreach ($action_ids as $action_id) { |
|
| 179 | + $action = $store->fetch_action($action_id); |
|
| 180 | 180 | |
| 181 | - $this->assertEquals( $hook, $action->get_hook() ); |
|
| 182 | - $this->assertEquals( as_get_datetime_object( $time ), $action->get_schedule()->get_date() ); |
|
| 183 | - $this->assertEquals( ActionScheduler_Store::STATUS_CANCELED, $store->get_status( $action_id ) ); |
|
| 184 | - $this->assertNull( $action->get_schedule()->get_next( $after ) ); |
|
| 181 | + $this->assertEquals($hook, $action->get_hook()); |
|
| 182 | + $this->assertEquals(as_get_datetime_object($time), $action->get_schedule()->get_date()); |
|
| 183 | + $this->assertEquals(ActionScheduler_Store::STATUS_CANCELED, $store->get_status($action_id)); |
|
| 184 | + $this->assertNull($action->get_schedule()->get_next($after)); |
|
| 185 | 185 | } |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | public function test_as_get_datetime_object_default() { |
| 189 | 189 | |
| 190 | - $utc_now = new ActionScheduler_DateTime( null, new DateTimeZone( 'UTC' ) ); |
|
| 190 | + $utc_now = new ActionScheduler_DateTime(null, new DateTimeZone('UTC')); |
|
| 191 | 191 | $as_now = as_get_datetime_object(); |
| 192 | 192 | |
| 193 | 193 | // Don't want to use 'U' as timestamps will always be in UTC. |
| 194 | - $this->assertEquals( $utc_now->format( 'Y-m-d H:i:s' ), $as_now->format( 'Y-m-d H:i:s' ) ); |
|
| 194 | + $this->assertEquals($utc_now->format('Y-m-d H:i:s'), $as_now->format('Y-m-d H:i:s')); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | public function test_as_get_datetime_object_relative() { |
| 198 | 198 | |
| 199 | - $utc_tomorrow = new ActionScheduler_DateTime( 'tomorrow', new DateTimeZone( 'UTC' ) ); |
|
| 200 | - $as_tomorrow = as_get_datetime_object( 'tomorrow' ); |
|
| 199 | + $utc_tomorrow = new ActionScheduler_DateTime('tomorrow', new DateTimeZone('UTC')); |
|
| 200 | + $as_tomorrow = as_get_datetime_object('tomorrow'); |
|
| 201 | 201 | |
| 202 | - $this->assertEquals( $utc_tomorrow->format( 'Y-m-d H:i:s' ), $as_tomorrow->format( 'Y-m-d H:i:s' ) ); |
|
| 202 | + $this->assertEquals($utc_tomorrow->format('Y-m-d H:i:s'), $as_tomorrow->format('Y-m-d H:i:s')); |
|
| 203 | 203 | |
| 204 | - $utc_tomorrow = new ActionScheduler_DateTime( 'yesterday', new DateTimeZone( 'UTC' ) ); |
|
| 205 | - $as_tomorrow = as_get_datetime_object( 'yesterday' ); |
|
| 204 | + $utc_tomorrow = new ActionScheduler_DateTime('yesterday', new DateTimeZone('UTC')); |
|
| 205 | + $as_tomorrow = as_get_datetime_object('yesterday'); |
|
| 206 | 206 | |
| 207 | - $this->assertEquals( $utc_tomorrow->format( 'Y-m-d H:i:s' ), $as_tomorrow->format( 'Y-m-d H:i:s' ) ); |
|
| 207 | + $this->assertEquals($utc_tomorrow->format('Y-m-d H:i:s'), $as_tomorrow->format('Y-m-d H:i:s')); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | public function test_as_get_datetime_object_fixed() { |
| 211 | 211 | |
| 212 | - $utc_tomorrow = new ActionScheduler_DateTime( '29 February 2016', new DateTimeZone( 'UTC' ) ); |
|
| 213 | - $as_tomorrow = as_get_datetime_object( '29 February 2016' ); |
|
| 212 | + $utc_tomorrow = new ActionScheduler_DateTime('29 February 2016', new DateTimeZone('UTC')); |
|
| 213 | + $as_tomorrow = as_get_datetime_object('29 February 2016'); |
|
| 214 | 214 | |
| 215 | - $this->assertEquals( $utc_tomorrow->format( 'Y-m-d H:i:s' ), $as_tomorrow->format( 'Y-m-d H:i:s' ) ); |
|
| 215 | + $this->assertEquals($utc_tomorrow->format('Y-m-d H:i:s'), $as_tomorrow->format('Y-m-d H:i:s')); |
|
| 216 | 216 | |
| 217 | - $utc_tomorrow = new ActionScheduler_DateTime( '1st January 2024', new DateTimeZone( 'UTC' ) ); |
|
| 218 | - $as_tomorrow = as_get_datetime_object( '1st January 2024' ); |
|
| 217 | + $utc_tomorrow = new ActionScheduler_DateTime('1st January 2024', new DateTimeZone('UTC')); |
|
| 218 | + $as_tomorrow = as_get_datetime_object('1st January 2024'); |
|
| 219 | 219 | |
| 220 | - $this->assertEquals( $utc_tomorrow->format( 'Y-m-d H:i:s' ), $as_tomorrow->format( 'Y-m-d H:i:s' ) ); |
|
| 220 | + $this->assertEquals($utc_tomorrow->format('Y-m-d H:i:s'), $as_tomorrow->format('Y-m-d H:i:s')); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | public function test_as_get_datetime_object_timezone() { |
@@ -226,76 +226,76 @@ discard block |
||
| 226 | 226 | $timezone_default = date_default_timezone_get(); |
| 227 | 227 | |
| 228 | 228 | // phpcs:ignore |
| 229 | - date_default_timezone_set( $timezone_au ); |
|
| 229 | + date_default_timezone_set($timezone_au); |
|
| 230 | 230 | |
| 231 | - $au_now = new ActionScheduler_DateTime( null ); |
|
| 231 | + $au_now = new ActionScheduler_DateTime(null); |
|
| 232 | 232 | $as_now = as_get_datetime_object(); |
| 233 | 233 | |
| 234 | 234 | // Make sure they're for the same time. |
| 235 | - $this->assertEquals( $au_now->getTimestamp(), $as_now->getTimestamp() ); |
|
| 235 | + $this->assertEquals($au_now->getTimestamp(), $as_now->getTimestamp()); |
|
| 236 | 236 | |
| 237 | 237 | // But not in the same timezone, as $as_now should be using UTC. |
| 238 | - $this->assertNotEquals( $au_now->format( 'Y-m-d H:i:s' ), $as_now->format( 'Y-m-d H:i:s' ) ); |
|
| 238 | + $this->assertNotEquals($au_now->format('Y-m-d H:i:s'), $as_now->format('Y-m-d H:i:s')); |
|
| 239 | 239 | |
| 240 | - $au_now = new ActionScheduler_DateTime( null ); |
|
| 240 | + $au_now = new ActionScheduler_DateTime(null); |
|
| 241 | 241 | $as_au_now = as_get_datetime_object(); |
| 242 | 242 | |
| 243 | - $this->assertEquals( $au_now->getTimestamp(), $as_now->getTimestamp(), '', 2 ); |
|
| 243 | + $this->assertEquals($au_now->getTimestamp(), $as_now->getTimestamp(), '', 2); |
|
| 244 | 244 | |
| 245 | 245 | // But not in the same timezone, as $as_now should be using UTC. |
| 246 | - $this->assertNotEquals( $au_now->format( 'Y-m-d H:i:s' ), $as_now->format( 'Y-m-d H:i:s' ) ); |
|
| 246 | + $this->assertNotEquals($au_now->format('Y-m-d H:i:s'), $as_now->format('Y-m-d H:i:s')); |
|
| 247 | 247 | |
| 248 | 248 | // phpcs:ignore |
| 249 | - date_default_timezone_set( $timezone_default ); |
|
| 249 | + date_default_timezone_set($timezone_default); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | public function test_as_get_datetime_object_type() { |
| 253 | 253 | $f = 'Y-m-d H:i:s'; |
| 254 | 254 | $now = as_get_datetime_object(); |
| 255 | - $this->assertInstanceOf( 'ActionScheduler_DateTime', $now ); |
|
| 255 | + $this->assertInstanceOf('ActionScheduler_DateTime', $now); |
|
| 256 | 256 | |
| 257 | - $datetime = new DateTime( 'now', new DateTimeZone( 'UTC' ) ); |
|
| 258 | - $as_datetime = as_get_datetime_object( $datetime ); |
|
| 259 | - $this->assertEquals( $datetime->format( $f ), $as_datetime->format( $f ) ); |
|
| 257 | + $datetime = new DateTime('now', new DateTimeZone('UTC')); |
|
| 258 | + $as_datetime = as_get_datetime_object($datetime); |
|
| 259 | + $this->assertEquals($datetime->format($f), $as_datetime->format($f)); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | public function test_as_has_scheduled_action() { |
| 263 | 263 | $store = ActionScheduler::store(); |
| 264 | 264 | |
| 265 | - $time = as_get_datetime_object( 'tomorrow' ); |
|
| 266 | - $action_id = as_schedule_single_action( $time->getTimestamp(), 'hook_1' ); |
|
| 265 | + $time = as_get_datetime_object('tomorrow'); |
|
| 266 | + $action_id = as_schedule_single_action($time->getTimestamp(), 'hook_1'); |
|
| 267 | 267 | |
| 268 | - $this->assertTrue( as_has_scheduled_action( 'hook_1' ) ); |
|
| 269 | - $this->assertFalse( as_has_scheduled_action( 'hook_2' ) ); |
|
| 268 | + $this->assertTrue(as_has_scheduled_action('hook_1')); |
|
| 269 | + $this->assertFalse(as_has_scheduled_action('hook_2')); |
|
| 270 | 270 | |
| 271 | 271 | // Go to in-progress. |
| 272 | - $store->log_execution( $action_id ); |
|
| 273 | - $this->assertTrue( as_has_scheduled_action( 'hook_1' ) ); |
|
| 272 | + $store->log_execution($action_id); |
|
| 273 | + $this->assertTrue(as_has_scheduled_action('hook_1')); |
|
| 274 | 274 | |
| 275 | 275 | // Go to complete. |
| 276 | - $store->mark_complete( $action_id ); |
|
| 277 | - $this->assertFalse( as_has_scheduled_action( 'hook_1' ) ); |
|
| 276 | + $store->mark_complete($action_id); |
|
| 277 | + $this->assertFalse(as_has_scheduled_action('hook_1')); |
|
| 278 | 278 | |
| 279 | 279 | // Go to failed. |
| 280 | - $store->mark_failure( $action_id ); |
|
| 281 | - $this->assertFalse( as_has_scheduled_action( 'hook_1' ) ); |
|
| 280 | + $store->mark_failure($action_id); |
|
| 281 | + $this->assertFalse(as_has_scheduled_action('hook_1')); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | public function test_as_has_scheduled_action_with_args() { |
| 285 | - as_schedule_single_action( time(), 'hook_1', array( 'a' ) ); |
|
| 285 | + as_schedule_single_action(time(), 'hook_1', array('a')); |
|
| 286 | 286 | |
| 287 | - $this->assertTrue( as_has_scheduled_action( 'hook_1' ) ); |
|
| 288 | - $this->assertFalse( as_has_scheduled_action( 'hook_1', array( 'b' ) ) ); |
|
| 287 | + $this->assertTrue(as_has_scheduled_action('hook_1')); |
|
| 288 | + $this->assertFalse(as_has_scheduled_action('hook_1', array('b'))); |
|
| 289 | 289 | |
| 290 | 290 | // Test for any args. |
| 291 | - $this->assertTrue( as_has_scheduled_action( 'hook_1', array( 'a' ) ) ); |
|
| 291 | + $this->assertTrue(as_has_scheduled_action('hook_1', array('a'))); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | public function test_as_has_scheduled_action_with_group() { |
| 295 | - as_schedule_single_action( time(), 'hook_1', array(), 'group_1' ); |
|
| 295 | + as_schedule_single_action(time(), 'hook_1', array(), 'group_1'); |
|
| 296 | 296 | |
| 297 | - $this->assertTrue( as_has_scheduled_action( 'hook_1', null, 'group_1' ) ); |
|
| 298 | - $this->assertTrue( as_has_scheduled_action( 'hook_1', array(), 'group_1' ) ); |
|
| 297 | + $this->assertTrue(as_has_scheduled_action('hook_1', null, 'group_1')); |
|
| 298 | + $this->assertTrue(as_has_scheduled_action('hook_1', array(), 'group_1')); |
|
| 299 | 299 | } |
| 300 | 300 | // phpcs:enable |
| 301 | 301 | |
@@ -303,52 +303,52 @@ discard block |
||
| 303 | 303 | * Test as_enqueue_async_action with unique param. |
| 304 | 304 | */ |
| 305 | 305 | public function test_as_enqueue_async_action_unique() { |
| 306 | - $this->set_action_scheduler_store( new ActionScheduler_DBStore() ); |
|
| 306 | + $this->set_action_scheduler_store(new ActionScheduler_DBStore()); |
|
| 307 | 307 | |
| 308 | - $action_id = as_enqueue_async_action( 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 309 | - $this->assertValidAction( $action_id ); |
|
| 308 | + $action_id = as_enqueue_async_action('hook_1', array('a'), 'dummy', true); |
|
| 309 | + $this->assertValidAction($action_id); |
|
| 310 | 310 | |
| 311 | - $action_id_duplicate = as_enqueue_async_action( 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 312 | - $this->assertSame( 0, $action_id_duplicate ); |
|
| 311 | + $action_id_duplicate = as_enqueue_async_action('hook_1', array('a'), 'dummy', true); |
|
| 312 | + $this->assertSame(0, $action_id_duplicate); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | /** |
| 316 | 316 | * Test as_schedule_single_action with unique param. |
| 317 | 317 | */ |
| 318 | 318 | public function test_as_schedule_single_action_unique() { |
| 319 | - $this->set_action_scheduler_store( new ActionScheduler_DBStore() ); |
|
| 319 | + $this->set_action_scheduler_store(new ActionScheduler_DBStore()); |
|
| 320 | 320 | |
| 321 | - $action_id = as_schedule_single_action( time(), 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 322 | - $this->assertValidAction( $action_id ); |
|
| 321 | + $action_id = as_schedule_single_action(time(), 'hook_1', array('a'), 'dummy', true); |
|
| 322 | + $this->assertValidAction($action_id); |
|
| 323 | 323 | |
| 324 | - $action_id_duplicate = as_schedule_single_action( time(), 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 325 | - $this->assertSame( 0, $action_id_duplicate ); |
|
| 324 | + $action_id_duplicate = as_schedule_single_action(time(), 'hook_1', array('a'), 'dummy', true); |
|
| 325 | + $this->assertSame(0, $action_id_duplicate); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
| 329 | 329 | * Test as_schedule_recurring_action with unique param. |
| 330 | 330 | */ |
| 331 | 331 | public function test_as_schedule_recurring_action_unique() { |
| 332 | - $this->set_action_scheduler_store( new ActionScheduler_DBStore() ); |
|
| 332 | + $this->set_action_scheduler_store(new ActionScheduler_DBStore()); |
|
| 333 | 333 | |
| 334 | - $action_id = as_schedule_recurring_action( time(), MINUTE_IN_SECONDS, 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 335 | - $this->assertValidAction( $action_id ); |
|
| 334 | + $action_id = as_schedule_recurring_action(time(), MINUTE_IN_SECONDS, 'hook_1', array('a'), 'dummy', true); |
|
| 335 | + $this->assertValidAction($action_id); |
|
| 336 | 336 | |
| 337 | - $action_id_duplicate = as_schedule_recurring_action( time(), MINUTE_IN_SECONDS, 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 338 | - $this->assertSame( 0, $action_id_duplicate ); |
|
| 337 | + $action_id_duplicate = as_schedule_recurring_action(time(), MINUTE_IN_SECONDS, 'hook_1', array('a'), 'dummy', true); |
|
| 338 | + $this->assertSame(0, $action_id_duplicate); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** |
| 342 | 342 | * Test as_schedule_cron with unique param. |
| 343 | 343 | */ |
| 344 | 344 | public function test_as_schedule_cron_action() { |
| 345 | - $this->set_action_scheduler_store( new ActionScheduler_DBStore() ); |
|
| 345 | + $this->set_action_scheduler_store(new ActionScheduler_DBStore()); |
|
| 346 | 346 | |
| 347 | - $action_id = as_schedule_cron_action( time(), '0 0 * * *', 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 348 | - $this->assertValidAction( $action_id ); |
|
| 347 | + $action_id = as_schedule_cron_action(time(), '0 0 * * *', 'hook_1', array('a'), 'dummy', true); |
|
| 348 | + $this->assertValidAction($action_id); |
|
| 349 | 349 | |
| 350 | - $action_id_duplicate = as_schedule_cron_action( time(), '0 0 * * *', 'hook_1', array( 'a' ), 'dummy', true ); |
|
| 351 | - $this->assertSame( 0, $action_id_duplicate ); |
|
| 350 | + $action_id_duplicate = as_schedule_cron_action(time(), '0 0 * * *', 'hook_1', array('a'), 'dummy', true); |
|
| 351 | + $this->assertSame(0, $action_id_duplicate); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** |
@@ -356,11 +356,11 @@ discard block |
||
| 356 | 356 | * |
| 357 | 357 | * @param ActionScheduler_Store $store Store instance to set. |
| 358 | 358 | */ |
| 359 | - private function set_action_scheduler_store( $store ) { |
|
| 360 | - $store_factory_setter = function () use ( $store ) { |
|
| 359 | + private function set_action_scheduler_store($store) { |
|
| 360 | + $store_factory_setter = function() use ($store) { |
|
| 361 | 361 | self::$store = $store; |
| 362 | 362 | }; |
| 363 | - $binded_store_factory_setter = Closure::bind( $store_factory_setter, null, ActionScheduler_Store::class ); |
|
| 363 | + $binded_store_factory_setter = Closure::bind($store_factory_setter, null, ActionScheduler_Store::class); |
|
| 364 | 364 | $binded_store_factory_setter(); |
| 365 | 365 | } |
| 366 | 366 | |
@@ -369,9 +369,9 @@ discard block |
||
| 369 | 369 | * |
| 370 | 370 | * @param int $action_id Action ID to assert. |
| 371 | 371 | */ |
| 372 | - private function assertValidAction( $action_id ) { |
|
| 373 | - $this->assertNotEquals( 0, $action_id ); |
|
| 374 | - $action = ActionScheduler::store()->fetch_action( $action_id ); |
|
| 375 | - $this->assertInstanceOf( 'ActionScheduler_Action', $action ); |
|
| 372 | + private function assertValidAction($action_id) { |
|
| 373 | + $this->assertNotEquals(0, $action_id); |
|
| 374 | + $action = ActionScheduler::store()->fetch_action($action_id); |
|
| 375 | + $this->assertInstanceOf('ActionScheduler_Action', $action); |
|
| 376 | 376 | } |
| 377 | 377 | } |
@@ -4,40 +4,40 @@ |
||
| 4 | 4 | * Class ActionScheduler_Versions_Test |
| 5 | 5 | */ |
| 6 | 6 | class ActionScheduler_Versions_Test extends ActionScheduler_UnitTestCase { |
| 7 | - public function test_register_version() { |
|
| 8 | - $versions = new ActionScheduler_Versions(); |
|
| 9 | - $versions->register( '1.0-dev', 'callback_1_dot_0_dev' ); |
|
| 10 | - $versions->register( '1.0', 'callback_1_dot_0' ); |
|
| 7 | + public function test_register_version() { |
|
| 8 | + $versions = new ActionScheduler_Versions(); |
|
| 9 | + $versions->register( '1.0-dev', 'callback_1_dot_0_dev' ); |
|
| 10 | + $versions->register( '1.0', 'callback_1_dot_0' ); |
|
| 11 | 11 | |
| 12 | - $registered = $versions->get_versions(); |
|
| 12 | + $registered = $versions->get_versions(); |
|
| 13 | 13 | |
| 14 | - $this->assertArrayHasKey( '1.0-dev', $registered ); |
|
| 15 | - $this->assertArrayHasKey( '1.0', $registered ); |
|
| 16 | - $this->assertCount( 2, $registered ); |
|
| 14 | + $this->assertArrayHasKey( '1.0-dev', $registered ); |
|
| 15 | + $this->assertArrayHasKey( '1.0', $registered ); |
|
| 16 | + $this->assertCount( 2, $registered ); |
|
| 17 | 17 | |
| 18 | - $this->assertEquals( 'callback_1_dot_0_dev', $registered['1.0-dev'] ); |
|
| 19 | - } |
|
| 18 | + $this->assertEquals( 'callback_1_dot_0_dev', $registered['1.0-dev'] ); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - public function test_duplicate_version() { |
|
| 22 | - $versions = new ActionScheduler_Versions(); |
|
| 23 | - $versions->register( '1.0', 'callback_1_dot_0_a' ); |
|
| 24 | - $versions->register( '1.0', 'callback_1_dot_0_b' ); |
|
| 21 | + public function test_duplicate_version() { |
|
| 22 | + $versions = new ActionScheduler_Versions(); |
|
| 23 | + $versions->register( '1.0', 'callback_1_dot_0_a' ); |
|
| 24 | + $versions->register( '1.0', 'callback_1_dot_0_b' ); |
|
| 25 | 25 | |
| 26 | - $registered = $versions->get_versions(); |
|
| 26 | + $registered = $versions->get_versions(); |
|
| 27 | 27 | |
| 28 | - $this->assertArrayHasKey( '1.0', $registered ); |
|
| 29 | - $this->assertCount( 1, $registered ); |
|
| 30 | - } |
|
| 28 | + $this->assertArrayHasKey( '1.0', $registered ); |
|
| 29 | + $this->assertCount( 1, $registered ); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function test_latest_version() { |
|
| 33 | - $versions = new ActionScheduler_Versions(); |
|
| 34 | - $this->assertEquals( '__return_null', $versions->latest_version_callback() ); |
|
| 35 | - $versions->register( '1.2', 'callback_1_dot_2' ); |
|
| 36 | - $versions->register( '1.3', 'callback_1_dot_3' ); |
|
| 37 | - $versions->register( '1.0', 'callback_1_dot_0' ); |
|
| 32 | + public function test_latest_version() { |
|
| 33 | + $versions = new ActionScheduler_Versions(); |
|
| 34 | + $this->assertEquals( '__return_null', $versions->latest_version_callback() ); |
|
| 35 | + $versions->register( '1.2', 'callback_1_dot_2' ); |
|
| 36 | + $versions->register( '1.3', 'callback_1_dot_3' ); |
|
| 37 | + $versions->register( '1.0', 'callback_1_dot_0' ); |
|
| 38 | 38 | |
| 39 | - $this->assertSame( '1.3', $versions->latest_version() ); |
|
| 40 | - $this->assertEquals( 'callback_1_dot_3', $versions->latest_version_callback() ); |
|
| 41 | - } |
|
| 39 | + $this->assertSame( '1.3', $versions->latest_version() ); |
|
| 40 | + $this->assertEquals( 'callback_1_dot_3', $versions->latest_version_callback() ); |
|
| 41 | + } |
|
| 42 | 42 | } |
| 43 | 43 | |
@@ -6,38 +6,38 @@ |
||
| 6 | 6 | class ActionScheduler_Versions_Test extends ActionScheduler_UnitTestCase { |
| 7 | 7 | public function test_register_version() { |
| 8 | 8 | $versions = new ActionScheduler_Versions(); |
| 9 | - $versions->register( '1.0-dev', 'callback_1_dot_0_dev' ); |
|
| 10 | - $versions->register( '1.0', 'callback_1_dot_0' ); |
|
| 9 | + $versions->register('1.0-dev', 'callback_1_dot_0_dev'); |
|
| 10 | + $versions->register('1.0', 'callback_1_dot_0'); |
|
| 11 | 11 | |
| 12 | 12 | $registered = $versions->get_versions(); |
| 13 | 13 | |
| 14 | - $this->assertArrayHasKey( '1.0-dev', $registered ); |
|
| 15 | - $this->assertArrayHasKey( '1.0', $registered ); |
|
| 16 | - $this->assertCount( 2, $registered ); |
|
| 14 | + $this->assertArrayHasKey('1.0-dev', $registered); |
|
| 15 | + $this->assertArrayHasKey('1.0', $registered); |
|
| 16 | + $this->assertCount(2, $registered); |
|
| 17 | 17 | |
| 18 | - $this->assertEquals( 'callback_1_dot_0_dev', $registered['1.0-dev'] ); |
|
| 18 | + $this->assertEquals('callback_1_dot_0_dev', $registered['1.0-dev']); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function test_duplicate_version() { |
| 22 | 22 | $versions = new ActionScheduler_Versions(); |
| 23 | - $versions->register( '1.0', 'callback_1_dot_0_a' ); |
|
| 24 | - $versions->register( '1.0', 'callback_1_dot_0_b' ); |
|
| 23 | + $versions->register('1.0', 'callback_1_dot_0_a'); |
|
| 24 | + $versions->register('1.0', 'callback_1_dot_0_b'); |
|
| 25 | 25 | |
| 26 | 26 | $registered = $versions->get_versions(); |
| 27 | 27 | |
| 28 | - $this->assertArrayHasKey( '1.0', $registered ); |
|
| 29 | - $this->assertCount( 1, $registered ); |
|
| 28 | + $this->assertArrayHasKey('1.0', $registered); |
|
| 29 | + $this->assertCount(1, $registered); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function test_latest_version() { |
| 33 | 33 | $versions = new ActionScheduler_Versions(); |
| 34 | - $this->assertEquals( '__return_null', $versions->latest_version_callback() ); |
|
| 35 | - $versions->register( '1.2', 'callback_1_dot_2' ); |
|
| 36 | - $versions->register( '1.3', 'callback_1_dot_3' ); |
|
| 37 | - $versions->register( '1.0', 'callback_1_dot_0' ); |
|
| 34 | + $this->assertEquals('__return_null', $versions->latest_version_callback()); |
|
| 35 | + $versions->register('1.2', 'callback_1_dot_2'); |
|
| 36 | + $versions->register('1.3', 'callback_1_dot_3'); |
|
| 37 | + $versions->register('1.0', 'callback_1_dot_0'); |
|
| 38 | 38 | |
| 39 | - $this->assertSame( '1.3', $versions->latest_version() ); |
|
| 40 | - $this->assertEquals( 'callback_1_dot_3', $versions->latest_version_callback() ); |
|
| 39 | + $this->assertSame('1.3', $versions->latest_version()); |
|
| 40 | + $this->assertEquals('callback_1_dot_3', $versions->latest_version_callback()); |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
@@ -7,131 +7,131 @@ |
||
| 7 | 7 | * @group tables |
| 8 | 8 | */ |
| 9 | 9 | class ActionScheduler_DBLogger_Test extends ActionScheduler_UnitTestCase { |
| 10 | - public function test_default_logger() { |
|
| 11 | - $logger = ActionScheduler::logger(); |
|
| 12 | - $this->assertInstanceOf( 'ActionScheduler_Logger', $logger ); |
|
| 13 | - $this->assertInstanceOf( ActionScheduler_DBLogger::class, $logger ); |
|
| 14 | - } |
|
| 15 | - |
|
| 16 | - public function test_add_log_entry() { |
|
| 17 | - $action_id = as_schedule_single_action( time(), __METHOD__ ); |
|
| 18 | - $logger = ActionScheduler::logger(); |
|
| 19 | - $message = 'Logging that something happened'; |
|
| 20 | - $log_id = $logger->log( $action_id, $message ); |
|
| 21 | - $entry = $logger->get_entry( $log_id ); |
|
| 22 | - |
|
| 23 | - $this->assertEquals( $action_id, $entry->get_action_id() ); |
|
| 24 | - $this->assertEquals( $message, $entry->get_message() ); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - public function test_storage_logs() { |
|
| 28 | - $action_id = as_schedule_single_action( time(), __METHOD__ ); |
|
| 29 | - $logger = ActionScheduler::logger(); |
|
| 30 | - $logs = $logger->get_logs( $action_id ); |
|
| 31 | - $expected = new ActionScheduler_LogEntry( $action_id, 'action created' ); |
|
| 32 | - $this->assertCount( 1, $logs ); |
|
| 33 | - $this->assertEquals( $expected->get_action_id(), $logs[0]->get_action_id() ); |
|
| 34 | - $this->assertEquals( $expected->get_message(), $logs[0]->get_message() ); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function test_execution_logs() { |
|
| 38 | - $action_id = as_schedule_single_action( time(), ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ); |
|
| 39 | - $logger = ActionScheduler::logger(); |
|
| 40 | - $started = new ActionScheduler_LogEntry( $action_id, 'action started via Unit Tests' ); |
|
| 41 | - $finished = new ActionScheduler_LogEntry( $action_id, 'action complete via Unit Tests' ); |
|
| 42 | - |
|
| 43 | - $runner = ActionScheduler_Mocker::get_queue_runner(); |
|
| 44 | - $runner->run( 'Unit Tests' ); |
|
| 45 | - |
|
| 46 | - // Expect 3 logs with the correct action ID. |
|
| 47 | - $logs = $logger->get_logs( $action_id ); |
|
| 48 | - $this->assertCount( 3, $logs ); |
|
| 49 | - foreach ( $logs as $log ) { |
|
| 50 | - $this->assertEquals( $action_id, $log->get_action_id() ); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - // Expect created, then started, then completed. |
|
| 54 | - $this->assertEquals( 'action created', $logs[0]->get_message() ); |
|
| 55 | - $this->assertEquals( $started->get_message(), $logs[1]->get_message() ); |
|
| 56 | - $this->assertEquals( $finished->get_message(), $logs[2]->get_message() ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public function test_failed_execution_logs() { |
|
| 60 | - $hook = __METHOD__; |
|
| 61 | - add_action( $hook, array( $this, '_a_hook_callback_that_throws_an_exception' ) ); |
|
| 62 | - $action_id = as_schedule_single_action( time(), $hook ); |
|
| 63 | - $logger = ActionScheduler::logger(); |
|
| 64 | - $started = new ActionScheduler_LogEntry( $action_id, 'action started via Unit Tests' ); |
|
| 65 | - $finished = new ActionScheduler_LogEntry( $action_id, 'action complete via Unit Tests' ); |
|
| 66 | - $failed = new ActionScheduler_LogEntry( $action_id, 'action failed via Unit Tests: Execution failed' ); |
|
| 67 | - |
|
| 68 | - $runner = ActionScheduler_Mocker::get_queue_runner(); |
|
| 69 | - $runner->run( 'Unit Tests' ); |
|
| 70 | - |
|
| 71 | - // Expect 3 logs with the correct action ID. |
|
| 72 | - $logs = $logger->get_logs( $action_id ); |
|
| 73 | - $this->assertCount( 3, $logs ); |
|
| 74 | - foreach ( $logs as $log ) { |
|
| 75 | - $this->assertEquals( $action_id, $log->get_action_id() ); |
|
| 76 | - $this->assertNotEquals( $finished->get_message(), $log->get_message() ); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // Expect created, then started, then failed. |
|
| 80 | - $this->assertEquals( 'action created', $logs[0]->get_message() ); |
|
| 81 | - $this->assertEquals( $started->get_message(), $logs[1]->get_message() ); |
|
| 82 | - $this->assertEquals( $failed->get_message(), $logs[2]->get_message() ); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - public function test_fatal_error_log() { |
|
| 86 | - $action_id = as_schedule_single_action( time(), __METHOD__ ); |
|
| 87 | - $logger = ActionScheduler::logger(); |
|
| 88 | - do_action( |
|
| 89 | - 'action_scheduler_unexpected_shutdown', |
|
| 90 | - $action_id, |
|
| 91 | - array( |
|
| 92 | - 'type' => E_ERROR, |
|
| 93 | - 'message' => 'Test error', |
|
| 94 | - 'file' => __FILE__, |
|
| 95 | - 'line' => __LINE__, |
|
| 96 | - ) |
|
| 97 | - ); |
|
| 98 | - |
|
| 99 | - $logs = $logger->get_logs( $action_id ); |
|
| 100 | - $found_log = false; |
|
| 101 | - foreach ( $logs as $l ) { |
|
| 102 | - if ( strpos( $l->get_message(), 'unexpected shutdown' ) === 0 ) { |
|
| 103 | - $found_log = true; |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - $this->assertTrue( $found_log, 'Unexpected shutdown log not found' ); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - public function test_canceled_action_log() { |
|
| 110 | - $action_id = as_schedule_single_action( time(), __METHOD__ ); |
|
| 111 | - as_unschedule_action( __METHOD__ ); |
|
| 112 | - $logger = ActionScheduler::logger(); |
|
| 113 | - $logs = $logger->get_logs( $action_id ); |
|
| 114 | - $expected = new ActionScheduler_LogEntry( $action_id, 'action canceled' ); |
|
| 115 | - $this->assertEquals( $expected->get_message(), end( $logs )->get_message() ); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - public function test_deleted_action_cleanup() { |
|
| 119 | - $time = as_get_datetime_object( '-10 minutes' ); |
|
| 120 | - $schedule = new \ActionScheduler_SimpleSchedule( $time ); |
|
| 121 | - $action = new \ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule ); |
|
| 122 | - $store = new ActionScheduler_DBStore(); |
|
| 123 | - $action_id = $store->save_action( $action ); |
|
| 124 | - |
|
| 125 | - $logger = new ActionScheduler_DBLogger(); |
|
| 126 | - $logs = $logger->get_logs( $action_id ); |
|
| 127 | - $this->assertNotEmpty( $logs ); |
|
| 128 | - |
|
| 129 | - $store->delete_action( $action_id ); |
|
| 130 | - $logs = $logger->get_logs( $action_id ); |
|
| 131 | - $this->assertEmpty( $logs ); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - public function _a_hook_callback_that_throws_an_exception() { |
|
| 135 | - throw new \RuntimeException( 'Execution failed' ); |
|
| 136 | - } |
|
| 10 | + public function test_default_logger() { |
|
| 11 | + $logger = ActionScheduler::logger(); |
|
| 12 | + $this->assertInstanceOf( 'ActionScheduler_Logger', $logger ); |
|
| 13 | + $this->assertInstanceOf( ActionScheduler_DBLogger::class, $logger ); |
|
| 14 | + } |
|
| 15 | + |
|
| 16 | + public function test_add_log_entry() { |
|
| 17 | + $action_id = as_schedule_single_action( time(), __METHOD__ ); |
|
| 18 | + $logger = ActionScheduler::logger(); |
|
| 19 | + $message = 'Logging that something happened'; |
|
| 20 | + $log_id = $logger->log( $action_id, $message ); |
|
| 21 | + $entry = $logger->get_entry( $log_id ); |
|
| 22 | + |
|
| 23 | + $this->assertEquals( $action_id, $entry->get_action_id() ); |
|
| 24 | + $this->assertEquals( $message, $entry->get_message() ); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + public function test_storage_logs() { |
|
| 28 | + $action_id = as_schedule_single_action( time(), __METHOD__ ); |
|
| 29 | + $logger = ActionScheduler::logger(); |
|
| 30 | + $logs = $logger->get_logs( $action_id ); |
|
| 31 | + $expected = new ActionScheduler_LogEntry( $action_id, 'action created' ); |
|
| 32 | + $this->assertCount( 1, $logs ); |
|
| 33 | + $this->assertEquals( $expected->get_action_id(), $logs[0]->get_action_id() ); |
|
| 34 | + $this->assertEquals( $expected->get_message(), $logs[0]->get_message() ); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function test_execution_logs() { |
|
| 38 | + $action_id = as_schedule_single_action( time(), ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ); |
|
| 39 | + $logger = ActionScheduler::logger(); |
|
| 40 | + $started = new ActionScheduler_LogEntry( $action_id, 'action started via Unit Tests' ); |
|
| 41 | + $finished = new ActionScheduler_LogEntry( $action_id, 'action complete via Unit Tests' ); |
|
| 42 | + |
|
| 43 | + $runner = ActionScheduler_Mocker::get_queue_runner(); |
|
| 44 | + $runner->run( 'Unit Tests' ); |
|
| 45 | + |
|
| 46 | + // Expect 3 logs with the correct action ID. |
|
| 47 | + $logs = $logger->get_logs( $action_id ); |
|
| 48 | + $this->assertCount( 3, $logs ); |
|
| 49 | + foreach ( $logs as $log ) { |
|
| 50 | + $this->assertEquals( $action_id, $log->get_action_id() ); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + // Expect created, then started, then completed. |
|
| 54 | + $this->assertEquals( 'action created', $logs[0]->get_message() ); |
|
| 55 | + $this->assertEquals( $started->get_message(), $logs[1]->get_message() ); |
|
| 56 | + $this->assertEquals( $finished->get_message(), $logs[2]->get_message() ); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public function test_failed_execution_logs() { |
|
| 60 | + $hook = __METHOD__; |
|
| 61 | + add_action( $hook, array( $this, '_a_hook_callback_that_throws_an_exception' ) ); |
|
| 62 | + $action_id = as_schedule_single_action( time(), $hook ); |
|
| 63 | + $logger = ActionScheduler::logger(); |
|
| 64 | + $started = new ActionScheduler_LogEntry( $action_id, 'action started via Unit Tests' ); |
|
| 65 | + $finished = new ActionScheduler_LogEntry( $action_id, 'action complete via Unit Tests' ); |
|
| 66 | + $failed = new ActionScheduler_LogEntry( $action_id, 'action failed via Unit Tests: Execution failed' ); |
|
| 67 | + |
|
| 68 | + $runner = ActionScheduler_Mocker::get_queue_runner(); |
|
| 69 | + $runner->run( 'Unit Tests' ); |
|
| 70 | + |
|
| 71 | + // Expect 3 logs with the correct action ID. |
|
| 72 | + $logs = $logger->get_logs( $action_id ); |
|
| 73 | + $this->assertCount( 3, $logs ); |
|
| 74 | + foreach ( $logs as $log ) { |
|
| 75 | + $this->assertEquals( $action_id, $log->get_action_id() ); |
|
| 76 | + $this->assertNotEquals( $finished->get_message(), $log->get_message() ); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // Expect created, then started, then failed. |
|
| 80 | + $this->assertEquals( 'action created', $logs[0]->get_message() ); |
|
| 81 | + $this->assertEquals( $started->get_message(), $logs[1]->get_message() ); |
|
| 82 | + $this->assertEquals( $failed->get_message(), $logs[2]->get_message() ); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + public function test_fatal_error_log() { |
|
| 86 | + $action_id = as_schedule_single_action( time(), __METHOD__ ); |
|
| 87 | + $logger = ActionScheduler::logger(); |
|
| 88 | + do_action( |
|
| 89 | + 'action_scheduler_unexpected_shutdown', |
|
| 90 | + $action_id, |
|
| 91 | + array( |
|
| 92 | + 'type' => E_ERROR, |
|
| 93 | + 'message' => 'Test error', |
|
| 94 | + 'file' => __FILE__, |
|
| 95 | + 'line' => __LINE__, |
|
| 96 | + ) |
|
| 97 | + ); |
|
| 98 | + |
|
| 99 | + $logs = $logger->get_logs( $action_id ); |
|
| 100 | + $found_log = false; |
|
| 101 | + foreach ( $logs as $l ) { |
|
| 102 | + if ( strpos( $l->get_message(), 'unexpected shutdown' ) === 0 ) { |
|
| 103 | + $found_log = true; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + $this->assertTrue( $found_log, 'Unexpected shutdown log not found' ); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + public function test_canceled_action_log() { |
|
| 110 | + $action_id = as_schedule_single_action( time(), __METHOD__ ); |
|
| 111 | + as_unschedule_action( __METHOD__ ); |
|
| 112 | + $logger = ActionScheduler::logger(); |
|
| 113 | + $logs = $logger->get_logs( $action_id ); |
|
| 114 | + $expected = new ActionScheduler_LogEntry( $action_id, 'action canceled' ); |
|
| 115 | + $this->assertEquals( $expected->get_message(), end( $logs )->get_message() ); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + public function test_deleted_action_cleanup() { |
|
| 119 | + $time = as_get_datetime_object( '-10 minutes' ); |
|
| 120 | + $schedule = new \ActionScheduler_SimpleSchedule( $time ); |
|
| 121 | + $action = new \ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule ); |
|
| 122 | + $store = new ActionScheduler_DBStore(); |
|
| 123 | + $action_id = $store->save_action( $action ); |
|
| 124 | + |
|
| 125 | + $logger = new ActionScheduler_DBLogger(); |
|
| 126 | + $logs = $logger->get_logs( $action_id ); |
|
| 127 | + $this->assertNotEmpty( $logs ); |
|
| 128 | + |
|
| 129 | + $store->delete_action( $action_id ); |
|
| 130 | + $logs = $logger->get_logs( $action_id ); |
|
| 131 | + $this->assertEmpty( $logs ); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + public function _a_hook_callback_that_throws_an_exception() { |
|
| 135 | + throw new \RuntimeException( 'Execution failed' ); |
|
| 136 | + } |
|
| 137 | 137 | } |
@@ -9,81 +9,81 @@ discard block |
||
| 9 | 9 | class ActionScheduler_DBLogger_Test extends ActionScheduler_UnitTestCase { |
| 10 | 10 | public function test_default_logger() { |
| 11 | 11 | $logger = ActionScheduler::logger(); |
| 12 | - $this->assertInstanceOf( 'ActionScheduler_Logger', $logger ); |
|
| 13 | - $this->assertInstanceOf( ActionScheduler_DBLogger::class, $logger ); |
|
| 12 | + $this->assertInstanceOf('ActionScheduler_Logger', $logger); |
|
| 13 | + $this->assertInstanceOf(ActionScheduler_DBLogger::class, $logger); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function test_add_log_entry() { |
| 17 | - $action_id = as_schedule_single_action( time(), __METHOD__ ); |
|
| 17 | + $action_id = as_schedule_single_action(time(), __METHOD__); |
|
| 18 | 18 | $logger = ActionScheduler::logger(); |
| 19 | 19 | $message = 'Logging that something happened'; |
| 20 | - $log_id = $logger->log( $action_id, $message ); |
|
| 21 | - $entry = $logger->get_entry( $log_id ); |
|
| 20 | + $log_id = $logger->log($action_id, $message); |
|
| 21 | + $entry = $logger->get_entry($log_id); |
|
| 22 | 22 | |
| 23 | - $this->assertEquals( $action_id, $entry->get_action_id() ); |
|
| 24 | - $this->assertEquals( $message, $entry->get_message() ); |
|
| 23 | + $this->assertEquals($action_id, $entry->get_action_id()); |
|
| 24 | + $this->assertEquals($message, $entry->get_message()); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | public function test_storage_logs() { |
| 28 | - $action_id = as_schedule_single_action( time(), __METHOD__ ); |
|
| 28 | + $action_id = as_schedule_single_action(time(), __METHOD__); |
|
| 29 | 29 | $logger = ActionScheduler::logger(); |
| 30 | - $logs = $logger->get_logs( $action_id ); |
|
| 31 | - $expected = new ActionScheduler_LogEntry( $action_id, 'action created' ); |
|
| 32 | - $this->assertCount( 1, $logs ); |
|
| 33 | - $this->assertEquals( $expected->get_action_id(), $logs[0]->get_action_id() ); |
|
| 34 | - $this->assertEquals( $expected->get_message(), $logs[0]->get_message() ); |
|
| 30 | + $logs = $logger->get_logs($action_id); |
|
| 31 | + $expected = new ActionScheduler_LogEntry($action_id, 'action created'); |
|
| 32 | + $this->assertCount(1, $logs); |
|
| 33 | + $this->assertEquals($expected->get_action_id(), $logs[0]->get_action_id()); |
|
| 34 | + $this->assertEquals($expected->get_message(), $logs[0]->get_message()); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public function test_execution_logs() { |
| 38 | - $action_id = as_schedule_single_action( time(), ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ); |
|
| 38 | + $action_id = as_schedule_single_action(time(), ActionScheduler_Callbacks::HOOK_WITH_CALLBACK); |
|
| 39 | 39 | $logger = ActionScheduler::logger(); |
| 40 | - $started = new ActionScheduler_LogEntry( $action_id, 'action started via Unit Tests' ); |
|
| 41 | - $finished = new ActionScheduler_LogEntry( $action_id, 'action complete via Unit Tests' ); |
|
| 40 | + $started = new ActionScheduler_LogEntry($action_id, 'action started via Unit Tests'); |
|
| 41 | + $finished = new ActionScheduler_LogEntry($action_id, 'action complete via Unit Tests'); |
|
| 42 | 42 | |
| 43 | 43 | $runner = ActionScheduler_Mocker::get_queue_runner(); |
| 44 | - $runner->run( 'Unit Tests' ); |
|
| 44 | + $runner->run('Unit Tests'); |
|
| 45 | 45 | |
| 46 | 46 | // Expect 3 logs with the correct action ID. |
| 47 | - $logs = $logger->get_logs( $action_id ); |
|
| 48 | - $this->assertCount( 3, $logs ); |
|
| 49 | - foreach ( $logs as $log ) { |
|
| 50 | - $this->assertEquals( $action_id, $log->get_action_id() ); |
|
| 47 | + $logs = $logger->get_logs($action_id); |
|
| 48 | + $this->assertCount(3, $logs); |
|
| 49 | + foreach ($logs as $log) { |
|
| 50 | + $this->assertEquals($action_id, $log->get_action_id()); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | // Expect created, then started, then completed. |
| 54 | - $this->assertEquals( 'action created', $logs[0]->get_message() ); |
|
| 55 | - $this->assertEquals( $started->get_message(), $logs[1]->get_message() ); |
|
| 56 | - $this->assertEquals( $finished->get_message(), $logs[2]->get_message() ); |
|
| 54 | + $this->assertEquals('action created', $logs[0]->get_message()); |
|
| 55 | + $this->assertEquals($started->get_message(), $logs[1]->get_message()); |
|
| 56 | + $this->assertEquals($finished->get_message(), $logs[2]->get_message()); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | public function test_failed_execution_logs() { |
| 60 | 60 | $hook = __METHOD__; |
| 61 | - add_action( $hook, array( $this, '_a_hook_callback_that_throws_an_exception' ) ); |
|
| 62 | - $action_id = as_schedule_single_action( time(), $hook ); |
|
| 61 | + add_action($hook, array($this, '_a_hook_callback_that_throws_an_exception')); |
|
| 62 | + $action_id = as_schedule_single_action(time(), $hook); |
|
| 63 | 63 | $logger = ActionScheduler::logger(); |
| 64 | - $started = new ActionScheduler_LogEntry( $action_id, 'action started via Unit Tests' ); |
|
| 65 | - $finished = new ActionScheduler_LogEntry( $action_id, 'action complete via Unit Tests' ); |
|
| 66 | - $failed = new ActionScheduler_LogEntry( $action_id, 'action failed via Unit Tests: Execution failed' ); |
|
| 64 | + $started = new ActionScheduler_LogEntry($action_id, 'action started via Unit Tests'); |
|
| 65 | + $finished = new ActionScheduler_LogEntry($action_id, 'action complete via Unit Tests'); |
|
| 66 | + $failed = new ActionScheduler_LogEntry($action_id, 'action failed via Unit Tests: Execution failed'); |
|
| 67 | 67 | |
| 68 | 68 | $runner = ActionScheduler_Mocker::get_queue_runner(); |
| 69 | - $runner->run( 'Unit Tests' ); |
|
| 69 | + $runner->run('Unit Tests'); |
|
| 70 | 70 | |
| 71 | 71 | // Expect 3 logs with the correct action ID. |
| 72 | - $logs = $logger->get_logs( $action_id ); |
|
| 73 | - $this->assertCount( 3, $logs ); |
|
| 74 | - foreach ( $logs as $log ) { |
|
| 75 | - $this->assertEquals( $action_id, $log->get_action_id() ); |
|
| 76 | - $this->assertNotEquals( $finished->get_message(), $log->get_message() ); |
|
| 72 | + $logs = $logger->get_logs($action_id); |
|
| 73 | + $this->assertCount(3, $logs); |
|
| 74 | + foreach ($logs as $log) { |
|
| 75 | + $this->assertEquals($action_id, $log->get_action_id()); |
|
| 76 | + $this->assertNotEquals($finished->get_message(), $log->get_message()); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | // Expect created, then started, then failed. |
| 80 | - $this->assertEquals( 'action created', $logs[0]->get_message() ); |
|
| 81 | - $this->assertEquals( $started->get_message(), $logs[1]->get_message() ); |
|
| 82 | - $this->assertEquals( $failed->get_message(), $logs[2]->get_message() ); |
|
| 80 | + $this->assertEquals('action created', $logs[0]->get_message()); |
|
| 81 | + $this->assertEquals($started->get_message(), $logs[1]->get_message()); |
|
| 82 | + $this->assertEquals($failed->get_message(), $logs[2]->get_message()); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | public function test_fatal_error_log() { |
| 86 | - $action_id = as_schedule_single_action( time(), __METHOD__ ); |
|
| 86 | + $action_id = as_schedule_single_action(time(), __METHOD__); |
|
| 87 | 87 | $logger = ActionScheduler::logger(); |
| 88 | 88 | do_action( |
| 89 | 89 | 'action_scheduler_unexpected_shutdown', |
@@ -96,42 +96,42 @@ discard block |
||
| 96 | 96 | ) |
| 97 | 97 | ); |
| 98 | 98 | |
| 99 | - $logs = $logger->get_logs( $action_id ); |
|
| 99 | + $logs = $logger->get_logs($action_id); |
|
| 100 | 100 | $found_log = false; |
| 101 | - foreach ( $logs as $l ) { |
|
| 102 | - if ( strpos( $l->get_message(), 'unexpected shutdown' ) === 0 ) { |
|
| 101 | + foreach ($logs as $l) { |
|
| 102 | + if (strpos($l->get_message(), 'unexpected shutdown') === 0) { |
|
| 103 | 103 | $found_log = true; |
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | - $this->assertTrue( $found_log, 'Unexpected shutdown log not found' ); |
|
| 106 | + $this->assertTrue($found_log, 'Unexpected shutdown log not found'); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | public function test_canceled_action_log() { |
| 110 | - $action_id = as_schedule_single_action( time(), __METHOD__ ); |
|
| 111 | - as_unschedule_action( __METHOD__ ); |
|
| 110 | + $action_id = as_schedule_single_action(time(), __METHOD__); |
|
| 111 | + as_unschedule_action(__METHOD__); |
|
| 112 | 112 | $logger = ActionScheduler::logger(); |
| 113 | - $logs = $logger->get_logs( $action_id ); |
|
| 114 | - $expected = new ActionScheduler_LogEntry( $action_id, 'action canceled' ); |
|
| 115 | - $this->assertEquals( $expected->get_message(), end( $logs )->get_message() ); |
|
| 113 | + $logs = $logger->get_logs($action_id); |
|
| 114 | + $expected = new ActionScheduler_LogEntry($action_id, 'action canceled'); |
|
| 115 | + $this->assertEquals($expected->get_message(), end($logs)->get_message()); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | public function test_deleted_action_cleanup() { |
| 119 | - $time = as_get_datetime_object( '-10 minutes' ); |
|
| 120 | - $schedule = new \ActionScheduler_SimpleSchedule( $time ); |
|
| 121 | - $action = new \ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule ); |
|
| 119 | + $time = as_get_datetime_object('-10 minutes'); |
|
| 120 | + $schedule = new \ActionScheduler_SimpleSchedule($time); |
|
| 121 | + $action = new \ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule); |
|
| 122 | 122 | $store = new ActionScheduler_DBStore(); |
| 123 | - $action_id = $store->save_action( $action ); |
|
| 123 | + $action_id = $store->save_action($action); |
|
| 124 | 124 | |
| 125 | 125 | $logger = new ActionScheduler_DBLogger(); |
| 126 | - $logs = $logger->get_logs( $action_id ); |
|
| 127 | - $this->assertNotEmpty( $logs ); |
|
| 126 | + $logs = $logger->get_logs($action_id); |
|
| 127 | + $this->assertNotEmpty($logs); |
|
| 128 | 128 | |
| 129 | - $store->delete_action( $action_id ); |
|
| 130 | - $logs = $logger->get_logs( $action_id ); |
|
| 131 | - $this->assertEmpty( $logs ); |
|
| 129 | + $store->delete_action($action_id); |
|
| 130 | + $logs = $logger->get_logs($action_id); |
|
| 131 | + $this->assertEmpty($logs); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | public function _a_hook_callback_that_throws_an_exception() { |
| 135 | - throw new \RuntimeException( 'Execution failed' ); |
|
| 135 | + throw new \RuntimeException('Execution failed'); |
|
| 136 | 136 | } |
| 137 | 137 | } |
@@ -6,224 +6,224 @@ |
||
| 6 | 6 | * @package test_cases\logging |
| 7 | 7 | */ |
| 8 | 8 | class ActionScheduler_wpCommentLogger_Test extends ActionScheduler_UnitTestCase { |
| 9 | - private $use_comment_logger; |
|
| 10 | - |
|
| 11 | - public function test_default_logger() { |
|
| 12 | - $logger = ActionScheduler::logger(); |
|
| 13 | - $this->assertInstanceOf( 'ActionScheduler_Logger', $logger ); |
|
| 14 | - if ( $this->using_comment_logger() ) { |
|
| 15 | - $this->assertInstanceOf( 'ActionScheduler_wpCommentLogger', $logger ); |
|
| 16 | - } else { |
|
| 17 | - $this->assertNotInstanceOf( 'ActionScheduler_wpCommentLogger', $logger ); |
|
| 18 | - } |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - public function test_add_log_entry() { |
|
| 22 | - $action_id = as_schedule_single_action( time(), 'a hook' ); |
|
| 23 | - $logger = ActionScheduler::logger(); |
|
| 24 | - $message = 'Logging that something happened'; |
|
| 25 | - $log_id = $logger->log( $action_id, $message ); |
|
| 26 | - $entry = $logger->get_entry( $log_id ); |
|
| 27 | - |
|
| 28 | - $this->assertEquals( $action_id, $entry->get_action_id() ); |
|
| 29 | - $this->assertEquals( $message, $entry->get_message() ); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - public function test_add_log_datetime() { |
|
| 33 | - $action_id = as_schedule_single_action( time(), 'a hook' ); |
|
| 34 | - $logger = ActionScheduler::logger(); |
|
| 35 | - $message = 'Logging that something happened'; |
|
| 36 | - $date = new DateTime( 'now', new DateTimeZone( 'UTC' ) ); |
|
| 37 | - $log_id = $logger->log( $action_id, $message, $date ); |
|
| 38 | - $entry = $logger->get_entry( $log_id ); |
|
| 39 | - |
|
| 40 | - $this->assertEquals( $action_id, $entry->get_action_id() ); |
|
| 41 | - $this->assertEquals( $message, $entry->get_message() ); |
|
| 42 | - |
|
| 43 | - $date = new ActionScheduler_DateTime( 'now', new DateTimeZone( 'UTC' ) ); |
|
| 44 | - $log_id = $logger->log( $action_id, $message, $date ); |
|
| 45 | - $entry = $logger->get_entry( $log_id ); |
|
| 46 | - |
|
| 47 | - $this->assertEquals( $action_id, $entry->get_action_id() ); |
|
| 48 | - $this->assertEquals( $message, $entry->get_message() ); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function test_erroneous_entry_id() { |
|
| 52 | - $comment = wp_insert_comment( |
|
| 53 | - array( |
|
| 54 | - 'comment_post_ID' => 1, |
|
| 55 | - 'comment_author' => 'test', |
|
| 56 | - 'comment_content' => 'this is not a log entry', |
|
| 57 | - ) |
|
| 58 | - ); |
|
| 59 | - $logger = ActionScheduler::logger(); |
|
| 60 | - $entry = $logger->get_entry( $comment ); |
|
| 61 | - $this->assertSame( '', $entry->get_action_id() ); |
|
| 62 | - $this->assertSame( '', $entry->get_message() ); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public function test_storage_comments() { |
|
| 66 | - $action_id = as_schedule_single_action( time(), 'a hook' ); |
|
| 67 | - $logger = ActionScheduler::logger(); |
|
| 68 | - $logs = $logger->get_logs( $action_id ); |
|
| 69 | - $expected = new ActionScheduler_LogEntry( $action_id, 'action created' ); |
|
| 70 | - $this->assertContains( $this->log_entry_to_array( $expected ), $this->log_entry_to_array( $logs ) ); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - protected function log_entry_to_array( $logs ) { |
|
| 74 | - if ( $logs instanceof ActionScheduler_LogEntry ) { |
|
| 75 | - return array( |
|
| 76 | - 'action_id' => $logs->get_action_id(), |
|
| 77 | - 'message' => $logs->get_message(), |
|
| 78 | - ); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - foreach ( $logs as $id => $log ) { |
|
| 82 | - $logs[ $id ] = array( |
|
| 83 | - 'action_id' => $log->get_action_id(), |
|
| 84 | - 'message' => $log->get_message(), |
|
| 85 | - ); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - return $logs; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function test_execution_comments() { |
|
| 92 | - $action_id = as_schedule_single_action( time(), ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ); |
|
| 93 | - $logger = ActionScheduler::logger(); |
|
| 94 | - $started = new ActionScheduler_LogEntry( $action_id, 'action started via Unit Tests' ); |
|
| 95 | - $finished = new ActionScheduler_LogEntry( $action_id, 'action complete via Unit Tests' ); |
|
| 96 | - |
|
| 97 | - $runner = ActionScheduler_Mocker::get_queue_runner(); |
|
| 98 | - $runner->run( 'Unit Tests' ); |
|
| 99 | - |
|
| 100 | - $logs = $logger->get_logs( $action_id ); |
|
| 101 | - $this->assertContains( $this->log_entry_to_array( $started ), $this->log_entry_to_array( $logs ) ); |
|
| 102 | - $this->assertContains( $this->log_entry_to_array( $finished ), $this->log_entry_to_array( $logs ) ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function test_failed_execution_comments() { |
|
| 106 | - $hook = md5( rand() ); |
|
| 107 | - add_action( $hook, array( $this, '_a_hook_callback_that_throws_an_exception' ) ); |
|
| 108 | - $action_id = as_schedule_single_action( time(), $hook ); |
|
| 109 | - $logger = ActionScheduler::logger(); |
|
| 110 | - $started = new ActionScheduler_LogEntry( $action_id, 'action started via Unit Tests' ); |
|
| 111 | - $finished = new ActionScheduler_LogEntry( $action_id, 'action complete via Unit Tests' ); |
|
| 112 | - $failed = new ActionScheduler_LogEntry( $action_id, 'action failed via Unit Tests: Execution failed' ); |
|
| 113 | - |
|
| 114 | - $runner = ActionScheduler_Mocker::get_queue_runner(); |
|
| 115 | - $runner->run( 'Unit Tests' ); |
|
| 116 | - |
|
| 117 | - $logs = $logger->get_logs( $action_id ); |
|
| 118 | - $this->assertContains( $this->log_entry_to_array( $started ), $this->log_entry_to_array( $logs ) ); |
|
| 119 | - $this->assertNotContains( $this->log_entry_to_array( $finished ), $this->log_entry_to_array( $logs ) ); |
|
| 120 | - $this->assertContains( $this->log_entry_to_array( $failed ), $this->log_entry_to_array( $logs ) ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - public function test_failed_schedule_next_instance_comments() { |
|
| 124 | - $action_id = rand(); |
|
| 125 | - $logger = ActionScheduler::logger(); |
|
| 126 | - $log_entry = new ActionScheduler_LogEntry( $action_id, 'There was a failure scheduling the next instance of this action: Execution failed' ); |
|
| 127 | - |
|
| 128 | - try { |
|
| 129 | - $this->_a_hook_callback_that_throws_an_exception(); |
|
| 130 | - } catch ( Exception $e ) { |
|
| 131 | - do_action( 'action_scheduler_failed_to_schedule_next_instance', $action_id, $e, new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ) ); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - $logs = $logger->get_logs( $action_id ); |
|
| 135 | - $this->assertContains( $this->log_entry_to_array( $log_entry ), $this->log_entry_to_array( $logs ) ); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - public function test_fatal_error_comments() { |
|
| 139 | - $hook = md5( rand() ); |
|
| 140 | - $action_id = as_schedule_single_action( time(), $hook ); |
|
| 141 | - $logger = ActionScheduler::logger(); |
|
| 142 | - do_action( |
|
| 143 | - 'action_scheduler_unexpected_shutdown', |
|
| 144 | - $action_id, |
|
| 145 | - array( |
|
| 146 | - 'type' => E_ERROR, |
|
| 147 | - 'message' => 'Test error', |
|
| 148 | - 'file' => __FILE__, |
|
| 149 | - 'line' => __LINE__, |
|
| 150 | - ) |
|
| 151 | - ); |
|
| 152 | - |
|
| 153 | - $logs = $logger->get_logs( $action_id ); |
|
| 154 | - $found_log = false; |
|
| 155 | - foreach ( $logs as $l ) { |
|
| 156 | - if ( strpos( $l->get_message(), 'unexpected shutdown' ) === 0 ) { |
|
| 157 | - $found_log = true; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - $this->assertTrue( $found_log, 'Unexpected shutdown log not found' ); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - public function test_canceled_action_comments() { |
|
| 164 | - $action_id = as_schedule_single_action( time(), 'a hook' ); |
|
| 165 | - as_unschedule_action( 'a hook' ); |
|
| 166 | - $logger = ActionScheduler::logger(); |
|
| 167 | - $logs = $logger->get_logs( $action_id ); |
|
| 168 | - $expected = new ActionScheduler_LogEntry( $action_id, 'action canceled' ); |
|
| 169 | - $this->assertContains( $this->log_entry_to_array( $expected ), $this->log_entry_to_array( $logs ) ); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - public function _a_hook_callback_that_throws_an_exception() { |
|
| 173 | - throw new RuntimeException( 'Execution failed' ); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - public function test_filtering_of_get_comments() { |
|
| 177 | - if ( ! $this->using_comment_logger() ) { |
|
| 178 | - $this->assertTrue( true ); |
|
| 179 | - return; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - $post_id = $this->factory->post->create_object( |
|
| 183 | - array( |
|
| 184 | - 'post_title' => __FUNCTION__, |
|
| 185 | - ) |
|
| 186 | - ); |
|
| 187 | - $comment_id = $this->factory->comment->create_object( |
|
| 188 | - array( |
|
| 189 | - 'comment_post_ID' => $post_id, |
|
| 190 | - 'comment_author' => __CLASS__, |
|
| 191 | - 'comment_content' => __FUNCTION__, |
|
| 192 | - ) |
|
| 193 | - ); |
|
| 194 | - |
|
| 195 | - // Verify that we're getting the expected comment before we add logging comments |
|
| 196 | - $comments = get_comments(); |
|
| 197 | - $this->assertCount( 1, $comments ); |
|
| 198 | - $this->assertEquals( $comment_id, $comments[0]->comment_ID ); |
|
| 199 | - |
|
| 200 | - $action_id = as_schedule_single_action( time(), 'a hook' ); |
|
| 201 | - $logger = ActionScheduler::logger(); |
|
| 202 | - $message = 'Logging that something happened'; |
|
| 203 | - $log_id = $logger->log( $action_id, $message ); |
|
| 204 | - |
|
| 205 | - // Verify that logging comments are excluded from general comment queries |
|
| 206 | - $comments = get_comments(); |
|
| 207 | - $this->assertCount( 1, $comments ); |
|
| 208 | - $this->assertEquals( $comment_id, $comments[0]->comment_ID ); |
|
| 209 | - |
|
| 210 | - // Verify that logging comments are returned when asking for them specifically |
|
| 211 | - $comments = get_comments( |
|
| 212 | - array( |
|
| 213 | - 'type' => ActionScheduler_wpCommentLogger::TYPE, |
|
| 214 | - ) |
|
| 215 | - ); |
|
| 216 | - // Expecting two: one when the action is created, another when we added our custom log |
|
| 217 | - $this->assertCount( 2, $comments ); |
|
| 218 | - $this->assertContains( $log_id, wp_list_pluck( $comments, 'comment_ID' ) ); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - private function using_comment_logger() { |
|
| 222 | - if ( null === $this->use_comment_logger ) { |
|
| 223 | - $this->use_comment_logger = ! ActionScheduler_DataController::dependencies_met(); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - return $this->use_comment_logger; |
|
| 227 | - } |
|
| 9 | + private $use_comment_logger; |
|
| 10 | + |
|
| 11 | + public function test_default_logger() { |
|
| 12 | + $logger = ActionScheduler::logger(); |
|
| 13 | + $this->assertInstanceOf( 'ActionScheduler_Logger', $logger ); |
|
| 14 | + if ( $this->using_comment_logger() ) { |
|
| 15 | + $this->assertInstanceOf( 'ActionScheduler_wpCommentLogger', $logger ); |
|
| 16 | + } else { |
|
| 17 | + $this->assertNotInstanceOf( 'ActionScheduler_wpCommentLogger', $logger ); |
|
| 18 | + } |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + public function test_add_log_entry() { |
|
| 22 | + $action_id = as_schedule_single_action( time(), 'a hook' ); |
|
| 23 | + $logger = ActionScheduler::logger(); |
|
| 24 | + $message = 'Logging that something happened'; |
|
| 25 | + $log_id = $logger->log( $action_id, $message ); |
|
| 26 | + $entry = $logger->get_entry( $log_id ); |
|
| 27 | + |
|
| 28 | + $this->assertEquals( $action_id, $entry->get_action_id() ); |
|
| 29 | + $this->assertEquals( $message, $entry->get_message() ); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + public function test_add_log_datetime() { |
|
| 33 | + $action_id = as_schedule_single_action( time(), 'a hook' ); |
|
| 34 | + $logger = ActionScheduler::logger(); |
|
| 35 | + $message = 'Logging that something happened'; |
|
| 36 | + $date = new DateTime( 'now', new DateTimeZone( 'UTC' ) ); |
|
| 37 | + $log_id = $logger->log( $action_id, $message, $date ); |
|
| 38 | + $entry = $logger->get_entry( $log_id ); |
|
| 39 | + |
|
| 40 | + $this->assertEquals( $action_id, $entry->get_action_id() ); |
|
| 41 | + $this->assertEquals( $message, $entry->get_message() ); |
|
| 42 | + |
|
| 43 | + $date = new ActionScheduler_DateTime( 'now', new DateTimeZone( 'UTC' ) ); |
|
| 44 | + $log_id = $logger->log( $action_id, $message, $date ); |
|
| 45 | + $entry = $logger->get_entry( $log_id ); |
|
| 46 | + |
|
| 47 | + $this->assertEquals( $action_id, $entry->get_action_id() ); |
|
| 48 | + $this->assertEquals( $message, $entry->get_message() ); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function test_erroneous_entry_id() { |
|
| 52 | + $comment = wp_insert_comment( |
|
| 53 | + array( |
|
| 54 | + 'comment_post_ID' => 1, |
|
| 55 | + 'comment_author' => 'test', |
|
| 56 | + 'comment_content' => 'this is not a log entry', |
|
| 57 | + ) |
|
| 58 | + ); |
|
| 59 | + $logger = ActionScheduler::logger(); |
|
| 60 | + $entry = $logger->get_entry( $comment ); |
|
| 61 | + $this->assertSame( '', $entry->get_action_id() ); |
|
| 62 | + $this->assertSame( '', $entry->get_message() ); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public function test_storage_comments() { |
|
| 66 | + $action_id = as_schedule_single_action( time(), 'a hook' ); |
|
| 67 | + $logger = ActionScheduler::logger(); |
|
| 68 | + $logs = $logger->get_logs( $action_id ); |
|
| 69 | + $expected = new ActionScheduler_LogEntry( $action_id, 'action created' ); |
|
| 70 | + $this->assertContains( $this->log_entry_to_array( $expected ), $this->log_entry_to_array( $logs ) ); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + protected function log_entry_to_array( $logs ) { |
|
| 74 | + if ( $logs instanceof ActionScheduler_LogEntry ) { |
|
| 75 | + return array( |
|
| 76 | + 'action_id' => $logs->get_action_id(), |
|
| 77 | + 'message' => $logs->get_message(), |
|
| 78 | + ); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + foreach ( $logs as $id => $log ) { |
|
| 82 | + $logs[ $id ] = array( |
|
| 83 | + 'action_id' => $log->get_action_id(), |
|
| 84 | + 'message' => $log->get_message(), |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + return $logs; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function test_execution_comments() { |
|
| 92 | + $action_id = as_schedule_single_action( time(), ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ); |
|
| 93 | + $logger = ActionScheduler::logger(); |
|
| 94 | + $started = new ActionScheduler_LogEntry( $action_id, 'action started via Unit Tests' ); |
|
| 95 | + $finished = new ActionScheduler_LogEntry( $action_id, 'action complete via Unit Tests' ); |
|
| 96 | + |
|
| 97 | + $runner = ActionScheduler_Mocker::get_queue_runner(); |
|
| 98 | + $runner->run( 'Unit Tests' ); |
|
| 99 | + |
|
| 100 | + $logs = $logger->get_logs( $action_id ); |
|
| 101 | + $this->assertContains( $this->log_entry_to_array( $started ), $this->log_entry_to_array( $logs ) ); |
|
| 102 | + $this->assertContains( $this->log_entry_to_array( $finished ), $this->log_entry_to_array( $logs ) ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function test_failed_execution_comments() { |
|
| 106 | + $hook = md5( rand() ); |
|
| 107 | + add_action( $hook, array( $this, '_a_hook_callback_that_throws_an_exception' ) ); |
|
| 108 | + $action_id = as_schedule_single_action( time(), $hook ); |
|
| 109 | + $logger = ActionScheduler::logger(); |
|
| 110 | + $started = new ActionScheduler_LogEntry( $action_id, 'action started via Unit Tests' ); |
|
| 111 | + $finished = new ActionScheduler_LogEntry( $action_id, 'action complete via Unit Tests' ); |
|
| 112 | + $failed = new ActionScheduler_LogEntry( $action_id, 'action failed via Unit Tests: Execution failed' ); |
|
| 113 | + |
|
| 114 | + $runner = ActionScheduler_Mocker::get_queue_runner(); |
|
| 115 | + $runner->run( 'Unit Tests' ); |
|
| 116 | + |
|
| 117 | + $logs = $logger->get_logs( $action_id ); |
|
| 118 | + $this->assertContains( $this->log_entry_to_array( $started ), $this->log_entry_to_array( $logs ) ); |
|
| 119 | + $this->assertNotContains( $this->log_entry_to_array( $finished ), $this->log_entry_to_array( $logs ) ); |
|
| 120 | + $this->assertContains( $this->log_entry_to_array( $failed ), $this->log_entry_to_array( $logs ) ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + public function test_failed_schedule_next_instance_comments() { |
|
| 124 | + $action_id = rand(); |
|
| 125 | + $logger = ActionScheduler::logger(); |
|
| 126 | + $log_entry = new ActionScheduler_LogEntry( $action_id, 'There was a failure scheduling the next instance of this action: Execution failed' ); |
|
| 127 | + |
|
| 128 | + try { |
|
| 129 | + $this->_a_hook_callback_that_throws_an_exception(); |
|
| 130 | + } catch ( Exception $e ) { |
|
| 131 | + do_action( 'action_scheduler_failed_to_schedule_next_instance', $action_id, $e, new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ) ); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + $logs = $logger->get_logs( $action_id ); |
|
| 135 | + $this->assertContains( $this->log_entry_to_array( $log_entry ), $this->log_entry_to_array( $logs ) ); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + public function test_fatal_error_comments() { |
|
| 139 | + $hook = md5( rand() ); |
|
| 140 | + $action_id = as_schedule_single_action( time(), $hook ); |
|
| 141 | + $logger = ActionScheduler::logger(); |
|
| 142 | + do_action( |
|
| 143 | + 'action_scheduler_unexpected_shutdown', |
|
| 144 | + $action_id, |
|
| 145 | + array( |
|
| 146 | + 'type' => E_ERROR, |
|
| 147 | + 'message' => 'Test error', |
|
| 148 | + 'file' => __FILE__, |
|
| 149 | + 'line' => __LINE__, |
|
| 150 | + ) |
|
| 151 | + ); |
|
| 152 | + |
|
| 153 | + $logs = $logger->get_logs( $action_id ); |
|
| 154 | + $found_log = false; |
|
| 155 | + foreach ( $logs as $l ) { |
|
| 156 | + if ( strpos( $l->get_message(), 'unexpected shutdown' ) === 0 ) { |
|
| 157 | + $found_log = true; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + $this->assertTrue( $found_log, 'Unexpected shutdown log not found' ); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + public function test_canceled_action_comments() { |
|
| 164 | + $action_id = as_schedule_single_action( time(), 'a hook' ); |
|
| 165 | + as_unschedule_action( 'a hook' ); |
|
| 166 | + $logger = ActionScheduler::logger(); |
|
| 167 | + $logs = $logger->get_logs( $action_id ); |
|
| 168 | + $expected = new ActionScheduler_LogEntry( $action_id, 'action canceled' ); |
|
| 169 | + $this->assertContains( $this->log_entry_to_array( $expected ), $this->log_entry_to_array( $logs ) ); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + public function _a_hook_callback_that_throws_an_exception() { |
|
| 173 | + throw new RuntimeException( 'Execution failed' ); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + public function test_filtering_of_get_comments() { |
|
| 177 | + if ( ! $this->using_comment_logger() ) { |
|
| 178 | + $this->assertTrue( true ); |
|
| 179 | + return; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + $post_id = $this->factory->post->create_object( |
|
| 183 | + array( |
|
| 184 | + 'post_title' => __FUNCTION__, |
|
| 185 | + ) |
|
| 186 | + ); |
|
| 187 | + $comment_id = $this->factory->comment->create_object( |
|
| 188 | + array( |
|
| 189 | + 'comment_post_ID' => $post_id, |
|
| 190 | + 'comment_author' => __CLASS__, |
|
| 191 | + 'comment_content' => __FUNCTION__, |
|
| 192 | + ) |
|
| 193 | + ); |
|
| 194 | + |
|
| 195 | + // Verify that we're getting the expected comment before we add logging comments |
|
| 196 | + $comments = get_comments(); |
|
| 197 | + $this->assertCount( 1, $comments ); |
|
| 198 | + $this->assertEquals( $comment_id, $comments[0]->comment_ID ); |
|
| 199 | + |
|
| 200 | + $action_id = as_schedule_single_action( time(), 'a hook' ); |
|
| 201 | + $logger = ActionScheduler::logger(); |
|
| 202 | + $message = 'Logging that something happened'; |
|
| 203 | + $log_id = $logger->log( $action_id, $message ); |
|
| 204 | + |
|
| 205 | + // Verify that logging comments are excluded from general comment queries |
|
| 206 | + $comments = get_comments(); |
|
| 207 | + $this->assertCount( 1, $comments ); |
|
| 208 | + $this->assertEquals( $comment_id, $comments[0]->comment_ID ); |
|
| 209 | + |
|
| 210 | + // Verify that logging comments are returned when asking for them specifically |
|
| 211 | + $comments = get_comments( |
|
| 212 | + array( |
|
| 213 | + 'type' => ActionScheduler_wpCommentLogger::TYPE, |
|
| 214 | + ) |
|
| 215 | + ); |
|
| 216 | + // Expecting two: one when the action is created, another when we added our custom log |
|
| 217 | + $this->assertCount( 2, $comments ); |
|
| 218 | + $this->assertContains( $log_id, wp_list_pluck( $comments, 'comment_ID' ) ); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + private function using_comment_logger() { |
|
| 222 | + if ( null === $this->use_comment_logger ) { |
|
| 223 | + $this->use_comment_logger = ! ActionScheduler_DataController::dependencies_met(); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + return $this->use_comment_logger; |
|
| 227 | + } |
|
| 228 | 228 | } |
| 229 | 229 | |
@@ -10,42 +10,42 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | public function test_default_logger() { |
| 12 | 12 | $logger = ActionScheduler::logger(); |
| 13 | - $this->assertInstanceOf( 'ActionScheduler_Logger', $logger ); |
|
| 14 | - if ( $this->using_comment_logger() ) { |
|
| 15 | - $this->assertInstanceOf( 'ActionScheduler_wpCommentLogger', $logger ); |
|
| 13 | + $this->assertInstanceOf('ActionScheduler_Logger', $logger); |
|
| 14 | + if ($this->using_comment_logger()) { |
|
| 15 | + $this->assertInstanceOf('ActionScheduler_wpCommentLogger', $logger); |
|
| 16 | 16 | } else { |
| 17 | - $this->assertNotInstanceOf( 'ActionScheduler_wpCommentLogger', $logger ); |
|
| 17 | + $this->assertNotInstanceOf('ActionScheduler_wpCommentLogger', $logger); |
|
| 18 | 18 | } |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function test_add_log_entry() { |
| 22 | - $action_id = as_schedule_single_action( time(), 'a hook' ); |
|
| 22 | + $action_id = as_schedule_single_action(time(), 'a hook'); |
|
| 23 | 23 | $logger = ActionScheduler::logger(); |
| 24 | 24 | $message = 'Logging that something happened'; |
| 25 | - $log_id = $logger->log( $action_id, $message ); |
|
| 26 | - $entry = $logger->get_entry( $log_id ); |
|
| 25 | + $log_id = $logger->log($action_id, $message); |
|
| 26 | + $entry = $logger->get_entry($log_id); |
|
| 27 | 27 | |
| 28 | - $this->assertEquals( $action_id, $entry->get_action_id() ); |
|
| 29 | - $this->assertEquals( $message, $entry->get_message() ); |
|
| 28 | + $this->assertEquals($action_id, $entry->get_action_id()); |
|
| 29 | + $this->assertEquals($message, $entry->get_message()); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function test_add_log_datetime() { |
| 33 | - $action_id = as_schedule_single_action( time(), 'a hook' ); |
|
| 33 | + $action_id = as_schedule_single_action(time(), 'a hook'); |
|
| 34 | 34 | $logger = ActionScheduler::logger(); |
| 35 | 35 | $message = 'Logging that something happened'; |
| 36 | - $date = new DateTime( 'now', new DateTimeZone( 'UTC' ) ); |
|
| 37 | - $log_id = $logger->log( $action_id, $message, $date ); |
|
| 38 | - $entry = $logger->get_entry( $log_id ); |
|
| 36 | + $date = new DateTime('now', new DateTimeZone('UTC')); |
|
| 37 | + $log_id = $logger->log($action_id, $message, $date); |
|
| 38 | + $entry = $logger->get_entry($log_id); |
|
| 39 | 39 | |
| 40 | - $this->assertEquals( $action_id, $entry->get_action_id() ); |
|
| 41 | - $this->assertEquals( $message, $entry->get_message() ); |
|
| 40 | + $this->assertEquals($action_id, $entry->get_action_id()); |
|
| 41 | + $this->assertEquals($message, $entry->get_message()); |
|
| 42 | 42 | |
| 43 | - $date = new ActionScheduler_DateTime( 'now', new DateTimeZone( 'UTC' ) ); |
|
| 44 | - $log_id = $logger->log( $action_id, $message, $date ); |
|
| 45 | - $entry = $logger->get_entry( $log_id ); |
|
| 43 | + $date = new ActionScheduler_DateTime('now', new DateTimeZone('UTC')); |
|
| 44 | + $log_id = $logger->log($action_id, $message, $date); |
|
| 45 | + $entry = $logger->get_entry($log_id); |
|
| 46 | 46 | |
| 47 | - $this->assertEquals( $action_id, $entry->get_action_id() ); |
|
| 48 | - $this->assertEquals( $message, $entry->get_message() ); |
|
| 47 | + $this->assertEquals($action_id, $entry->get_action_id()); |
|
| 48 | + $this->assertEquals($message, $entry->get_message()); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | public function test_erroneous_entry_id() { |
@@ -57,29 +57,29 @@ discard block |
||
| 57 | 57 | ) |
| 58 | 58 | ); |
| 59 | 59 | $logger = ActionScheduler::logger(); |
| 60 | - $entry = $logger->get_entry( $comment ); |
|
| 61 | - $this->assertSame( '', $entry->get_action_id() ); |
|
| 62 | - $this->assertSame( '', $entry->get_message() ); |
|
| 60 | + $entry = $logger->get_entry($comment); |
|
| 61 | + $this->assertSame('', $entry->get_action_id()); |
|
| 62 | + $this->assertSame('', $entry->get_message()); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | public function test_storage_comments() { |
| 66 | - $action_id = as_schedule_single_action( time(), 'a hook' ); |
|
| 66 | + $action_id = as_schedule_single_action(time(), 'a hook'); |
|
| 67 | 67 | $logger = ActionScheduler::logger(); |
| 68 | - $logs = $logger->get_logs( $action_id ); |
|
| 69 | - $expected = new ActionScheduler_LogEntry( $action_id, 'action created' ); |
|
| 70 | - $this->assertContains( $this->log_entry_to_array( $expected ), $this->log_entry_to_array( $logs ) ); |
|
| 68 | + $logs = $logger->get_logs($action_id); |
|
| 69 | + $expected = new ActionScheduler_LogEntry($action_id, 'action created'); |
|
| 70 | + $this->assertContains($this->log_entry_to_array($expected), $this->log_entry_to_array($logs)); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - protected function log_entry_to_array( $logs ) { |
|
| 74 | - if ( $logs instanceof ActionScheduler_LogEntry ) { |
|
| 73 | + protected function log_entry_to_array($logs) { |
|
| 74 | + if ($logs instanceof ActionScheduler_LogEntry) { |
|
| 75 | 75 | return array( |
| 76 | 76 | 'action_id' => $logs->get_action_id(), |
| 77 | 77 | 'message' => $logs->get_message(), |
| 78 | 78 | ); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - foreach ( $logs as $id => $log ) { |
|
| 82 | - $logs[ $id ] = array( |
|
| 81 | + foreach ($logs as $id => $log) { |
|
| 82 | + $logs[$id] = array( |
|
| 83 | 83 | 'action_id' => $log->get_action_id(), |
| 84 | 84 | 'message' => $log->get_message(), |
| 85 | 85 | ); |
@@ -89,55 +89,55 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | public function test_execution_comments() { |
| 92 | - $action_id = as_schedule_single_action( time(), ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ); |
|
| 92 | + $action_id = as_schedule_single_action(time(), ActionScheduler_Callbacks::HOOK_WITH_CALLBACK); |
|
| 93 | 93 | $logger = ActionScheduler::logger(); |
| 94 | - $started = new ActionScheduler_LogEntry( $action_id, 'action started via Unit Tests' ); |
|
| 95 | - $finished = new ActionScheduler_LogEntry( $action_id, 'action complete via Unit Tests' ); |
|
| 94 | + $started = new ActionScheduler_LogEntry($action_id, 'action started via Unit Tests'); |
|
| 95 | + $finished = new ActionScheduler_LogEntry($action_id, 'action complete via Unit Tests'); |
|
| 96 | 96 | |
| 97 | 97 | $runner = ActionScheduler_Mocker::get_queue_runner(); |
| 98 | - $runner->run( 'Unit Tests' ); |
|
| 98 | + $runner->run('Unit Tests'); |
|
| 99 | 99 | |
| 100 | - $logs = $logger->get_logs( $action_id ); |
|
| 101 | - $this->assertContains( $this->log_entry_to_array( $started ), $this->log_entry_to_array( $logs ) ); |
|
| 102 | - $this->assertContains( $this->log_entry_to_array( $finished ), $this->log_entry_to_array( $logs ) ); |
|
| 100 | + $logs = $logger->get_logs($action_id); |
|
| 101 | + $this->assertContains($this->log_entry_to_array($started), $this->log_entry_to_array($logs)); |
|
| 102 | + $this->assertContains($this->log_entry_to_array($finished), $this->log_entry_to_array($logs)); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | public function test_failed_execution_comments() { |
| 106 | - $hook = md5( rand() ); |
|
| 107 | - add_action( $hook, array( $this, '_a_hook_callback_that_throws_an_exception' ) ); |
|
| 108 | - $action_id = as_schedule_single_action( time(), $hook ); |
|
| 106 | + $hook = md5(rand()); |
|
| 107 | + add_action($hook, array($this, '_a_hook_callback_that_throws_an_exception')); |
|
| 108 | + $action_id = as_schedule_single_action(time(), $hook); |
|
| 109 | 109 | $logger = ActionScheduler::logger(); |
| 110 | - $started = new ActionScheduler_LogEntry( $action_id, 'action started via Unit Tests' ); |
|
| 111 | - $finished = new ActionScheduler_LogEntry( $action_id, 'action complete via Unit Tests' ); |
|
| 112 | - $failed = new ActionScheduler_LogEntry( $action_id, 'action failed via Unit Tests: Execution failed' ); |
|
| 110 | + $started = new ActionScheduler_LogEntry($action_id, 'action started via Unit Tests'); |
|
| 111 | + $finished = new ActionScheduler_LogEntry($action_id, 'action complete via Unit Tests'); |
|
| 112 | + $failed = new ActionScheduler_LogEntry($action_id, 'action failed via Unit Tests: Execution failed'); |
|
| 113 | 113 | |
| 114 | 114 | $runner = ActionScheduler_Mocker::get_queue_runner(); |
| 115 | - $runner->run( 'Unit Tests' ); |
|
| 115 | + $runner->run('Unit Tests'); |
|
| 116 | 116 | |
| 117 | - $logs = $logger->get_logs( $action_id ); |
|
| 118 | - $this->assertContains( $this->log_entry_to_array( $started ), $this->log_entry_to_array( $logs ) ); |
|
| 119 | - $this->assertNotContains( $this->log_entry_to_array( $finished ), $this->log_entry_to_array( $logs ) ); |
|
| 120 | - $this->assertContains( $this->log_entry_to_array( $failed ), $this->log_entry_to_array( $logs ) ); |
|
| 117 | + $logs = $logger->get_logs($action_id); |
|
| 118 | + $this->assertContains($this->log_entry_to_array($started), $this->log_entry_to_array($logs)); |
|
| 119 | + $this->assertNotContains($this->log_entry_to_array($finished), $this->log_entry_to_array($logs)); |
|
| 120 | + $this->assertContains($this->log_entry_to_array($failed), $this->log_entry_to_array($logs)); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | public function test_failed_schedule_next_instance_comments() { |
| 124 | 124 | $action_id = rand(); |
| 125 | 125 | $logger = ActionScheduler::logger(); |
| 126 | - $log_entry = new ActionScheduler_LogEntry( $action_id, 'There was a failure scheduling the next instance of this action: Execution failed' ); |
|
| 126 | + $log_entry = new ActionScheduler_LogEntry($action_id, 'There was a failure scheduling the next instance of this action: Execution failed'); |
|
| 127 | 127 | |
| 128 | 128 | try { |
| 129 | 129 | $this->_a_hook_callback_that_throws_an_exception(); |
| 130 | - } catch ( Exception $e ) { |
|
| 131 | - do_action( 'action_scheduler_failed_to_schedule_next_instance', $action_id, $e, new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ) ); |
|
| 130 | + } catch (Exception $e) { |
|
| 131 | + do_action('action_scheduler_failed_to_schedule_next_instance', $action_id, $e, new ActionScheduler_Action(ActionScheduler_Callbacks::HOOK_WITH_CALLBACK)); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - $logs = $logger->get_logs( $action_id ); |
|
| 135 | - $this->assertContains( $this->log_entry_to_array( $log_entry ), $this->log_entry_to_array( $logs ) ); |
|
| 134 | + $logs = $logger->get_logs($action_id); |
|
| 135 | + $this->assertContains($this->log_entry_to_array($log_entry), $this->log_entry_to_array($logs)); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | public function test_fatal_error_comments() { |
| 139 | - $hook = md5( rand() ); |
|
| 140 | - $action_id = as_schedule_single_action( time(), $hook ); |
|
| 139 | + $hook = md5(rand()); |
|
| 140 | + $action_id = as_schedule_single_action(time(), $hook); |
|
| 141 | 141 | $logger = ActionScheduler::logger(); |
| 142 | 142 | do_action( |
| 143 | 143 | 'action_scheduler_unexpected_shutdown', |
@@ -150,36 +150,36 @@ discard block |
||
| 150 | 150 | ) |
| 151 | 151 | ); |
| 152 | 152 | |
| 153 | - $logs = $logger->get_logs( $action_id ); |
|
| 153 | + $logs = $logger->get_logs($action_id); |
|
| 154 | 154 | $found_log = false; |
| 155 | - foreach ( $logs as $l ) { |
|
| 156 | - if ( strpos( $l->get_message(), 'unexpected shutdown' ) === 0 ) { |
|
| 155 | + foreach ($logs as $l) { |
|
| 156 | + if (strpos($l->get_message(), 'unexpected shutdown') === 0) { |
|
| 157 | 157 | $found_log = true; |
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | - $this->assertTrue( $found_log, 'Unexpected shutdown log not found' ); |
|
| 160 | + $this->assertTrue($found_log, 'Unexpected shutdown log not found'); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | public function test_canceled_action_comments() { |
| 164 | - $action_id = as_schedule_single_action( time(), 'a hook' ); |
|
| 165 | - as_unschedule_action( 'a hook' ); |
|
| 164 | + $action_id = as_schedule_single_action(time(), 'a hook'); |
|
| 165 | + as_unschedule_action('a hook'); |
|
| 166 | 166 | $logger = ActionScheduler::logger(); |
| 167 | - $logs = $logger->get_logs( $action_id ); |
|
| 168 | - $expected = new ActionScheduler_LogEntry( $action_id, 'action canceled' ); |
|
| 169 | - $this->assertContains( $this->log_entry_to_array( $expected ), $this->log_entry_to_array( $logs ) ); |
|
| 167 | + $logs = $logger->get_logs($action_id); |
|
| 168 | + $expected = new ActionScheduler_LogEntry($action_id, 'action canceled'); |
|
| 169 | + $this->assertContains($this->log_entry_to_array($expected), $this->log_entry_to_array($logs)); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | public function _a_hook_callback_that_throws_an_exception() { |
| 173 | - throw new RuntimeException( 'Execution failed' ); |
|
| 173 | + throw new RuntimeException('Execution failed'); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | public function test_filtering_of_get_comments() { |
| 177 | - if ( ! $this->using_comment_logger() ) { |
|
| 178 | - $this->assertTrue( true ); |
|
| 177 | + if ( ! $this->using_comment_logger()) { |
|
| 178 | + $this->assertTrue(true); |
|
| 179 | 179 | return; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - $post_id = $this->factory->post->create_object( |
|
| 182 | + $post_id = $this->factory->post->create_object( |
|
| 183 | 183 | array( |
| 184 | 184 | 'post_title' => __FUNCTION__, |
| 185 | 185 | ) |
@@ -194,18 +194,18 @@ discard block |
||
| 194 | 194 | |
| 195 | 195 | // Verify that we're getting the expected comment before we add logging comments |
| 196 | 196 | $comments = get_comments(); |
| 197 | - $this->assertCount( 1, $comments ); |
|
| 198 | - $this->assertEquals( $comment_id, $comments[0]->comment_ID ); |
|
| 197 | + $this->assertCount(1, $comments); |
|
| 198 | + $this->assertEquals($comment_id, $comments[0]->comment_ID); |
|
| 199 | 199 | |
| 200 | - $action_id = as_schedule_single_action( time(), 'a hook' ); |
|
| 200 | + $action_id = as_schedule_single_action(time(), 'a hook'); |
|
| 201 | 201 | $logger = ActionScheduler::logger(); |
| 202 | 202 | $message = 'Logging that something happened'; |
| 203 | - $log_id = $logger->log( $action_id, $message ); |
|
| 203 | + $log_id = $logger->log($action_id, $message); |
|
| 204 | 204 | |
| 205 | 205 | // Verify that logging comments are excluded from general comment queries |
| 206 | 206 | $comments = get_comments(); |
| 207 | - $this->assertCount( 1, $comments ); |
|
| 208 | - $this->assertEquals( $comment_id, $comments[0]->comment_ID ); |
|
| 207 | + $this->assertCount(1, $comments); |
|
| 208 | + $this->assertEquals($comment_id, $comments[0]->comment_ID); |
|
| 209 | 209 | |
| 210 | 210 | // Verify that logging comments are returned when asking for them specifically |
| 211 | 211 | $comments = get_comments( |
@@ -214,12 +214,12 @@ discard block |
||
| 214 | 214 | ) |
| 215 | 215 | ); |
| 216 | 216 | // Expecting two: one when the action is created, another when we added our custom log |
| 217 | - $this->assertCount( 2, $comments ); |
|
| 218 | - $this->assertContains( $log_id, wp_list_pluck( $comments, 'comment_ID' ) ); |
|
| 217 | + $this->assertCount(2, $comments); |
|
| 218 | + $this->assertContains($log_id, wp_list_pluck($comments, 'comment_ID')); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | private function using_comment_logger() { |
| 222 | - if ( null === $this->use_comment_logger ) { |
|
| 222 | + if (null === $this->use_comment_logger) { |
|
| 223 | 223 | $this->use_comment_logger = ! ActionScheduler_DataController::dependencies_met(); |
| 224 | 224 | } |
| 225 | 225 | |
@@ -6,13 +6,13 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | // Check for select constants defined as environment variables |
| 8 | 8 | foreach ( array( 'WP_CONTENT_DIR', 'WP_CONTENT_URL', 'WP_PLUGIN_DIR', 'WP_PLUGIN_URL', 'WPMU_PLUGIN_DIR' ) as $env_constant ) { |
| 9 | - if ( false !== getenv( $env_constant ) && ! defined( $env_constant ) ) { |
|
| 10 | - define( $env_constant, getenv( $env_constant ) ); |
|
| 11 | - } |
|
| 9 | + if ( false !== getenv( $env_constant ) && ! defined( $env_constant ) ) { |
|
| 10 | + define( $env_constant, getenv( $env_constant ) ); |
|
| 11 | + } |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | if ( ! defined( 'WP_PLUGIN_DIR' ) ) { |
| 15 | - define( 'WP_PLUGIN_DIR', dirname( dirname( __DIR__ ) ) ); |
|
| 15 | + define( 'WP_PLUGIN_DIR', dirname( dirname( __DIR__ ) ) ); |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | // PHPUnit polyfills as required by the core WP test framework. |
@@ -25,9 +25,9 @@ discard block |
||
| 25 | 25 | require_once dirname( __DIR__ ) . '/action-scheduler.php'; |
| 26 | 26 | |
| 27 | 27 | if ( class_exists( 'PHPUnit\Framework\TestResult' ) ) { // PHPUnit 6.0 or newer |
| 28 | - include_once('ActionScheduler_UnitTestCase.php'; |
|
| 28 | + include_once('ActionScheduler_UnitTestCase.php'; |
|
| 29 | 29 | } else { |
| 30 | - include_once('phpunit/deprecated/ActionScheduler_UnitTestCase.php'; |
|
| 30 | + include_once('phpunit/deprecated/ActionScheduler_UnitTestCase.php'; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | require_once 'phpunit/helpers/ActionScheduler_Callbacks.php'; |
@@ -2,29 +2,29 @@ |
||
| 2 | 2 | |
| 3 | 3 | $GLOBALS['wp_tests_options']['template'] = 'twentyseventeen'; |
| 4 | 4 | $GLOBALS['wp_tests_options']['stylesheet'] = 'twentyseventeen'; |
| 5 | -$GLOBALS['wp_tests_options']['active_plugins'][] = basename( dirname( __DIR__ ) ) . '/action-scheduler.php'; |
|
| 5 | +$GLOBALS['wp_tests_options']['active_plugins'][] = basename(dirname(__DIR__)).'/action-scheduler.php'; |
|
| 6 | 6 | |
| 7 | 7 | // Check for select constants defined as environment variables |
| 8 | -foreach ( array( 'WP_CONTENT_DIR', 'WP_CONTENT_URL', 'WP_PLUGIN_DIR', 'WP_PLUGIN_URL', 'WPMU_PLUGIN_DIR' ) as $env_constant ) { |
|
| 9 | - if ( false !== getenv( $env_constant ) && ! defined( $env_constant ) ) { |
|
| 10 | - define( $env_constant, getenv( $env_constant ) ); |
|
| 8 | +foreach (array('WP_CONTENT_DIR', 'WP_CONTENT_URL', 'WP_PLUGIN_DIR', 'WP_PLUGIN_URL', 'WPMU_PLUGIN_DIR') as $env_constant) { |
|
| 9 | + if (false !== getenv($env_constant) && ! defined($env_constant)) { |
|
| 10 | + define($env_constant, getenv($env_constant)); |
|
| 11 | 11 | } |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | -if ( ! defined( 'WP_PLUGIN_DIR' ) ) { |
|
| 15 | - define( 'WP_PLUGIN_DIR', dirname( dirname( __DIR__ ) ) ); |
|
| 14 | +if ( ! defined('WP_PLUGIN_DIR')) { |
|
| 15 | + define('WP_PLUGIN_DIR', dirname(dirname(__DIR__))); |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | // PHPUnit polyfills as required by the core WP test framework. |
| 19 | -require_once __DIR__ . '/../vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; |
|
| 19 | +require_once __DIR__.'/../vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; |
|
| 20 | 20 | |
| 21 | -$wordpress_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : sys_get_temp_dir() . '/wordpress-tests-lib'; |
|
| 22 | -require_once $wordpress_tests_dir . '/includes/functions.php'; |
|
| 23 | -require $wordpress_tests_dir . '/includes/bootstrap.php'; |
|
| 21 | +$wordpress_tests_dir = getenv('WP_TESTS_DIR') ? getenv('WP_TESTS_DIR') : sys_get_temp_dir().'/wordpress-tests-lib'; |
|
| 22 | +require_once $wordpress_tests_dir.'/includes/functions.php'; |
|
| 23 | +require $wordpress_tests_dir.'/includes/bootstrap.php'; |
|
| 24 | 24 | |
| 25 | -require_once dirname( __DIR__ ) . '/action-scheduler.php'; |
|
| 25 | +require_once dirname(__DIR__).'/action-scheduler.php'; |
|
| 26 | 26 | |
| 27 | -if ( class_exists( 'PHPUnit\Framework\TestResult' ) ) { // PHPUnit 6.0 or newer |
|
| 27 | +if (class_exists('PHPUnit\Framework\TestResult')) { // PHPUnit 6.0 or newer |
|
| 28 | 28 | include_once('ActionScheduler_UnitTestCase.php'; |
| 29 | 29 | } else { |
| 30 | 30 | include_once('phpunit/deprecated/ActionScheduler_UnitTestCase.php'; |
@@ -5,56 +5,56 @@ |
||
| 5 | 5 | */ |
| 6 | 6 | class ActionScheduler_UnitTestCase extends WP_UnitTestCase { |
| 7 | 7 | |
| 8 | - protected $existing_timezone; |
|
| 9 | - |
|
| 10 | - /** |
|
| 11 | - * Perform test set-up work. |
|
| 12 | - */ |
|
| 13 | - public function set_up() { |
|
| 14 | - ActionScheduler_Callbacks::add_callbacks(); |
|
| 15 | - parent::set_up(); |
|
| 16 | - } |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * Perform test tear-down work. |
|
| 20 | - */ |
|
| 21 | - public function tear_down() { |
|
| 22 | - ActionScheduler_Callbacks::remove_callbacks(); |
|
| 23 | - parent::tear_down(); |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Counts the number of test cases executed by run(TestResult result). |
|
| 28 | - * |
|
| 29 | - * @return int |
|
| 30 | - */ |
|
| 31 | - public function count(): int { |
|
| 32 | - return 'UTC' == date_default_timezone_get() ? 2 : 3; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * We want to run every test multiple times using a different timezone to make sure |
|
| 37 | - * that they are unaffected by changes to PHP's timezone. |
|
| 38 | - */ |
|
| 39 | - public function run( PHPUnit\Framework\TestResult $result = null ): \PHPUnit\Framework\TestResult { |
|
| 40 | - |
|
| 41 | - if ( $result === null ) { |
|
| 42 | - $result = $this->createResult(); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - if ( 'UTC' != ( $this->existing_timezone = date_default_timezone_get() ) ) { |
|
| 46 | - date_default_timezone_set( 'UTC' ); |
|
| 47 | - $result->run( $this ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - date_default_timezone_set( 'Pacific/Fiji' ); // UTC+12 |
|
| 51 | - $result->run( $this ); |
|
| 52 | - |
|
| 53 | - date_default_timezone_set( 'Pacific/Tahiti' ); // UTC-10: it's a magical place |
|
| 54 | - $result->run( $this ); |
|
| 55 | - |
|
| 56 | - date_default_timezone_set( $this->existing_timezone ); |
|
| 57 | - |
|
| 58 | - return $result; |
|
| 59 | - } |
|
| 8 | + protected $existing_timezone; |
|
| 9 | + |
|
| 10 | + /** |
|
| 11 | + * Perform test set-up work. |
|
| 12 | + */ |
|
| 13 | + public function set_up() { |
|
| 14 | + ActionScheduler_Callbacks::add_callbacks(); |
|
| 15 | + parent::set_up(); |
|
| 16 | + } |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * Perform test tear-down work. |
|
| 20 | + */ |
|
| 21 | + public function tear_down() { |
|
| 22 | + ActionScheduler_Callbacks::remove_callbacks(); |
|
| 23 | + parent::tear_down(); |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Counts the number of test cases executed by run(TestResult result). |
|
| 28 | + * |
|
| 29 | + * @return int |
|
| 30 | + */ |
|
| 31 | + public function count(): int { |
|
| 32 | + return 'UTC' == date_default_timezone_get() ? 2 : 3; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * We want to run every test multiple times using a different timezone to make sure |
|
| 37 | + * that they are unaffected by changes to PHP's timezone. |
|
| 38 | + */ |
|
| 39 | + public function run( PHPUnit\Framework\TestResult $result = null ): \PHPUnit\Framework\TestResult { |
|
| 40 | + |
|
| 41 | + if ( $result === null ) { |
|
| 42 | + $result = $this->createResult(); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + if ( 'UTC' != ( $this->existing_timezone = date_default_timezone_get() ) ) { |
|
| 46 | + date_default_timezone_set( 'UTC' ); |
|
| 47 | + $result->run( $this ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + date_default_timezone_set( 'Pacific/Fiji' ); // UTC+12 |
|
| 51 | + $result->run( $this ); |
|
| 52 | + |
|
| 53 | + date_default_timezone_set( 'Pacific/Tahiti' ); // UTC-10: it's a magical place |
|
| 54 | + $result->run( $this ); |
|
| 55 | + |
|
| 56 | + date_default_timezone_set( $this->existing_timezone ); |
|
| 57 | + |
|
| 58 | + return $result; |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -36,24 +36,24 @@ |
||
| 36 | 36 | * We want to run every test multiple times using a different timezone to make sure |
| 37 | 37 | * that they are unaffected by changes to PHP's timezone. |
| 38 | 38 | */ |
| 39 | - public function run( PHPUnit\Framework\TestResult $result = null ): \PHPUnit\Framework\TestResult { |
|
| 39 | + public function run(PHPUnit\Framework\TestResult $result = null): \PHPUnit\Framework\TestResult { |
|
| 40 | 40 | |
| 41 | - if ( $result === null ) { |
|
| 41 | + if ($result === null) { |
|
| 42 | 42 | $result = $this->createResult(); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if ( 'UTC' != ( $this->existing_timezone = date_default_timezone_get() ) ) { |
|
| 46 | - date_default_timezone_set( 'UTC' ); |
|
| 47 | - $result->run( $this ); |
|
| 45 | + if ('UTC' != ($this->existing_timezone = date_default_timezone_get())) { |
|
| 46 | + date_default_timezone_set('UTC'); |
|
| 47 | + $result->run($this); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - date_default_timezone_set( 'Pacific/Fiji' ); // UTC+12 |
|
| 51 | - $result->run( $this ); |
|
| 50 | + date_default_timezone_set('Pacific/Fiji'); // UTC+12 |
|
| 51 | + $result->run($this); |
|
| 52 | 52 | |
| 53 | - date_default_timezone_set( 'Pacific/Tahiti' ); // UTC-10: it's a magical place |
|
| 54 | - $result->run( $this ); |
|
| 53 | + date_default_timezone_set('Pacific/Tahiti'); // UTC-10: it's a magical place |
|
| 54 | + $result->run($this); |
|
| 55 | 55 | |
| 56 | - date_default_timezone_set( $this->existing_timezone ); |
|
| 56 | + date_default_timezone_set($this->existing_timezone); |
|
| 57 | 57 | |
| 58 | 58 | return $result; |
| 59 | 59 | } |
@@ -19,8 +19,8 @@ discard block |
||
| 19 | 19 | * @return string The job ID |
| 20 | 20 | */ |
| 21 | 21 | function wc_schedule_single_action( $timestamp, $hook, $args = array(), $group = '' ) { |
| 22 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_single_action()' ); |
|
| 23 | - return as_schedule_single_action( $timestamp, $hook, $args, $group ); |
|
| 22 | + _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_single_action()' ); |
|
| 23 | + return as_schedule_single_action( $timestamp, $hook, $args, $group ); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | * @return string The job ID |
| 38 | 38 | */ |
| 39 | 39 | function wc_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '' ) { |
| 40 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_recurring_action()' ); |
|
| 41 | - return as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args, $group ); |
|
| 40 | + _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_recurring_action()' ); |
|
| 41 | + return as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args, $group ); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | * @return string The job ID |
| 66 | 66 | */ |
| 67 | 67 | function wc_schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), $group = '' ) { |
| 68 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_cron_action()' ); |
|
| 69 | - return as_schedule_cron_action( $timestamp, $schedule, $hook, $args, $group ); |
|
| 68 | + _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_cron_action()' ); |
|
| 69 | + return as_schedule_cron_action( $timestamp, $schedule, $hook, $args, $group ); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -79,8 +79,8 @@ discard block |
||
| 79 | 79 | * @deprecated 2.1.0 |
| 80 | 80 | */ |
| 81 | 81 | function wc_unschedule_action( $hook, $args = array(), $group = '' ) { |
| 82 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_unschedule_action()' ); |
|
| 83 | - as_unschedule_action( $hook, $args, $group ); |
|
| 82 | + _deprecated_function( __FUNCTION__, '2.1.0', 'as_unschedule_action()' ); |
|
| 83 | + as_unschedule_action( $hook, $args, $group ); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -93,8 +93,8 @@ discard block |
||
| 93 | 93 | * @return int|bool The timestamp for the next occurrence, or false if nothing was found |
| 94 | 94 | */ |
| 95 | 95 | function wc_next_scheduled_action( $hook, $args = null, $group = '' ) { |
| 96 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_next_scheduled_action()' ); |
|
| 97 | - return as_next_scheduled_action( $hook, $args, $group ); |
|
| 96 | + _deprecated_function( __FUNCTION__, '2.1.0', 'as_next_scheduled_action()' ); |
|
| 97 | + return as_next_scheduled_action( $hook, $args, $group ); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -121,6 +121,6 @@ discard block |
||
| 121 | 121 | * @return array |
| 122 | 122 | */ |
| 123 | 123 | function wc_get_scheduled_actions( $args = array(), $return_format = OBJECT ) { |
| 124 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_get_scheduled_actions()' ); |
|
| 125 | - return as_get_scheduled_actions( $args, $return_format ); |
|
| 124 | + _deprecated_function( __FUNCTION__, '2.1.0', 'as_get_scheduled_actions()' ); |
|
| 125 | + return as_get_scheduled_actions( $args, $return_format ); |
|
| 126 | 126 | } |
@@ -18,9 +18,9 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @return string The job ID |
| 20 | 20 | */ |
| 21 | -function wc_schedule_single_action( $timestamp, $hook, $args = array(), $group = '' ) { |
|
| 22 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_single_action()' ); |
|
| 23 | - return as_schedule_single_action( $timestamp, $hook, $args, $group ); |
|
| 21 | +function wc_schedule_single_action($timestamp, $hook, $args = array(), $group = '') { |
|
| 22 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_schedule_single_action()'); |
|
| 23 | + return as_schedule_single_action($timestamp, $hook, $args, $group); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @return string The job ID |
| 38 | 38 | */ |
| 39 | -function wc_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '' ) { |
|
| 40 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_recurring_action()' ); |
|
| 41 | - return as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args, $group ); |
|
| 39 | +function wc_schedule_recurring_action($timestamp, $interval_in_seconds, $hook, $args = array(), $group = '') { |
|
| 40 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_schedule_recurring_action()'); |
|
| 41 | + return as_schedule_recurring_action($timestamp, $interval_in_seconds, $hook, $args, $group); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @return string The job ID |
| 66 | 66 | */ |
| 67 | -function wc_schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), $group = '' ) { |
|
| 68 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_cron_action()' ); |
|
| 69 | - return as_schedule_cron_action( $timestamp, $schedule, $hook, $args, $group ); |
|
| 67 | +function wc_schedule_cron_action($timestamp, $schedule, $hook, $args = array(), $group = '') { |
|
| 68 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_schedule_cron_action()'); |
|
| 69 | + return as_schedule_cron_action($timestamp, $schedule, $hook, $args, $group); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @deprecated 2.1.0 |
| 80 | 80 | */ |
| 81 | -function wc_unschedule_action( $hook, $args = array(), $group = '' ) { |
|
| 82 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_unschedule_action()' ); |
|
| 83 | - as_unschedule_action( $hook, $args, $group ); |
|
| 81 | +function wc_unschedule_action($hook, $args = array(), $group = '') { |
|
| 82 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_unschedule_action()'); |
|
| 83 | + as_unschedule_action($hook, $args, $group); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -92,9 +92,9 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @return int|bool The timestamp for the next occurrence, or false if nothing was found |
| 94 | 94 | */ |
| 95 | -function wc_next_scheduled_action( $hook, $args = null, $group = '' ) { |
|
| 96 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_next_scheduled_action()' ); |
|
| 97 | - return as_next_scheduled_action( $hook, $args, $group ); |
|
| 95 | +function wc_next_scheduled_action($hook, $args = null, $group = '') { |
|
| 96 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_next_scheduled_action()'); |
|
| 97 | + return as_next_scheduled_action($hook, $args, $group); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * |
| 121 | 121 | * @return array |
| 122 | 122 | */ |
| 123 | -function wc_get_scheduled_actions( $args = array(), $return_format = OBJECT ) { |
|
| 124 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_get_scheduled_actions()' ); |
|
| 125 | - return as_get_scheduled_actions( $args, $return_format ); |
|
| 123 | +function wc_get_scheduled_actions($args = array(), $return_format = OBJECT) { |
|
| 124 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_get_scheduled_actions()'); |
|
| 125 | + return as_get_scheduled_actions($args, $return_format); |
|
| 126 | 126 | } |