|
5 | 5 | * @package WP-Background-Processing |
6 | 6 | */ |
7 | 7 |
|
8 | | - require_once __DIR__ . '/fixtures/Test_Batch_Data.php'; |
| 8 | +require_once __DIR__ . '/fixtures/Test_Batch_Data.php'; |
9 | 9 |
|
10 | 10 | use PHPUnit\Framework\MockObject\MockObject; |
11 | 11 |
|
@@ -208,31 +208,31 @@ public function test_get_batch() { |
208 | 208 | $this->assertEquals( array( $batch_data_object ), $this->getWPBPProperty( 'data' ) ); |
209 | 209 | $this->wpbp->save(); |
210 | 210 | $third_batch = $this->executeWPBPMethod( 'get_batch' ); |
211 | | - $this->assertCount( 1, $third_batch->data ); |
| 211 | + $this->assertCount( 1, $third_batch->data ); |
212 | 212 | $this->assertInstanceOf( Test_Batch_Data::class, $third_batch->data[0] ); |
213 | 213 |
|
214 | 214 | // Explicitly set allowed classes to Test_Batch_Data. |
215 | 215 | $this->setWPBPProperty( 'allowed_batch_data_classes', array( Test_Batch_Data::class ) ); |
216 | 216 | $third_batch = $this->executeWPBPMethod( 'get_batch' ); |
217 | | - $this->assertCount( 1, $third_batch->data ); |
| 217 | + $this->assertCount( 1, $third_batch->data ); |
218 | 218 | $this->assertInstanceOf( Test_Batch_Data::class, $third_batch->data[0] ); |
219 | 219 |
|
220 | 220 | // Allow a different class. |
221 | 221 | $this->setWPBPProperty( 'allowed_batch_data_classes', array( stdClass::class ) ); |
222 | 222 | $third_batch = $this->executeWPBPMethod( 'get_batch' ); |
223 | | - $this->assertCount( 1, $third_batch->data ); |
| 223 | + $this->assertCount( 1, $third_batch->data ); |
224 | 224 | $this->assertInstanceOf( __PHP_Incomplete_Class::class, $third_batch->data[0] ); |
225 | 225 |
|
226 | 226 | // Disallow all classes. |
227 | 227 | $this->setWPBPProperty( 'allowed_batch_data_classes', false ); |
228 | 228 | $third_batch = $this->executeWPBPMethod( 'get_batch' ); |
229 | | - $this->assertCount( 1, $third_batch->data ); |
| 229 | + $this->assertCount( 1, $third_batch->data ); |
230 | 230 | $this->assertInstanceOf( __PHP_Incomplete_Class::class, $third_batch->data[0] ); |
231 | 231 |
|
232 | 232 | // Allow everything. |
233 | 233 | $this->setWPBPProperty( 'allowed_batch_data_classes', true ); |
234 | 234 | $third_batch = $this->executeWPBPMethod( 'get_batch' ); |
235 | | - $this->assertCount( 1, $third_batch->data ); |
| 235 | + $this->assertCount( 1, $third_batch->data ); |
236 | 236 | $this->assertInstanceOf( Test_Batch_Data::class, $third_batch->data[0] ); |
237 | 237 | } |
238 | 238 |
|
@@ -642,4 +642,31 @@ public function test_is_active() { |
642 | 642 | $this->wpbp->maybe_handle(); |
643 | 643 | $this->assertFalse( $this->wpbp->is_active(), 'cancel handled, queue emptied, so no longer active' ); |
644 | 644 | } |
| 645 | + |
| 646 | + /** |
| 647 | + * Test get_cron_interval. |
| 648 | + * |
| 649 | + * @return void |
| 650 | + */ |
| 651 | + public function test_get_cron_interval() { |
| 652 | + // Default value. |
| 653 | + $this->assertEquals( 5, $this->wpbp->get_cron_interval() ); |
| 654 | + |
| 655 | + // Override via property (usually on subclass). |
| 656 | + $this->wpbp->cron_interval = 3; |
| 657 | + $this->assertEquals( 3, $this->wpbp->get_cron_interval() ); |
| 658 | + |
| 659 | + // Override via filter. |
| 660 | + $callback = function ( $interval ) { |
| 661 | + return 1; |
| 662 | + }; |
| 663 | + add_filter( $this->getWPBPProperty( 'identifier' ) . '_cron_interval', $callback ); |
| 664 | + $this->assertEquals( 1, $this->wpbp->get_cron_interval() ); |
| 665 | + |
| 666 | + remove_filter( $this->getWPBPProperty( 'identifier' ) . '_cron_interval', $callback ); |
| 667 | + $this->assertEquals( 3, $this->wpbp->get_cron_interval() ); |
| 668 | + |
| 669 | + unset( $this->wpbp->cron_interval ); |
| 670 | + $this->assertEquals( 5, $this->wpbp->get_cron_interval() ); |
| 671 | + } |
645 | 672 | } |
0 commit comments