Make WordPress Core

Opened 16 months ago

Closed 13 months ago

Last modified 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:

Description


Change History (6)

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


16 months ago
#1

  • Keywords has-patch has-unit-tests added

#3 @flihovituhe1982
13 months ago

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

`php
<?php
class ForceSslAdminTest extends WP_UnitTestCase {

Test that force_ssl_admin is enabled
function test_force_ssl_admin_enabled() {

$this->assertTrue(force_ssl_admin());

}

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

update_option('force_ssl_admin', 0);
$this->assertFalse(force_ssl_admin());

}

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
13 months ago

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

Duplicate of #57261.

@swissspidy commented on PR #5730:


5 months ago
#5

Closing in favor of #3718

@swissspidy commented on PR #5730:


5 months ago
#6

Closing in favor of #7624 which adds a data provider and fixes the type casr

Note: See TracTickets for help on using tickets.