diff --git a/tests/php/src/Validation/SavePostValidationEventTest.php b/tests/php/src/Validation/SavePostValidationEventTest.php index 2e42f6d272a..a9b459057a0 100644 --- a/tests/php/src/Validation/SavePostValidationEventTest.php +++ b/tests/php/src/Validation/SavePostValidationEventTest.php @@ -8,6 +8,7 @@ use AmpProject\AmpWP\BackgroundTask\BackgroundTaskDeactivator; use AmpProject\AmpWP\BackgroundTask\SingleScheduledBackgroundTask; use AmpProject\AmpWP\DevTools\UserAccess; +use AmpProject\AmpWP\Infrastructure\Conditional; use AmpProject\AmpWP\Infrastructure\Registerable; use AmpProject\AmpWP\Infrastructure\Service; use AmpProject\AmpWP\Tests\Helpers\AssertContainsCompatibility; @@ -49,6 +50,17 @@ public function test__construct() { $this->assertInstanceof( SavePostValidationEvent::class, $this->test_instance ); $this->assertInstanceof( Service::class, $this->test_instance ); $this->assertInstanceof( Registerable::class, $this->test_instance ); + $this->assertInstanceof( Conditional::class, $this->test_instance ); + } + + /** @covers ::is_needed() */ + public function test_is_needed() { + $this->assertFalse( SavePostValidationEvent::is_needed() ); + + add_filter( 'amp_temp_validation_cron_tasks_enabled', '__return_true' ); + $this->assertTrue( SavePostValidationEvent::is_needed() ); + + remove_filter( 'amp_temp_validation_cron_tasks_enabled', '__return_true' ); } /** diff --git a/tests/php/src/Validation/URLValidationCronTest.php b/tests/php/src/Validation/URLValidationCronTest.php index b6d16abe5ae..654a60f1d4a 100644 --- a/tests/php/src/Validation/URLValidationCronTest.php +++ b/tests/php/src/Validation/URLValidationCronTest.php @@ -4,6 +4,7 @@ use AmpProject\AmpWP\BackgroundTask\BackgroundTaskDeactivator; use AmpProject\AmpWP\BackgroundTask\CronBasedBackgroundTask; +use AmpProject\AmpWP\Infrastructure\Conditional; use AmpProject\AmpWP\Infrastructure\Registerable; use AmpProject\AmpWP\Infrastructure\Service; use AmpProject\AmpWP\Tests\Helpers\PrivateAccess; @@ -45,6 +46,7 @@ public function test_register() { $this->assertInstanceof( URLValidationCron::class, $this->test_instance ); $this->assertInstanceof( Service::class, $this->test_instance ); $this->assertInstanceof( Registerable::class, $this->test_instance ); + $this->assertInstanceof( Conditional::class, $this->test_instance ); $this->test_instance->register(); @@ -52,6 +54,16 @@ public function test_register() { $this->assertEquals( 10, has_action( URLValidationCron::BACKGROUND_TASK_NAME, [ $this->test_instance, 'process' ] ) ); } + /** @covers ::is_needed() */ + public function test_is_needed() { + $this->assertFalse( URLValidationCron::is_needed() ); + + add_filter( 'amp_temp_validation_cron_tasks_enabled', '__return_true' ); + $this->assertTrue( URLValidationCron::is_needed() ); + + remove_filter( 'amp_temp_validation_cron_tasks_enabled', '__return_true' ); + } + /** @covers ::schedule_event() */ public function test_schedule_event_with_no_user() { $event_name = $this->call_private_method( $this->test_instance, 'get_event_name' );