From 7f341bd504804c1fea2a4b28c41e4592f2434084 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Mon, 27 Apr 2026 13:55:39 -0400 Subject: [PATCH 1/2] Add unit tests for got_mod_rewrite() in src/wp-admin/includes/misc.php Reference: https://core.trac.wordpress.org/ticket/65134 --- .../admin/includes/misc/gotModRewrite.php | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/phpunit/tests/admin/includes/misc/gotModRewrite.php diff --git a/tests/phpunit/tests/admin/includes/misc/gotModRewrite.php b/tests/phpunit/tests/admin/includes/misc/gotModRewrite.php new file mode 100644 index 0000000000000..1b0b57c1a621c --- /dev/null +++ b/tests/phpunit/tests/admin/includes/misc/gotModRewrite.php @@ -0,0 +1,91 @@ +temp_filter_value = $filter_value; + } + + // 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() ); + + if ( null !== $filter_value ) { + remove_filter( 'got_rewrite', array( $this, 'filter_got_rewrite' ) ); + unset( $this->temp_filter_value ); + } + } + + /** + * 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. + * } + */ + public function data_got_mod_rewrite() { + 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, + ), + ); + } + + /** + * Temporary property for filter value. + * @var bool + */ + private $temp_filter_value; + + /** + * Filter callback for 'got_rewrite'. + * + * @return bool + */ + public function filter_got_rewrite() { + return $this->temp_filter_value; + } +} From 53ae4e0ca6e8ffcfc9e657ef61071a17afbb2a27 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Mon, 27 Apr 2026 15:27:55 -0400 Subject: [PATCH 2/2] Ensure empty marker lines are excluded in src/wp-admin/includes/misc.php --- src/wp-admin/includes/misc.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/misc.php b/src/wp-admin/includes/misc.php index 3724684ffd428..942f75b90e8e0 100644 --- a/src/wp-admin/includes/misc.php +++ b/src/wp-admin/includes/misc.php @@ -86,7 +86,9 @@ function extract_from_markers( $filename, $marker ) { continue; } - $result[] = $markerline; + if ( '' !== $markerline ) { + $result[] = $markerline; + } } if ( str_contains( $markerline, '# BEGIN ' . $marker ) ) {