Make WordPress Core


Ignore:
Timestamp:
03/26/2021 08:02:01 PM (6 years ago)
Author:
desrosj
Message:

Build/Test Tools: Backport GitHub Action and build improvements to the 5.2 branch.

This backports several build and test tool improvements to the 5.2 branch. Most notably, this includes:

  • The changes required to allow each workflow to be triggered by the workflow_dispatch event so that tests can be run on a schedule [50590].
  • The ability to run PHPUnit tests from src instead of build [50441-50443].
  • Splitting single site and multisite tests into parallel jobs [50379].
  • Split slow tests into separate, parallel jobs for PHP 5.6 [50444].
  • Better branch and path scoping for GitHub Action workflows when running on pull_request [50432,50479].
  • Several devDependency updates.

Merges [50267,50299,50379,50387,50413,50416,50432,50435-50436,50441-50444,50446,50473-50474,50476,50479,50485-50487,50545,50579,50590,50598] to the 5.2 branch.
See #50401, #51734, #51801, #51802, #52548, #52608, #52612, #52623, #52624, #52625, #52645, #52653, #52658, #52660, #52667.

Location:
branches/5.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.2

  • branches/5.2/tests/phpunit/tests/admin/includesPlugin.php

    r42343 r50606  
    55 */
    66class Tests_Admin_includesPlugin extends WP_UnitTestCase {
     7        public static function wpSetUpBeforeClass( $factory ) {
     8                self::_back_up_mu_plugins();
     9        }
     10
     11        public static function wpTearDownAfterClass() {
     12                self::_restore_mu_plugins();
     13        }
     14
    715        function test_get_plugin_data() {
    816                $data = get_plugin_data( DIR_TESTDATA . '/plugins/hello.php' );
    … …  
    111119                        'list_files_test_plugin/subdir/subfile.php',
    112120                );
    113                 $this->assertEquals( $expected, $plugin_files );
    114121
    115122                unlink( $sub_dir . '/subfile.php' );
    … …  
    117124                rmdir( $sub_dir );
    118125                rmdir( $plugin_dir );
     126
     127                $this->assertSame( $expected, $plugin_files );
    119128        }
    120129
    … …  
    123132         */
    124133        public function test_get_mu_plugins_when_mu_plugins_exists_but_is_empty() {
    125                 if ( is_dir( WPMU_PLUGIN_DIR ) ) {
    126                         $exists = true;
    127                         $this->_back_up_mu_plugins();
    128                 } else {
    129                         $exists = false;
    130                         mkdir( WPMU_PLUGIN_DIR );
    131                 }
    132 
    133                 $this->assertEquals( array(), get_mu_plugins() );
    134 
    135                 // Clean up.
    136                 if ( $exists ) {
    137                         $this->_restore_mu_plugins();
    138                 } else {
    139                         rmdir( WPMU_PLUGIN_DIR );
    140                 }
     134                mkdir( WPMU_PLUGIN_DIR );
     135
     136                $mu_plugins = get_mu_plugins();
     137
     138                rmdir( WPMU_PLUGIN_DIR );
     139
     140                $this->assertSame( array(), $mu_plugins );
    141141        }
    142142
    … …  
    145145         */
    146146        public function test_get_mu_plugins_when_mu_plugins_directory_does_not_exist() {
    147                 $exists = false;
    148                 if ( is_dir( WPMU_PLUGIN_DIR ) ) {
    149                         $exists = true;
    150                         $this->_back_up_mu_plugins();
    151                         rmdir( WPMU_PLUGIN_DIR );
    152                 }
    153 
    154                 $this->assertEquals( array(), get_mu_plugins() );
    155 
    156                 // Clean up.
    157                 if ( $exists ) {
    158                         mkdir( WPMU_PLUGIN_DIR );
    159                         $this->_restore_mu_plugins();
    160                 }
     147                $this->assertFileNotExists( WPMU_PLUGIN_DIR );
     148                $this->assertSame( array(), get_mu_plugins() );
    161149        }
    162150
    … …  
    165153         */
    166154        public function test_get_mu_plugins_should_ignore_index_php_containing_silence_is_golden() {
    167                 if ( is_dir( WPMU_PLUGIN_DIR ) ) {
    168                         $exists = true;
    169                         $this->_back_up_mu_plugins();
    170                 } else {
    171                         $exists = false;
    172                         mkdir( WPMU_PLUGIN_DIR );
    173                 }
     155                mkdir( WPMU_PLUGIN_DIR );
    174156
    175157                $this->_create_plugin( '<?php\n//Silence is golden.', 'index.php', WPMU_PLUGIN_DIR );
    176                 $this->assertEquals( array(), get_mu_plugins() );
     158
     159                $mu_plugins = get_mu_plugins();
     160
     161                unlink( WPMU_PLUGIN_DIR . '/index.php' );
     162                rmdir( WPMU_PLUGIN_DIR );
     163
     164                $this->assertSame( array(), $mu_plugins );
     165        }
     166
     167        /**
     168         * @covers ::get_mu_plugins
     169         */
     170        public function test_get_mu_plugins_should_not_ignore_index_php_containing_something_other_than_silence_is_golden() {
     171                mkdir( WPMU_PLUGIN_DIR );
     172
     173                $this->_create_plugin( '<?php\n//Silence is not golden.', 'index.php', WPMU_PLUGIN_DIR );
     174                $found = get_mu_plugins();
    177175
    178176                // Clean up.
    179177                unlink( WPMU_PLUGIN_DIR . '/index.php' );
    180                 if ( $exists ) {
    181                         $this->_restore_mu_plugins();
    182                 } else {
    183                         rmdir( WPMU_PLUGIN_DIR );
    184                 }
     178                rmdir( WPMU_PLUGIN_DIR );
     179
     180                $this->assertSame( array( 'index.php' ), array_keys( $found ) );
    185181        }
    186182
    … …  
    188184         * @covers ::get_mu_plugins
    189185         */
    190         public function test_get_mu_plugins_should_not_ignore_index_php_containing_something_other_than_silence_is_golden() {
    191                 if ( is_dir( WPMU_PLUGIN_DIR ) ) {
    192                         $exists = true;
    193                         $this->_back_up_mu_plugins();
    194                 } else {
    195                         $exists = false;
    196                         mkdir( WPMU_PLUGIN_DIR );
    197                 }
    198 
    199                 $this->_create_plugin( '<?php\n//Silence is not golden.', 'index.php', WPMU_PLUGIN_DIR );
    200                 $found = get_mu_plugins();
    201                 $this->assertEquals( array( 'index.php' ), array_keys( $found ) );
    202 
    203                 // Clean up.
    204                 unlink( WPMU_PLUGIN_DIR . '/index.php' );
    205                 if ( $exists ) {
    206                         $this->_restore_mu_plugins();
    207                 } else {
    208                         rmdir( WPMU_PLUGIN_DIR );
    209                 }
    210         }
    211 
    212         /**
    213          * @covers ::get_mu_plugins
    214          */
    215186        public function test_get_mu_plugins_should_ignore_files_without_php_extensions() {
    216                 if ( is_dir( WPMU_PLUGIN_DIR ) ) {
    217                         $exists = true;
    218                         $this->_back_up_mu_plugins();
    219                 } else {
    220                         $exists = false;
    221                         mkdir( WPMU_PLUGIN_DIR );
    222                 }
     187                mkdir( WPMU_PLUGIN_DIR );
    223188
    224189                $this->_create_plugin( '<?php\n//Test', 'foo.php', WPMU_PLUGIN_DIR );
    225190                $this->_create_plugin( '<?php\n//Test 2', 'bar.txt', WPMU_PLUGIN_DIR );
    226191                $found = get_mu_plugins();
    227                 $this->assertEquals( array( 'foo.php' ), array_keys( $found ) );
    228192
    229193                // Clean up.
    230194                unlink( WPMU_PLUGIN_DIR . '/foo.php' );
    231195                unlink( WPMU_PLUGIN_DIR . '/bar.txt' );
    232                 if ( $exists ) {
    233                         $this->_restore_mu_plugins();
    234                 } else {
    235                         rmdir( WPMU_PLUGIN_DIR );
    236                 }
     196
     197                $this->assertSame( array( 'foo.php' ), array_keys( $found ) );
    237198        }
    238199
    … …  
    393354
    394355        /**
    395          * Move existing mu-plugins to wp-content/mu-plugin/backup.
     356         * Move existing mu-plugins to wp-content/mu-plugin-backup.
    396357         *
    397358         * @since 4.2.0
    … …  
    399360         * @access private
    400361         */
    401         private function _back_up_mu_plugins() {
     362        private static function _back_up_mu_plugins() {
    402363                if ( is_dir( WPMU_PLUGIN_DIR ) ) {
    403364                        $mu_bu_dir = WP_CONTENT_DIR . '/mu-plugin-backup';
    404                         if ( ! is_dir( $mu_bu_dir ) ) {
    405                                 mkdir( $mu_bu_dir );
    406                         }
    407 
    408                         $files_to_move = array();
    409                         if ( $mu_plugins = opendir( WPMU_PLUGIN_DIR ) ) {
    410                                 while ( false !== $plugin = readdir( $mu_plugins ) ) {
    411                                         if ( 0 !== strpos( $plugin, '.' ) ) {
    412                                                 $files_to_move[] = $plugin;
    413                                         }
    414                                 }
    415                         }
    416 
    417                         @closedir( $mu_plugins );
    418 
    419                         foreach ( $files_to_move as $file_to_move ) {
    420                                 $f = rename( WPMU_PLUGIN_DIR . '/' . $file_to_move, $mu_bu_dir . '/' . $file_to_move );
    421                         }
     365                        rename( WPMU_PLUGIN_DIR, $mu_bu_dir );
    422366                }
    423367        }
    … …  
    430374         * @access private
    431375         */
    432         private function _restore_mu_plugins() {
    433                 $mu_bu_dir     = WP_CONTENT_DIR . '/mu-plugin-backup';
    434                 $files_to_move = array();
    435                 if ( is_dir( $mu_bu_dir ) && $mu_plugins = opendir( $mu_bu_dir ) ) {
    436                         while ( false !== $plugin = readdir( $mu_plugins ) ) {
    437                                 if ( 0 !== strpos( $plugin, '.' ) ) {
    438                                         $files_to_move[] = $plugin;
    439                                 }
    440                         }
    441                 }
    442 
    443                 @closedir( $mu_plugins );
    444 
    445                 foreach ( $files_to_move as $file_to_move ) {
    446                         rename( $mu_bu_dir . '/' . $file_to_move, WPMU_PLUGIN_DIR . '/' . $file_to_move );
     376        private static function _restore_mu_plugins() {
     377                $mu_bu_dir = WP_CONTENT_DIR . '/mu-plugin-backup';
     378
     379                if ( is_dir( WPMU_PLUGIN_DIR ) ) {
     380                        rmdir( WPMU_PLUGIN_DIR );
    447381                }
    448382
    449383                if ( is_dir( $mu_bu_dir ) ) {
    450                         rmdir( $mu_bu_dir );
     384                        rename( $mu_bu_dir, WPMU_PLUGIN_DIR );
    451385                }
    452386        }
Note: See TracChangeset for help on using the changeset viewer.