#60018 closed defect (bug) (duplicate)
PHPUnit test for force_ssl_admin
Reported by: |
|
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
@
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:
test_force_ssl_admin_enabled()
: Checks ifforce_ssl_admin()
returnstrue
when the option is enabled.test_force_ssl_admin_disabled()
: Checks ifforce_ssl_admin()
returnsfalse
when the option is disabled.test_force_ssl_admin_redirect()
: Checks if the admin URL starts with 'https://' after enablingforce_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
@
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
fixed in https://core.trac.wordpress.org/ticket/60023