Skip to content

Commit

Permalink
Test that cron services are conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
pierlon committed Feb 18, 2021
1 parent 1dcd3f6 commit f12c5d5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/php/src/Validation/SavePostValidationEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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' );
}

/**
Expand Down
12 changes: 12 additions & 0 deletions tests/php/src/Validation/URLValidationCronTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,13 +46,24 @@ 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();

$this->assertEquals( 10, has_action( 'admin_init', [ $this->test_instance, 'schedule_event' ] ) );
$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' );
Expand Down

0 comments on commit f12c5d5

Please sign in to comment.