mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
1 parent
510d5ac
commit a29d13a
Showing
1 changed file
with
55 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,55 @@ | ||
<?php | ||
/** | ||
* Test cases for the `force_ssl_admin()` function. | ||
* | ||
* @package WordPress\UnitTests | ||
* | ||
* @since 6.8.0 | ||
* | ||
* @group functions | ||
* | ||
* @covers ::force_ssl_admin | ||
*/ | ||
class Tests_Functions_ForceSslAdmin extends WP_UnitTestCase { | ||
|
||
public function set_up(): void { | ||
parent::set_up(); | ||
// Reset the static variable before each test | ||
force_ssl_admin( false ); | ||
} | ||
|
||
/** | ||
* Data provider for testing force_ssl_admin. | ||
* | ||
* Provides various inputs and expected outcomes for the function. | ||
* | ||
* @return array[] | ||
*/ | ||
public function data_should_return_expected_value_when_various_inputs_are_passed() { | ||
return array( | ||
'default' => array( null, false, false ), | ||
'first_call_true' => array( true, false, true ), | ||
'first_call_false' => array( false, false, false ), | ||
'first_call_non_empty_string' => array( 'some string', false, true ), | ||
'empty_string' => array( '', false, false ), | ||
'first_call_integer_1' => array( 1, false, true ), | ||
'integer_0' => array( 0, false, false ), | ||
); | ||
} | ||
|
||
/** | ||
* Tests that force_ssl_admin returns expected values based on various inputs. | ||
* | ||
* @dataProvider data_should_return_expected_value_when_various_inputs_are_passed | ||
* | ||
* @param mixed $input The input value to test. | ||
* @param bool $expectedFirstCall The expected result for the first call. | ||
* @param bool $expectedSubsequentCall The expected result for subsequent calls. | ||
*/ | ||
public function test_should_return_expected_value_when_various_inputs_are_passed( $input, $expectedFirstCall, $expectedSubsequentCall ) { | ||
Check warning on line 49 in tests/phpunit/tests/functions/forceSslAdmin.php
|
||
$this->assertSame( $expectedFirstCall, force_ssl_admin( $input ), 'First call did not return expected value' ); | ||
|
||
// Call again to check subsequent behavior | ||
$this->assertSame( $expectedSubsequentCall, force_ssl_admin( $input ), 'Subsequent call did not return expected value' ); | ||
} | ||
} |