From a835af5de9cdd66553d3217dd26252c5be4f7bba Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Mon, 19 Oct 2026 12:59:12 +0530 Subject: [PATCH] Tests: Add unit tests for `wp_is_recovery_mode()` --- tests/phpunit/tests/load/wpIsRecoveryMode.php | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/phpunit/tests/load/wpIsRecoveryMode.php diff --git a/tests/phpunit/tests/load/wpIsRecoveryMode.php b/tests/phpunit/tests/load/wpIsRecoveryMode.php new file mode 100644 index 0000000000000..a1f6c8836b4c6 --- /dev/null +++ b/tests/phpunit/tests/load/wpIsRecoveryMode.php @@ -0,0 +1,89 @@ +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 ) { + $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() ); + } +}