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..d2ed3ad3d87a2 --- /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 ); + } +}