This repository has been archived by the owner on Jun 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) ); | ||
} | ||
} |