Skip to content

Commit

Permalink
Add unit test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Debarghya-Banerjee committed Oct 23, 2024
1 parent 510d5ac commit a29d13a
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/phpunit/tests/functions/forceSslAdmin.php
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

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Variable "$expectedFirstCall" is not in valid snake_case format, try "$expected_first_call"

Check warning on line 49 in tests/phpunit/tests/functions/forceSslAdmin.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Variable "$expectedSubsequentCall" is not in valid snake_case format, try "$expected_subsequent_call"
$this->assertSame( $expectedFirstCall, force_ssl_admin( $input ), 'First call did not return expected value' );

Check warning on line 50 in tests/phpunit/tests/functions/forceSslAdmin.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Variable "$expectedFirstCall" is not in valid snake_case format, try "$expected_first_call"

// Call again to check subsequent behavior
$this->assertSame( $expectedSubsequentCall, force_ssl_admin( $input ), 'Subsequent call did not return expected value' );

Check warning on line 53 in tests/phpunit/tests/functions/forceSslAdmin.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Variable "$expectedSubsequentCall" is not in valid snake_case format, try "$expected_subsequent_call"
}
}

0 comments on commit a29d13a

Please sign in to comment.