Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsoo committed Jun 28, 2023
1 parent 593338f commit 0f7eb10
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
class Verification_Cron_Schedule_Handler_Test extends TestCase {

/**
* @var \Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler
* The instance.
*
* @var Verification_Cron_Schedule_Handler
*/
private $instance;

/**
* The cron verification gate.
*
* @var \Mockery\MockInterface|Cron_Verification_Gate
*/
private $cron_verification_gate;
Expand All @@ -46,6 +50,12 @@ protected function setUp(): void {
* @covers ::schedule_indexable_verification
*
* @dataProvider schedule_indexable_verification_provider
*
* @param bool $should_verify If the indexable verification is enabled.
* @param bool $post_scheduled If the cron is scheduled.
* @param bool $timestamp_scheduled If the cron is scheduled.
* @param int $time_wp_schedule_event How many times this functions should be called.
*
* @return void
*/
public function test_schedule_indexable_verification(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Yoast\WP\SEO\Tests\Unit\Indexables\Domain;
namespace Yoast\WP\SEO\Tests\Unit\Indexables\User_Interface;

use Mockery;
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
Expand All @@ -18,12 +18,16 @@
class Mark_Deactivation_Integration_Test extends TestCase {

/**
* @var \Yoast\WP\SEO\Indexables\User_Interface\Mark_Deactivation_Integration
* The instance.
*
* @var Mark_Deactivation_Integration
*/
private $instance;

/**
* @var \Mockery\MockInterface|\Yoast\WP\SEO\Helpers\Options_Helper
* The options helper.
*
* @var \Mockery\MockInterface|Options_Helper
*/
private $options_helper;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Yoast\WP\SEO\Tests\Unit\Indexables\Domain;
namespace Yoast\WP\SEO\Tests\Unit\Indexables\User_Interface;

use Mockery;
use Brain\Monkey;
Expand All @@ -20,16 +20,22 @@
class Schedule_Verification_Cron_Integration_Test extends TestCase {

/**
* @var \Yoast\WP\SEO\Indexables\User_Interface\Schedule_Verification_Cron_Integration
* The instance.
*
* @var Schedule_Verification_Cron_Integration
*/
private $instance;

/**
* @var \Mockery\MockInterface|\Yoast\WP\SEO\Helpers\Options_Helper
* The options helper.
*
* @var \Mockery\MockInterface|Options_Helper
*/
private $options_helper;

/**
* The cron schedule handler.
*
* @var \Mockery\MockInterface|Verification_Cron_Schedule_Handler
*/
private $cron_schedule_handler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Yoast\WP\SEO\Tests\Unit\Indexables\Domain;
namespace Yoast\WP\SEO\Tests\Unit\Indexables\User_Interface;

use Brain\Monkey;
use Mockery;
Expand All @@ -25,36 +25,50 @@
class Verification_No_Timestamp_Cron_Callback_Integration_Test extends TestCase {

/**
* @var \Yoast\WP\SEO\Indexables\User_Interface\Verification_No_Timestamp_Cron_Callback_Integration
* The instance.
*
* @var Verification_No_Timestamp_Cron_Callback_Integration
*/
private $instance;

/**
* @var \Mockery\MockInterface|\Yoast\WP\SEO\Helpers\Options_Helper
* The options helper.
*
* @var \Mockery\MockInterface|Options_Helper
*/
private $options_helper;

/**
* The cron schedule handler.
*
* @var \Mockery\MockInterface|Verification_Cron_Schedule_Handler
*/
private $cron_schedule_handler;

/**
* The cron verification gate.
*
* @var \Mockery\MockInterface|Cron_Verification_Gate
*/
private $cron_verification_gate;

/**
* The verification cron batch handler.
*
* @var \Mockery\MockInterface|Verification_Cron_Batch_Handler
*/
private $verification_cron_batch_handler;

/**
* The command handler.
*
* @var \Mockery\MockInterface|Verify_Non_Timestamp_Indexables_Command_Handler
*/
private $verify_non_timestamp_indexables_command_handler;

/**
* The next action handler.
*
* @var \Mockery\MockInterface|Next_Verification_Action_Handler
*/
private $next_verification_action_handler;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?php

namespace Yoast\WP\SEO\Tests\Unit\Indexables\User_Interface;

use Brain\Monkey;
use Mockery;
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Non_Timestamp_Indexables_Command_Handler;
use Yoast\WP\SEO\Indexables\Application\Commands\Verify_Post_Indexables_Command_Handler;
use Yoast\WP\SEO\Indexables\Application\Cron_Verification_Gate;
use Yoast\WP\SEO\Indexables\Application\Next_Verification_Action_Handler;
use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Batch_Handler;
use Yoast\WP\SEO\Indexables\Application\Verification_Cron_Schedule_Handler;
use Yoast\WP\SEO\Indexables\User_Interface\Mark_Deactivation_Integration;
use Yoast\WP\SEO\Indexables\User_Interface\Verification_No_Timestamp_Cron_Callback_Integration;
use Yoast\WP\SEO\Indexables\User_Interface\Verification_Posts_Cron_Callback_Integration;
use Yoast\WP\SEO\Tests\Unit\TestCase;

/**
* The Verification_Posts_Cron_Callback_Integration_Test class.
*
* @group indexables
*
* @coversDefaultClass \Yoast\WP\SEO\Indexables\User_Interface\Verification_Posts_Cron_Callback_Integration
*/
class Verification_Posts_Cron_Callback_Integration_Test extends TestCase {

/**
* The instance.
*
* @var Verification_Posts_Cron_Callback_Integration
*/
private $instance;

/**
* The options helper.
*
* @var \Mockery\MockInterface|Options_Helper
*/
private $options_helper;

/**
* The cron schedule handler.
*
* @var \Mockery\MockInterface|Verification_Cron_Schedule_Handler
*/
private $cron_schedule_handler;

/**
* The cron verification gate.
*
* @var \Mockery\MockInterface|Cron_Verification_Gate
*/
private $cron_verification_gate;

/**
* The verification cron batch handler.
*
* @var \Mockery\MockInterface|Verification_Cron_Batch_Handler
*/
private $verification_cron_batch_handler;

/**
* The command handler.
*
* @var \Mockery\MockInterface|Verify_Post_Indexables_Command_Handler
*/
private $verify_posts_indexables_command_handler;

/**
* The setup function.
*
* @return void
*/
protected function setUp(): void {
parent::setUp();

$this->cron_verification_gate = Mockery::mock( Cron_Verification_Gate::class );
$this->cron_schedule_handler = Mockery::mock( Verification_Cron_Schedule_Handler::class );
$this->options_helper = Mockery::mock( Options_Helper::class );
$this->verification_cron_batch_handler = Mockery::mock( Verification_Cron_Batch_Handler::class );
$this->verify_posts_indexables_command_handler = Mockery::mock( Verify_Post_Indexables_Command_Handler::class );
$this->instance = new Verification_Posts_Cron_Callback_Integration( $this->cron_verification_gate, $this->cron_schedule_handler, $this->options_helper, $this->verification_cron_batch_handler, $this->verify_posts_indexables_command_handler );
}

/**
* Tests the register_hooks function.
*
* @covers ::register_hooks
* @return void
*/
public function test_register_hooks() {
Monkey\Functions\expect( 'add_action' )
->with(
Verification_Cron_Schedule_Handler::INDEXABLE_VERIFY_POST_INDEXABLES_NAME,
[
$this->instance,
'start_verify_posts',
]
);

$this->instance->register_hooks();
}

/**
* Tests the get function.
*
* @covers ::get_conditionals
* @return void
*/
public function test_get_conditionals() {
$this->assertEquals(
[
Admin_Conditional::class,
],
Verification_Posts_Cron_Callback_Integration::get_conditionals()
);
}

/**
* Tests the `start_verify_posts` while a cron is already running.
*
* @covers ::start_verify_posts
*
* @return void
*/
public function test_start_verify_posts_indexables_doing_cron() {
Monkey\Functions\expect( 'wp_doing_cron' )->andReturnTrue();
$this->cron_schedule_handler->expects( 'unschedule_verify_post_indexables_cron' )->once();
$this->instance->start_verify_posts();
}

/**
* Tests the `start_verify_posts` when no cron is running and indexables are enabled.
*
* @covers ::start_verify_posts
*
* @return void
*/
public function test_start_verify_posts_indexables_indexables_disabled() {
Monkey\Functions\expect( 'wp_doing_cron' )->andReturnFalse();
$this->cron_verification_gate->expects( 'should_verify_on_cron' )->andReturnFalse();
$this->cron_schedule_handler->expects( 'unschedule_verify_post_indexables_cron' )->once();
$this->instance->start_verify_posts();
}

/**
* Tests the `start_verify_posts` in a normal flow.
*
* @covers ::start_verify_posts
*
* @return void
*/
public function test_start_verify_posts_indexables() {
Monkey\Functions\expect( 'wp_doing_cron' )->andReturnFalse();
$this->cron_verification_gate->expects( 'should_verify_on_cron' )->andReturnTrue();

$this->verification_cron_batch_handler->expects( 'get_current_post_indexables_batch' )->andReturn( 10 );
$this->options_helper->expects( 'get' )
->with( Mark_Deactivation_Integration::PLUGIN_DEACTIVATED_AT_OPTION, \time() )->andReturn( \time() );

$this->verify_posts_indexables_command_handler->expects( 'handle' );

$this->instance->start_verify_posts();
}
}

0 comments on commit 0f7eb10

Please sign in to comment.