From 375af8c6c6fe222fc4dacad6eed16f31a68061d7 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 6 Jan 2025 15:58:50 +0000 Subject: [PATCH] Tests: Improve the test for the copyright year in bundled themes' `readme.txt`. This aims to catch entries like `(C) 2024 WordPress.org` in addition to `Copyright 2024 WordPress.org`. Includes converting the test to use a data provider, so that messages could be displayed for each individual theme. Follow-up to [46719], [59569]. See #62280. git-svn-id: https://develop.svn.wordpress.org/trunk@59579 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/theme.php | 40 ++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/tests/phpunit/tests/theme.php b/tests/phpunit/tests/theme.php index 248aaa833a..c18c4d434f 100644 --- a/tests/phpunit/tests/theme.php +++ b/tests/phpunit/tests/theme.php @@ -302,36 +302,38 @@ class Tests_Theme extends WP_UnitTestCase { /** * @ticket 48566 + * + * @dataProvider data_year_in_readme */ - public function test_year_in_readme() { + public function test_year_in_readme( $theme ) { // This test is designed to only run on trunk. $this->skipOnAutomatedBranches(); - foreach ( $this->default_themes as $theme ) { - $wp_theme = wp_get_theme( $theme ); + $wp_theme = wp_get_theme( $theme ); - $path_to_readme_txt = $wp_theme->get_theme_root() . '/' . $wp_theme->get_stylesheet() . '/readme.txt'; - $this->assertFileExists( $path_to_readme_txt ); + $path_to_readme_txt = $wp_theme->get_theme_root() . '/' . $wp_theme->get_stylesheet() . '/readme.txt'; + $this->assertFileExists( $path_to_readme_txt ); - $readme = file_get_contents( $path_to_readme_txt ); - $this_year = gmdate( 'Y' ); + $readme = file_get_contents( $path_to_readme_txt ); + $this_year = gmdate( 'Y' ); - preg_match( '#Copyright (\d+) WordPress.org#', $readme, $matches ); - if ( $matches ) { - $readme_year = trim( $matches[1] ); + preg_match( '#(Copyright|\(C\)) (20\d\d-)?(\d+) WordPress.org#i', $readme, $matches ); + if ( $matches ) { + $readme_year = trim( $matches[3] ); - $this->assertSame( $this_year, $readme_year, "Bundled themes readme.txt's year needs to be updated to $this_year." ); - } - - preg_match( '#Copyright 20\d\d-(\d+) WordPress.org#', $readme, $matches ); - if ( $matches ) { - $readme_year = trim( $matches[1] ); - - $this->assertSame( $this_year, $readme_year, "Bundled themes readme.txt's year needs to be updated to $this_year." ); - } + $this->assertSame( $this_year, $readme_year, "$theme readme.txt's year needs to be updated to $this_year." ); } } + public function data_year_in_readme() { + return array_map( + static function ( $theme ) { + return array( $theme ); + }, + $this->default_themes + ); + } + /** * @ticket 20897 * @expectedDeprecated get_theme_data