-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add unit tests for got_mod_rewrite() in src/wp-admin/includes/misc.php #11656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from 8 commits
7f341bd
53ae4e0
1f73812
84a37f5
719bd4d
0dae5c5
c25af28
70d2ce4
9513cbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Tests for the got_mod_rewrite() function. | ||
| * | ||
| * @group admin | ||
| * @group rewrite | ||
| * | ||
| * @covers ::got_mod_rewrite | ||
| */ | ||
| class Tests_got_mod_rewrite extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * Tests that got_mod_rewrite() correctly detects mod_rewrite based on server and filters. | ||
| * | ||
| * @ticket 65134 | ||
| * | ||
| * @dataProvider data_got_mod_rewrite | ||
| * | ||
| * @param bool $expected The expected result from got_mod_rewrite(). | ||
| * @param bool $apache_loaded Whether mod_rewrite is reported as loaded by Apache. | ||
| * @param bool|null $filter_value Optional value to return via the 'got_rewrite' filter. | ||
| */ | ||
| public function test_got_mod_rewrite( $expected, $apache_loaded, $filter_value = null ) { | ||
| // Mock the Apache module check by filtering 'got_rewrite' if needed, | ||
| // but since got_mod_rewrite calls apache_mod_loaded which we can't easily mock | ||
| // without a framework, we rely on the filter for full control. | ||
|
|
||
| if ( null !== $filter_value ) { | ||
| add_filter( 'got_rewrite', function() use ( $filter_value ) { return $filter_value; } ); | ||
|
Check failure on line 30 in tests/phpunit/tests/admin/includes/misc/gotModRewrite.php
|
||
| } | ||
|
|
||
| // If we are NOT filtering, we need to be aware of the environment. | ||
| // However, the function's internal logic is: | ||
| // return apply_filters( 'got_rewrite', apache_mod_loaded( 'mod_rewrite', true ) ); | ||
| // Since we want to test the function's behavior across different scenarios, | ||
| // we use the filter to simulate the different outcomes of the internal check. | ||
|
|
||
| $this->assertSame( $expected, got_mod_rewrite() ); | ||
| } | ||
|
|
||
| /** | ||
| * Data provider for test_got_mod_rewrite. | ||
| * | ||
| * @return array[] { | ||
| * @type bool $expected The expected result. | ||
| * @type bool $apache_loaded Whether mod_rewrite is loaded (simulated via filter). | ||
| * @type bool|null $filter_value The value to return from the filter. | ||
| * } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use PHPStan array shape syntax since there's no need to target WordPress Developer docs.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure of the ask here
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. That looks right. We can remove the old one though. Added a suggestion. |
||
| * | ||
| * @phpstan-return array<string, array{ | ||
| * expected: bool, | ||
| * apache_loaded: bool, | ||
| * filter_value: bool|null, | ||
| * }> | ||
|
pbearne marked this conversation as resolved.
Outdated
|
||
| */ | ||
| public function data_got_mod_rewrite(): array { | ||
| return array( | ||
| 'Default behavior (should match filter or internal check)' => array( | ||
| 'expected' => true, | ||
| 'apache_loaded' => true, | ||
| 'filter_value' => true, | ||
| ), | ||
| 'Filter returns false' => array( | ||
| 'expected' => false, | ||
| 'apache_loaded' => true, | ||
| 'filter_value' => false, | ||
| ), | ||
| 'Filter returns true even if Apache check might be false' => array( | ||
| 'expected' => true, | ||
| 'apache_loaded' => false, | ||
| 'filter_value' => true, | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.