|
2 | 2 | /** |
3 | 3 | * Test cases for the `force_ssl_admin()` function. |
4 | 4 | * |
5 | | - * @package WordPress\UnitTests |
6 | | - * |
7 | 5 | * @since 6.8.0 |
8 | 6 | * |
9 | 7 | * @group functions |
|
12 | 10 | */ |
13 | 11 | class Tests_Functions_ForceSslAdmin extends WP_UnitTestCase { |
14 | 12 |
|
15 | | - public function set_up(): void { |
| 13 | + public function set_up() { |
16 | 14 | parent::set_up(); |
17 | | - // Reset the static variable before each test |
| 15 | + // Reset the `$forced` static variable before each test. |
18 | 16 | force_ssl_admin( false ); |
19 | 17 | } |
20 | 18 |
|
21 | 19 | /** |
22 | | - * Data provider for testing force_ssl_admin. |
| 20 | + * Tests that force_ssl_admin() returns expected values based on various inputs. |
23 | 21 | * |
24 | | - * Provides various inputs and expected outcomes for the function. |
| 22 | + * @dataProvider data_force_ssl_admin |
25 | 23 | * |
26 | | - * @return array[] |
| 24 | + * @param mixed $input The input value to test. |
| 25 | + * @param bool $expected The expected result for subsequent calls. |
27 | 26 | */ |
28 | | - public function data_should_return_expected_value_when_various_inputs_are_passed() { |
29 | | - return array( |
30 | | - 'default' => array( null, false, false ), |
31 | | - 'first_call_true' => array( true, false, true ), |
32 | | - 'first_call_false' => array( false, false, false ), |
33 | | - 'first_call_non_empty_string' => array( 'some string', false, true ), |
34 | | - 'empty_string' => array( '', false, false ), |
35 | | - 'first_call_integer_1' => array( 1, false, true ), |
36 | | - 'integer_0' => array( 0, false, false ), |
37 | | - ); |
| 27 | + public function test_force_ssl_admin( $input, $expected ) { |
| 28 | + // The first call always returns the previous value. |
| 29 | + $this->assertFalse( force_ssl_admin( $input ), 'First call did not return the expected value' ); |
| 30 | + |
| 31 | + // Call again to check subsequent behavior. |
| 32 | + $this->assertSame( $expected, force_ssl_admin( $input ), 'Subsequent call did not return the expected value' ); |
38 | 33 | } |
39 | 34 |
|
40 | 35 | /** |
41 | | - * Tests that force_ssl_admin returns expected values based on various inputs. |
| 36 | + * Data provider for testing force_ssl_admin(). |
42 | 37 | * |
43 | | - * @dataProvider data_should_return_expected_value_when_various_inputs_are_passed |
44 | | - * |
45 | | - * @param mixed $input The input value to test. |
46 | | - * @param bool $expected_first_call The expected result for the first call. |
47 | | - * @param bool $expected_subsequent_call The expected result for subsequent calls. |
| 38 | + * @return array[] |
48 | 39 | */ |
49 | | - public function test_should_return_expected_value_when_various_inputs_are_passed( $input, $expected_first_call, $expected_subsequent_call ) { |
50 | | - $this->assertSame( $expected_first_call, force_ssl_admin( $input ), 'First call did not return expected value' ); |
51 | | - |
52 | | - // Call again to check subsequent behavior |
53 | | - $this->assertSame( $expected_subsequent_call, force_ssl_admin( $input ), 'Subsequent call did not return expected value' ); |
| 40 | + public function data_force_ssl_admin() { |
| 41 | + return array( |
| 42 | + 'default' => array( null, false ), |
| 43 | + 'true' => array( true, true ), |
| 44 | + 'false' => array( false, false ), |
| 45 | + 'non-empty string' => array( 'some string', true ), |
| 46 | + 'empty string' => array( '', false ), |
| 47 | + 'integer 1' => array( 1, true ), |
| 48 | + 'integer 0' => array( 0, false ), |
| 49 | + ); |
54 | 50 | } |
55 | 51 | } |
0 commit comments