From 0908aeb96d701b8b34bee5e28cb647a35c38a5ed Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Wed, 6 May 2026 15:49:22 -0400 Subject: [PATCH 1/4] Add unit tests for wp_doc_link_parse() in wp-admin/includes/misc.php --- .../admin/includes/misc/wpDocLinkParse.php | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php diff --git a/tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php b/tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php new file mode 100644 index 0000000000000..6e0cb65568cae --- /dev/null +++ b/tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php @@ -0,0 +1,104 @@ +assertSame( $expected, wp_doc_link_parse( $content ) ); + } + + /** + * Data provider for test_wp_doc_link_parse. + * + * @return array + */ + public function data_wp_doc_link_parse(): array { + return array( + 'empty string' => array( + 'content' => '', + 'expected' => array(), + ), + 'null (invalid type)' => array( + 'content' => null, + 'expected' => array(), + ), + 'simple function call' => array( + 'content' => '', + 'expected' => array( 'get_header' ), + ), + 'multiple unique functions' => array( + 'content' => '', + 'expected' => array( 'get_header', 'wp_footer' ), + ), + 'duplicate functions' => array( + 'content' => '', + 'expected' => array( '_e' ), + ), + 'sorted output' => array( + 'content' => '', + 'expected' => array( 'alpha', 'zeta' ), + ), + 'local function definition' => array( + 'content' => '', + 'expected' => array(), + ), + 'class method call' => array( + 'content' => 'my_method(); ?>', + 'expected' => array(), + ), + 'static class method call' => array( + 'content' => '', + 'expected' => array( 'my_static_method' ), // token_get_all handles :: differently. + ), + 'mixed content' => array( + 'content' => 'method(); + esc_html( "test" ); + ?>', + 'expected' => array( 'esc_html', 'wp_remote_get' ), + ), + 'function call with space' => array( + 'content' => '', + 'expected' => array( 'is_array' ), + ), + ); + } + + /** + * Tests the documentation_ignore_functions filter. + * + * @ticket 65182 + */ + public function test_wp_doc_link_parse_filter() { + $filter = function( $ignore ) { + $ignore[] = 'wp_remote_get'; + return $ignore; + }; + + add_filter( 'documentation_ignore_functions', $filter ); + $result = wp_doc_link_parse( '' ); + remove_filter( 'documentation_ignore_functions', $filter ); + + $this->assertSame( array( 'esc_html' ), $result ); + } +} From 6c70203a92eb796f7b16b93bc2fb8d609ee88c8a Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Wed, 6 May 2026 15:52:57 -0400 Subject: [PATCH 2/4] Fix spacing in filter function declaration --- tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php b/tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php index 6e0cb65568cae..455f0ac683532 100644 --- a/tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php +++ b/tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php @@ -90,7 +90,7 @@ function local_f() {} * @ticket 65182 */ public function test_wp_doc_link_parse_filter() { - $filter = function( $ignore ) { + $filter = function ( $ignore ) { $ignore[] = 'wp_remote_get'; return $ignore; }; From fd1a7ef2e295c4567b94078f0d4cd7cadff4bf04 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Wed, 6 May 2026 16:18:09 -0400 Subject: [PATCH 3/4] Fix array keys formatting in wpDocLinkParse.php --- .../admin/includes/misc/wpDocLinkParse.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php b/tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php index 455f0ac683532..12487531ecbd4 100644 --- a/tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php +++ b/tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php @@ -35,39 +35,39 @@ public function data_wp_doc_link_parse(): array { 'content' => '', 'expected' => array(), ), - 'null (invalid type)' => array( + 'null (invalid type)' => array( 'content' => null, 'expected' => array(), ), - 'simple function call' => array( + 'simple function call' => array( 'content' => '', 'expected' => array( 'get_header' ), ), - 'multiple unique functions' => array( + 'multiple unique functions' => array( 'content' => '', 'expected' => array( 'get_header', 'wp_footer' ), ), - 'duplicate functions' => array( + 'duplicate functions' => array( 'content' => '', 'expected' => array( '_e' ), ), - 'sorted output' => array( + 'sorted output' => array( 'content' => '', 'expected' => array( 'alpha', 'zeta' ), ), - 'local function definition' => array( + 'local function definition' => array( 'content' => '', 'expected' => array(), ), - 'class method call' => array( + 'class method call' => array( 'content' => 'my_method(); ?>', 'expected' => array(), ), - 'static class method call' => array( + 'static class method call' => array( 'content' => '', 'expected' => array( 'my_static_method' ), // token_get_all handles :: differently. ), - 'mixed content' => array( + 'mixed content' => array( 'content' => '', 'expected' => array( 'esc_html', 'wp_remote_get' ), ), - 'function call with space' => array( + 'function call with space' => array( 'content' => '', 'expected' => array( 'is_array' ), ), From 18c91ac9d00c49f8318db44f63352c78dc5fc321 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Wed, 6 May 2026 16:20:19 -0400 Subject: [PATCH 4/4] Update wpDocLinkParse.php --- tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php b/tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php index 12487531ecbd4..d2ed3ad3d87a2 100644 --- a/tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php +++ b/tests/phpunit/tests/admin/includes/misc/wpDocLinkParse.php @@ -31,7 +31,7 @@ public function test_wp_doc_link_parse( $content, $expected ) { */ public function data_wp_doc_link_parse(): array { return array( - 'empty string' => array( + 'empty string' => array( 'content' => '', 'expected' => array(), ),