#60018 closed defect (bug) (duplicate)
PHPUnit test for force_ssl_admin
| Reported by: | pbearne | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Build/Test Tools | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
Change History (6)
This ticket was mentioned in PR #5730 on WordPress/wordpress-develop by @pbearne.
3 years ago
#1
- Keywords has-patch has-unit-tests added
#3
@
2 years 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()returnstruewhen the option is enabled.test_force_ssl_admin_disabled(): Checks ifforce_ssl_admin()returnsfalsewhen 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
@
2 years ago
- Milestone Awaiting Review
- Resolution → duplicate
- Status new → closed
Duplicate of #57261.
@swissspidy commented on PR #5730:
21 months ago
#5
Closing in favor of #3718
@swissspidy commented on PR #5730:
21 months ago
#6
Closing in favor of #7624 which adds a data provider and fixes the type casr
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
fixed in https://core.trac.wordpress.org/ticket/60023