Skip to content
This repository has been archived by the owner on Jun 14, 2022. It is now read-only.

Commit

Permalink
Add unit tests for Redirect class
Browse files Browse the repository at this point in the history
  • Loading branch information
kienstra committed Jan 10, 2022
1 parent 753e43a commit cd3ce53
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions tests/integration/migration/test-redirect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* Atomic Blocks Test_Redirect tests.
*
* @package AtomicBlocks\Tests
*/

namespace AtomicBlocks\Tests;

use stdClass;
use Atomic_Blocks\Admin\Migration\Redirect;

/**
* Class Test_Redirect
*
* @package AtomicBlocks\Tests
*/
class Test_Redirect extends \WP_UnitTestCase {

/**
* The option name to do the redirect.
*
* @var string
*/
const REDIRECT_OPTION_NAME = 'atomic_blocks_do_activation_redirect';

/**
* The instance to test.
*
* @var Redirect
*/
public $instance;

/**
* Sets up each test.
*/
public function setUp() {
parent::setUp();
$this->instance = new Redirect();
}

/**
* Tears down after each test.
*/
public function tearDown() {
delete_option( self::REDIRECT_OPTION_NAME );
parent::tearDown();
}

/**
* Test redirect_after_upgrade.
*/
public function test_redirect_after_upgrade_wrong_user() {
$this->instance->redirect_after_upgrade( new stdClass(), [] );
$this->assertFalse( get_option( self::REDIRECT_OPTION_NAME ) );
}

/**
* Test redirect_after_upgrade.
*/
public function test_redirect_after_upgrade_correct_user_wrong_plugin() {
wp_set_current_user( $this->factory()->user->create( [ 'role' => 'administrator' ] ) );
$this->instance->redirect_after_upgrade( new stdClass(), [ 'plugins' => [ 'foo/foo.php' ] ] );

$this->assertFalse( get_option( self::REDIRECT_OPTION_NAME ) );
}

/**
* Test redirect_after_upgrade.
*/
public function test_redirect_after_upgrade_correct_user_correct_plugin() {
wp_set_current_user( $this->factory()->user->create( [ 'role' => 'administrator' ] ) );
$this->instance->redirect_after_upgrade( new stdClass(), [ 'plugins' => [ 'atomic-blocks/atomicblocks.php' ] ] );

$this->assertTrue( get_option( self::REDIRECT_OPTION_NAME ) );
}
}

0 comments on commit cd3ce53

Please sign in to comment.