From d980f190f2a5827884b2bf60aff08c588dd67f72 Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Wed, 25 Nov 2026 15:13:38 +0530 Subject: [PATCH 1/2] Tests: Cover `get_the_generator()` type inference from the current filter --- .../phpunit/tests/general/getTheGenerator.php | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tests/phpunit/tests/general/getTheGenerator.php b/tests/phpunit/tests/general/getTheGenerator.php index 62100e9d1b2b7..a78c29e9b5dbc 100644 --- a/tests/phpunit/tests/general/getTheGenerator.php +++ b/tests/phpunit/tests/general/getTheGenerator.php @@ -89,6 +89,84 @@ public function test_get_the_generator_returns_null_when_type_empty() { $this->assertNull( get_the_generator( '' ) ); } + /** + * Tests that an empty $type is inferred from the current filter. + * + * @ticket 66757 + * + * @dataProvider data_generator_type_from_current_filter + * + * @param string $filter Current filter name. + * @param string $type Inferred generator type. + * @param string $expected Expected markup template with placeholder for version. + */ + public function test_get_the_generator_infers_type_from_current_filter( $filter, $type, $expected ) { + global $wp_current_filter; + + $original_filter = $wp_current_filter; + $wp_current_filter = array( $filter ); + + try { + $version = ( 'atom' === $type || 'rss2' === $type || 'rdf' === $type ) + ? get_bloginfo_rss( 'version' ) + : get_bloginfo( 'version' ); + + $this->assertSame( sprintf( $expected, $version ), get_the_generator() ); + } finally { + $wp_current_filter = $original_filter; + } + } + + /** + * Data provider for test_get_the_generator_infers_type_from_current_filter(). + * + * @return array[] + */ + public static function data_generator_type_from_current_filter() { + return array( + 'rss2_head' => array( + 'rss2_head', + 'rss2', + 'https://wordpress.org/?v=%s', + ), + 'commentsrss2_head' => array( + 'commentsrss2_head', + 'rss2', + 'https://wordpress.org/?v=%s', + ), + 'rss_head' => array( + 'rss_head', + 'comment', + '', + ), + 'opml_head' => array( + 'opml_head', + 'comment', + '', + ), + 'rdf_header' => array( + 'rdf_header', + 'rdf', + '', + ), + 'atom_head' => array( + 'atom_head', + 'atom', + 'WordPress', + ), + 'comments_atom_head' => array( + 'comments_atom_head', + 'atom', + 'WordPress', + ), + 'app_head' => array( + 'app_head', + 'atom', + 'WordPress', + ), + ); + } + /** * Tests that get_the_generator_$type filter modifies the generator markup. * From da2237b373bfb7dc6425419b649ac5abff4b7e83 Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Thu, 26 Nov 2026 10:48:51 +0530 Subject: [PATCH 2/2] Refactor test_get_the_generator_infers_type_from_current_filter --- .../phpunit/tests/general/getTheGenerator.php | 68 ++++--------------- 1 file changed, 13 insertions(+), 55 deletions(-) diff --git a/tests/phpunit/tests/general/getTheGenerator.php b/tests/phpunit/tests/general/getTheGenerator.php index a78c29e9b5dbc..f9d95b790be96 100644 --- a/tests/phpunit/tests/general/getTheGenerator.php +++ b/tests/phpunit/tests/general/getTheGenerator.php @@ -92,29 +92,19 @@ public function test_get_the_generator_returns_null_when_type_empty() { /** * Tests that an empty $type is inferred from the current filter. * - * @ticket 66757 + * @ticket 66832 * * @dataProvider data_generator_type_from_current_filter * - * @param string $filter Current filter name. - * @param string $type Inferred generator type. - * @param string $expected Expected markup template with placeholder for version. + * @param string $filter Current filter name. + * @param string $type Expected inferred generator type. */ - public function test_get_the_generator_infers_type_from_current_filter( $filter, $type, $expected ) { + public function test_get_the_generator_infers_type_from_current_filter( $filter, $type ) { global $wp_current_filter; - $original_filter = $wp_current_filter; $wp_current_filter = array( $filter ); - try { - $version = ( 'atom' === $type || 'rss2' === $type || 'rdf' === $type ) - ? get_bloginfo_rss( 'version' ) - : get_bloginfo( 'version' ); - - $this->assertSame( sprintf( $expected, $version ), get_the_generator() ); - } finally { - $wp_current_filter = $original_filter; - } + $this->assertSame( get_the_generator( $type ), get_the_generator() ); } /** @@ -124,46 +114,14 @@ public function test_get_the_generator_infers_type_from_current_filter( $filter, */ public static function data_generator_type_from_current_filter() { return array( - 'rss2_head' => array( - 'rss2_head', - 'rss2', - 'https://wordpress.org/?v=%s', - ), - 'commentsrss2_head' => array( - 'commentsrss2_head', - 'rss2', - 'https://wordpress.org/?v=%s', - ), - 'rss_head' => array( - 'rss_head', - 'comment', - '', - ), - 'opml_head' => array( - 'opml_head', - 'comment', - '', - ), - 'rdf_header' => array( - 'rdf_header', - 'rdf', - '', - ), - 'atom_head' => array( - 'atom_head', - 'atom', - 'WordPress', - ), - 'comments_atom_head' => array( - 'comments_atom_head', - 'atom', - 'WordPress', - ), - 'app_head' => array( - 'app_head', - 'atom', - 'WordPress', - ), + 'rss2_head' => array( 'rss2_head', 'rss2' ), + 'commentsrss2_head' => array( 'commentsrss2_head', 'rss2' ), + 'rss_head' => array( 'rss_head', 'comment' ), + 'opml_head' => array( 'opml_head', 'comment' ), + 'rdf_header' => array( 'rdf_header', 'rdf' ), + 'atom_head' => array( 'atom_head', 'atom' ), + 'comments_atom_head' => array( 'comments_atom_head', 'atom' ), + 'app_head' => array( 'app_head', 'atom' ), ); }