summaryrefslogtreecommitdiffstatshomepage
path: root/tests/phpunit
diff options
context:
space:
mode:
authorSergey Biryukov <sergeybiryukov@git.wordpress.org>2025-04-08 18:02:14 +0000
committerSergey Biryukov <sergeybiryukov@git.wordpress.org>2025-04-08 18:02:14 +0000
commitac648a15245df2261c0782f7e1c618911f392601 (patch)
tree6c0559276eb24da873ed0e809926894cf887a4cd /tests/phpunit
parent6511cc02f764a3d9c0dd105e5366fdfe63a564cc (diff)
downloadwordpress-ac648a15245df2261c0782f7e1c618911f392601.tar.gz
wordpress-ac648a15245df2261c0782f7e1c618911f392601.zip
General: Correct `force_ssl_content()` to always return a boolean value.
This aims to bring parity with `force_ssl_admin()`. Includes: * Allowing `force_ssl_content()` to properly accept `false` as a value. * Correcting an erroneous `! $force` conditional that should have been reversed. * Adding unit tests to confirm valid behavior. Follow-up to [https://mu.trac.wordpress.org/changeset/1979 mu:1979], [11903], [12603], [47808], [59830]. Props justlevine for initial patch. See #52217. git-svn-id: https://develop.svn.wordpress.org/trunk@60147 602fd350-edb4-49c9-b593-d223f7449a82
Diffstat (limited to 'tests/phpunit')
-rw-r--r--tests/phpunit/tests/multisite/forceSslContent.php53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/phpunit/tests/multisite/forceSslContent.php b/tests/phpunit/tests/multisite/forceSslContent.php
new file mode 100644
index 0000000000..b701dd013a
--- /dev/null
+++ b/tests/phpunit/tests/multisite/forceSslContent.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * Test cases for the `force_ssl_content()` function.
+ *
+ * @since 6.9.0
+ *
+ * @group functions
+ * @group multisite
+ * @group ms-required
+ *
+ * @covers ::force_ssl_content
+ */
+class Tests_Functions_ForceSslContent extends WP_UnitTestCase {
+
+ public function set_up() {
+ parent::set_up();
+ // Reset the `$forced_content` static variable before each test.
+ force_ssl_content( false );
+ }
+
+ /**
+ * Tests that force_ssl_content() returns expected values based on various inputs.
+ *
+ * @dataProvider data_force_ssl_content
+ *
+ * @param mixed $input The input value to test.
+ * @param bool $expected The expected result for subsequent calls.
+ */
+ public function test_force_ssl_content( $input, $expected ) {
+ // The first call always returns the previous value.
+ $this->assertFalse( force_ssl_content( $input ), 'First call did not return the expected value' );
+
+ // Call again to check subsequent behavior.
+ $this->assertSame( $expected, force_ssl_content( $input ), 'Subsequent call did not return the expected value' );
+ }
+
+ /**
+ * Data provider for testing force_ssl_content().
+ *
+ * @return array[]
+ */
+ public function data_force_ssl_content() {
+ return array(
+ 'default' => array( null, false ),
+ 'true' => array( true, true ),
+ 'false' => array( false, false ),
+ 'non-empty string' => array( 'some string', true ),
+ 'empty string' => array( '', false ),
+ 'integer 1' => array( 1, true ),
+ 'integer 0' => array( 0, false ),
+ );
+ }
+}