Make WordPress Core

Opened 7 months ago

Closed 5 months ago

#60018 closed defect (bug) (duplicate)

PHPUnit test for force_ssl_admin

Reported by: pbearne's profile pbearne Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch has-unit-tests
Focuses: Cc:


Change History (4)

This ticket was mentioned in PR #5730 on WordPress/wordpress-develop by @pbearne.

7 months ago

  • Keywords has-patch has-unit-tests added

#3 @flihovituhe1982
5 months ago

Sure, here's an example PHPUnit test for the force_ssl_admin functionality in WordPress:

class ForceSslAdminTest extends WP_UnitTestCase {

Test that force_ssl_admin is enabled
function test_force_ssl_admin_enabled() {



Test that force_ssl_admin is disabled when turned off
function test_force_ssl_admin_disabled() {

update_option('force_ssl_admin', 0);


Test that force_ssl_admin redirects admin urls to https when enabled

function test_force_ssl_admin_redirect() {

update_option('force_ssl_admin', 1);
$admin_url = admin_url();
$this->assertStringStartsWith('https://', $admin_url);



This PHPUnit test class includes three test methods:

  1. test_force_ssl_admin_enabled(): Checks if force_ssl_admin() returns true when the option is enabled.
  2. test_force_ssl_admin_disabled(): Checks if force_ssl_admin() returns false when the option is disabled.
  3. test_force_ssl_admin_redirect(): Checks if the admin URL starts with 'https://' after enabling force_ssl_admin.

Make sure you have the necessary setup for running PHPUnit tests in your WordPress environment. This includes having PHPUnit installed and configuring wp-tests-config.php properly.

#4 @swissspidy
5 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #57261.

Note: See TracTickets for help on using tickets.