Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions tests/phpunit/tests/load/wpIsRecoveryMode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

/**
* Tests for wp_is_recovery_mode().
*
* @group load
* @group error-protection
*
* @covers ::wp_is_recovery_mode
*/
class Tests_Load_WpIsRecoveryMode extends WP_UnitTestCase {

/**
* Original recovery mode is_active property.
*
* @var bool
*/
private $original_is_active;

public function set_up() {
parent::set_up();

$this->original_is_active = $this->get_recovery_mode_property( 'is_active' );
}

public function tear_down() {
$this->set_recovery_mode_active( $this->original_is_active );

parent::tear_down();
}

/**
* Gets a WP_Recovery_Mode property value.
*
* @param string $property Property name.
* @return mixed Property value.
*/
private function get_recovery_mode_property( $property ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional, and it applies to several PRs in this series (#14482, #14480, #14477, #14476, #14475): each copies the same reflection helpers to read and set the recovery mode state. Also, tear_down() does not need to restore options or hooks. The test framework rolls back the database and restores hooks after each test.

$reflection = new ReflectionProperty( wp_recovery_mode(), $property );
if ( PHP_VERSION_ID < 80100 ) {
$reflection->setAccessible( true );
}

return $reflection->getValue( wp_recovery_mode() );
}

/**
* Sets whether recovery mode is active.
*
* @param bool $is_active Whether recovery mode is active.
*/
private function set_recovery_mode_active( $is_active ) {
$reflection = new ReflectionProperty( wp_recovery_mode(), 'is_active' );
if ( PHP_VERSION_ID < 80100 ) {
$reflection->setAccessible( true );
}

$reflection->setValue( wp_recovery_mode(), $is_active );
}

/**
* @ticket 65819
*/
public function test_returns_false_when_recovery_mode_is_inactive() {
$this->set_recovery_mode_active( false );

$this->assertFalse( wp_is_recovery_mode() );
}

/**
* @ticket 65819
*/
public function test_returns_true_when_recovery_mode_is_active() {
$this->set_recovery_mode_active( true );

$this->assertTrue( wp_is_recovery_mode() );
}

/**
* @ticket 65819
*/
public function test_matches_recovery_mode_singleton_state() {
$this->set_recovery_mode_active( false );
$this->assertSame( wp_recovery_mode()->is_active(), wp_is_recovery_mode() );

$this->set_recovery_mode_active( true );
$this->assertSame( wp_recovery_mode()->is_active(), wp_is_recovery_mode() );
}
}
Loading