Make WordPress Core

Changeset 59579


Ignore:
Timestamp:
01/06/2025 03:58:50 PM (20 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme.php

    r59227 r59579  
    303303        /**
    304304         * @ticket 48566
    305          */
    306         public function test_year_in_readme() {
     305         *
     306         * @dataProvider data_year_in_readme
     307         */
     308        public function test_year_in_readme( $theme ) {
    307309                // This test is designed to only run on trunk.
    308310                $this->skipOnAutomatedBranches();
    309311
    310                 foreach ( $this->default_themes as $theme ) {
    311                         $wp_theme = wp_get_theme( $theme );
    312 
    313                         $path_to_readme_txt = $wp_theme->get_theme_root() . '/' . $wp_theme->get_stylesheet() . '/readme.txt';
    314                         $this->assertFileExists( $path_to_readme_txt );
    315 
    316                         $readme    = file_get_contents( $path_to_readme_txt );
    317                         $this_year = gmdate( 'Y' );
    318 
    319                         preg_match( '#Copyright (\d+) WordPress.org#', $readme, $matches );
    320                         if ( $matches ) {
    321                                 $readme_year = trim( $matches[1] );
    322 
    323                                 $this->assertSame( $this_year, $readme_year, "Bundled themes readme.txt's year needs to be updated to $this_year." );
    324                         }
    325 
    326                         preg_match( '#Copyright 20\d\d-(\d+) WordPress.org#', $readme, $matches );
    327                         if ( $matches ) {
    328                                 $readme_year = trim( $matches[1] );
    329 
    330                                 $this->assertSame( $this_year, $readme_year, "Bundled themes readme.txt's year needs to be updated to $this_year." );
    331                         }
     312                $wp_theme = wp_get_theme( $theme );
     313
     314                $path_to_readme_txt = $wp_theme->get_theme_root() . '/' . $wp_theme->get_stylesheet() . '/readme.txt';
     315                $this->assertFileExists( $path_to_readme_txt );
     316
     317                $readme    = file_get_contents( $path_to_readme_txt );
     318                $this_year = gmdate( 'Y' );
     319
     320                preg_match( '#(Copyright|\(C\)) (20\d\d-)?(\d+) WordPress.org#i', $readme, $matches );
     321                if ( $matches ) {
     322                        $readme_year = trim( $matches[3] );
     323
     324                        $this->assertSame( $this_year, $readme_year, "$theme readme.txt's year needs to be updated to $this_year." );
    332325                }
     326        }
     327
     328        public function data_year_in_readme() {
     329                return array_map(
     330                        static function ( $theme ) {
     331                                return array( $theme );
     332                        },
     333                        $this->default_themes
     334                );
    333335        }
    334336
Note: See TracChangeset for help on using the changeset viewer.