WordPress.org

Make WordPress Core

Changeset 50464


Ignore:
Timestamp:
03/01/2021 08:21:23 PM (7 months ago)
Author:
johnbillion
Message:

Build/Test Tools: PHPUnit test improvements:

  • Switch back to running the PHPUnit test suite against the src directory instead of build
  • Increase the reliability of backing up the mu-plugins directory during tests
  • Split the PHPUnit tests for PHP versions below 7.0 in half, allowing them to run in parallel and reduce the overall test run duration on GitHub Actions

Merges [50441-50444] to the 5.7 branch.

Fixes #51734, #51735, #52645

Location:
branches/5.7
Files:
2 deleted
17 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/5.7

  • branches/5.7/.github/workflows/phpunit-tests.yml

    r50413 r50464  
    1616
    1717env:
    18   LOCAL_DIR: build
    1918  PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: ${{ true }}
    2019  COMPOSER_INSTALL: ${{ false }}
     
    2221  PHPUNIT_SCRIPT: php
    2322  LOCAL_PHP_MEMCACHED: ${{ false }}
     23  SLOW_TESTS: 'external-http,media,restapi'
    2424
    2525jobs:
    26   # Sets up WordPress for testing or development use.
     26  # Sets up the workflow for testing.
    2727  #
    2828  # Performs the following steps:
    2929  # - Cancels all previous workflow runs for pull requests that have not completed.
    30   # - Checks out the repository.
    31   # - Logs debug information about the runner container.
    32   # - Installs NodeJS 14.
    33   # - Sets up caching for NPM.
    34   # _ Installs NPM dependencies using install-changed to hash the `package.json` file.
    35   # - Builds WordPress to run from the `build` directory.
    36   # - Creates a ZIP file of compiled WordPress.
    37   # - Uploads ZIP file as an artifact.
    38   setup-wordpress:
    39     name: Setup WordPress
     30  setup-workflow:
     31    name: Setup Workflow
    4032    runs-on: ubuntu-latest
    4133    if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }}
     
    4739        with:
    4840          access_token: ${{ github.token }}
    49 
    50       - name: Checkout repository
    51         uses: actions/checkout@v2
    52 
    53       - name: Log debug information
    54         run: |
    55           echo "$GITHUB_REF"
    56           echo "$GITHUB_EVENT_NAME"
    57           npm --version
    58           node --version
    59           curl --version
    60           git --version
    61           svn --version
    62           php --version
    63           php -i
    64           locale -a
    65 
    66       - name: Install NodeJS
    67         uses: actions/setup-node@v2
    68         with:
    69           node-version: 14
    70 
    71       - name: Cache NodeJS modules
    72         uses: actions/cache@v2
    73         env:
    74           cache-name: cache-node-modules
    75         with:
    76           # npm cache files are stored in `~/.npm` on Linux/macOS
    77           path: ~/.npm
    78           key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
    79           restore-keys: |
    80             ${{ runner.os }}-npm-
    81 
    82       - name: Install Dependencies
    83         run: npx install-changed --install-command="npm ci"
    84 
    85       - name: Build WordPress
    86         run: npm run build
    87 
    88       - name: Create ZIP artifact
    89         uses: thedoctor0/zip-release@0.4.1
    90         with:
    91           filename: built-wp-${{ github.sha }}.zip
    92           exclusions: '*.git* /*node_modules/* packagehash.txt'
    93 
    94       - name: Upload build artifact
    95         uses: actions/upload-artifact@v2
    96         with:
    97           name: built-wp-${{ github.sha }}
    98           path: built-wp-${{ github.sha }}.zip
    99           if-no-files-found: error
    10041
    10142  # Runs the PHPUnit tests for WordPress.
     
    10445  # - Set environment variables.
    10546  # - Sets up the environment variables needed for testing with memcached (if desired).
    106   # - Downloads the built WordPress artifact from the previous job.
    107   # - Unzips the artifact.
    10847  # - Installs NodeJS 14.
    10948  # - Sets up caching for NPM.
    110   # _ Installs NPM dependencies using install-changed to hash the `package.json` file.
     49  # - Installs NPM dependencies
    11150  # - Configures caching for Composer.
    112   # _ Installs Composer dependencies (if desired).
     51  # - Installs Composer dependencies (if desired).
    11352  # - Logs Docker debug information (about both the Docker installation within the runner).
    11453  # - Starts the WordPress Docker container.
     
    12564  # - todo: Configure Slack notifications for failing tests.
    12665  test-php:
    127     name: ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }}${{ matrix.memcached && ' with memcached' || '' }} on ${{ matrix.os }}
    128     needs: setup-wordpress
     66    name: ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }}${{ matrix.split_slow && ' slow tests' || '' }} ${{ matrix.memcached && ' with memcached' || '' }} on ${{ matrix.os }}
    12967    runs-on: ${{ matrix.os }}
    13068    strategy:
     
    13371        os: [ ubuntu-latest ]
    13472        memcached: [ false ]
     73        split_slow: [ false ]
    13574        multisite: [ false, true ]
    13675        include:
     76          # Additional "slow" jobs for PHP 5.6.
     77          - php: '5.6.20'
     78            os: ubuntu-latest
     79            memcached: false
     80            multisite: false
     81            split_slow: true
     82          - php: '5.6.20'
     83            os: ubuntu-latest
     84            memcached: false
     85            multisite: true
     86            split_slow: true
    13787          # Include jobs for PHP 7.4 with memcached.
    13888          - php: '7.4'
     
    161111          echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV
    162112
    163       - name: Download the built WordPress artifact
    164         uses: actions/download-artifact@v2
    165         with:
    166           name: built-wp-${{ github.sha }}
    167 
    168       - name: Unzip built artifact
    169         run: unzip built-wp-${{ github.sha }}.zip
     113      - name: Checkout repository
     114        uses: actions/checkout@v2
    170115
    171116      - name: Install NodeJS
     
    232177        if: ${{ matrix.memcached }}
    233178        run: |
    234           cp tests/phpunit/includes/object-cache.php build/wp-content/object-cache.php
     179          cp tests/phpunit/includes/object-cache.php src/wp-content/object-cache.php
    235180          docker run --name memcached --net $(basename "$PWD")_wpdevnet -d memcached
    236181
     
    257202        run: npm run env:install
    258203
     204      - name: Run slow PHPUnit tests
     205        if: ${{ matrix.split_slow }}
     206        run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --group ${{ env.SLOW_TESTS }}
     207
     208      - name: Run PHPUnit tests for single site excluding slow tests
     209        if: ${{ matrix.php < '7.0' && ! matrix.split_slow && ! matrix.multisite }}
     210        run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --exclude-group ${{ env.SLOW_TESTS }},ajax,ms-files,ms-required
     211
     212      - name: Run PHPUnit tests for Multisite excluding slow tests
     213        if: ${{ matrix.php < '7.0' && ! matrix.split_slow && matrix.multisite }}
     214        run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --exclude-group ${{ env.SLOW_TESTS }},ajax,ms-files,ms-excluded,oembed-headers
     215
    259216      - name: Run PHPUnit tests
     217        if: ${{ matrix.php >= '7.0' }}
    260218        run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c ${{ env.PHPUNIT_CONFIG }}
    261219
    262220      - name: Run AJAX tests
     221        if: ${{ ! matrix.split_slow }}
    263222        run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --group ajax
    264223
    265224      - name: Run ms-files tests as a multisite install
    266         if: ${{ matrix.multisite }}
     225        if: ${{ matrix.multisite && ! matrix.split_slow }}
    267226        run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c tests/phpunit/multisite.xml --group ms-files
    268227
    269228      - name: Run external HTTP tests
    270         if: ${{ ! matrix.multisite }}
     229        if: ${{ ! matrix.multisite && ! matrix.split_slow }}
    271230        run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c phpunit.xml.dist --group external-http
    272231
    273232      # __fakegroup__ is excluded to force PHPUnit to ignore the <exclude> settings in phpunit.xml.dist.
    274233      - name: Run (xDebug) tests
     234        if: ${{ ! matrix.split_slow }}
    275235        run: LOCAL_PHP_XDEBUG=true npm run test:${{ env.PHPUNIT_SCRIPT }} -- -v --group xdebug --exclude-group __fakegroup__
    276236
     
    281241          repository: 'WordPress/phpunit-test-runner'
    282242          path: 'test-runner'
    283 
    284       - name: Set up the Git repository
    285         if: ${{ github.repository == 'WordPress/wordpress-develop' && github.ref == 'refs/heads/master' && matrix.report }}
    286         run: |
    287           git init
    288           git remote add origin https://github.com/WordPress/wordpress-develop.git
    289           git fetch
    290           git reset origin/master
    291243
    292244      - name: Submit test results to the WordPress.org host test results
  • branches/5.7/.github/workflows/test-coverage.yml

    r50387 r50464  
    77
    88env:
    9   LOCAL_DIR: build
    109  PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: ${{ true }}
    1110  COMPOSER_INSTALL: ${{ false }}
     
    2726  # - Sets up caching for NPM.
    2827  # _ Installs NPM dependencies using install-changed to hash the `package.json` file.
    29   # - Builds WordPress to run from the `build` directory.
    3028  # - Logs Docker debug information (about the Docker installation within the runner).
    3129  # - Starts the WordPress Docker container.
     
    8886        run: npx install-changed --install-command="npm ci"
    8987
    90       - name: Build WordPress
    91         run: npm run build
    92 
    9388      - name: Docker debug information
    9489        run: |
  • branches/5.7/Gruntfile.js

    r50457 r50464  
    88    var path = require('path'),
    99        fs = require( 'fs' ),
     10        glob = require( 'glob' ),
     11        assert = require( 'assert' ).strict,
    1012        spawn = require( 'child_process' ).spawnSync,
    1113        SOURCE_DIR = 'src/',
     
    14341436    ] );
    14351437
     1438    /**
     1439     * Build verification tasks.
     1440     */
     1441    grunt.registerTask( 'verify:build', [
     1442        'verify:wp-embed',
     1443        'verify:old-files',
     1444        'verify:source-maps',
     1445    ] );
     1446
     1447    /**
     1448     * Build assertions for wp-embed.min.js.
     1449     *
     1450     * @ticket 34698
     1451     */
     1452    grunt.registerTask( 'verify:wp-embed', function() {
     1453        const file = `${ BUILD_DIR }/wp-includes/js/wp-embed.min.js`;
     1454
     1455        assert(
     1456            fs.existsSync( file ),
     1457            'The build/wp-includes/js/wp-embed.min.js file does not exist.'
     1458        );
     1459
     1460        const contents = fs.readFileSync( file, {
     1461            encoding: 'utf8',
     1462        } );
     1463
     1464        assert(
     1465            contents.length > 0,
     1466            'The build/wp-includes/js/wp-embed.min.js file must not be empty.'
     1467        );
     1468        assert(
     1469            false === contents.includes( '&' ),
     1470            'The build/wp-includes/js/wp-embed.min.js file must not contain ampersands.'
     1471        );
     1472    } );
     1473
     1474    /**
     1475     * Build assertions to ensure no project files are inside `$_old_files` in the build directory.
     1476     *
     1477     * @ticket 36083
     1478     */
     1479    grunt.registerTask( 'verify:old-files', function() {
     1480        const file = `${ BUILD_DIR }wp-admin/includes/update-core.php`;
     1481
     1482        assert(
     1483            fs.existsSync( file ),
     1484            'The build/wp-admin/includes/update-core.php file does not exist.'
     1485        );
     1486
     1487        const contents = fs.readFileSync( file, {
     1488            encoding: 'utf8',
     1489        } );
     1490
     1491        assert(
     1492            contents.length > 0,
     1493            'The build/wp-admin/includes/update-core.php file must not be empty.'
     1494        );
     1495
     1496        const match = contents.match( /\$_old_files = array\(([^\)]+)\);/ );
     1497
     1498        assert(
     1499            match.length > 0,
     1500            'The build/wp-admin/includes/update-core.php file does not include an `$_old_files` array.'
     1501        );
     1502
     1503        const files = match[1].split( '\n\t' ).filter( function( file ) {
     1504            // Filter out empty lines
     1505            if ( '' === file ) {
     1506                return false;
     1507            }
     1508
     1509            // Filter out commented out lines
     1510            if ( 0 === file.indexOf( '/' ) ) {
     1511                return false;
     1512            }
     1513
     1514            return true;
     1515        } ).map( function( file ) {
     1516            // Strip leading and trailing single quotes and commas
     1517            return file.replace( /^\'|\',$/g, '' );
     1518        } );
     1519
     1520        files.forEach(function( file ){
     1521            const search = `${ BUILD_DIR }${ file }`;
     1522            assert(
     1523                false === fs.existsSync( search ),
     1524                `${ search } should not be present in the $_old_files array.`
     1525            );
     1526        });
     1527    } );
     1528
     1529    /**
     1530     * Build assertions for the lack of source maps in JavaScript files.
     1531     *
     1532     * @ticket 24994
     1533     * @ticket 46218
     1534     */
     1535    grunt.registerTask( 'verify:source-maps', function() {
     1536        const path = `${ BUILD_DIR }**/*.js`;
     1537        const files = glob.sync( path );
     1538
     1539        assert(
     1540            files.length > 0,
     1541            'No JavaScript files found in the build directory.'
     1542        );
     1543
     1544        files.forEach( function( file ) {
     1545            const contents = fs.readFileSync( file, {
     1546                encoding: 'utf8',
     1547            } );
     1548            // `data:` URLs are allowed:
     1549            const match = contents.match( /sourceMappingURL=((?!data:).)/ );
     1550
     1551            assert(
     1552                match === null,
     1553                `The ${ file } file must not contain a sourceMappingURL.`
     1554            );
     1555        } );
     1556    } );
     1557
    14361558    grunt.registerTask( 'build', function() {
    14371559        if ( grunt.option( 'dev' ) ) {
     
    14471569                'includes:emoji',
    14481570                'includes:embed',
    1449                 'replace:emojiBannerText'
     1571                'replace:emojiBannerText',
     1572                'verify:build'
    14501573            ] );
    14511574        }
  • branches/5.7/README.md

    r49957 r50464  
    4646
    4747```
    48 npm run watch
     48npm run dev
    4949```
    5050
  • branches/5.7/tests/phpunit/includes/abstract-testcase.php

    r49916 r50464  
    12941294        );
    12951295    }
     1296
     1297    /**
     1298     * Touches the given file and its directory if it doesn't already exist.
     1299     *
     1300     * This can be used to ensure a file that is implictly relied on in a test exists
     1301     * without it having to be built.
     1302     *
     1303     * @param string $file The file name.
     1304     */
     1305    public static function touch( $file ) {
     1306        if ( file_exists( $file ) ) {
     1307            return;
     1308        }
     1309
     1310        $dir = dirname( $file );
     1311
     1312        if ( ! file_exists( $dir ) ) {
     1313            mkdir( $dir, 0777, true );
     1314        }
     1315
     1316        touch( $file );
     1317    }
    12961318}
  • branches/5.7/tests/phpunit/tests/admin/includesPlugin.php

    r49566 r50464  
    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' );
     
    370378            'list_files_test_plugin/subdir/subfile.php',
    371379        );
    372         $this->assertSame( $expected, $plugin_files );
    373380
    374381        unlink( $sub_dir . '/subfile.php' );
     
    376383        rmdir( $sub_dir );
    377384        rmdir( $plugin_dir );
     385
     386        $this->assertSame( $expected, $plugin_files );
    378387    }
    379388
     
    382391     */
    383392    public function test_get_mu_plugins_when_mu_plugins_exists_but_is_empty() {
    384         if ( is_dir( WPMU_PLUGIN_DIR ) ) {
    385             $exists = true;
    386             $this->_back_up_mu_plugins();
    387         } else {
    388             $exists = false;
    389             mkdir( WPMU_PLUGIN_DIR );
    390         }
    391 
     393        mkdir( WPMU_PLUGIN_DIR );
     394
     395        $mu_plugins = get_mu_plugins();
     396
     397        rmdir( WPMU_PLUGIN_DIR );
     398
     399        $this->assertSame( array(), $mu_plugins );
     400    }
     401
     402    /**
     403     * @covers ::get_mu_plugins
     404     */
     405    public function test_get_mu_plugins_when_mu_plugins_directory_does_not_exist() {
     406        $this->assertFileNotExists( WPMU_PLUGIN_DIR );
    392407        $this->assertSame( array(), get_mu_plugins() );
    393 
    394         // Clean up.
    395         if ( $exists ) {
    396             $this->_restore_mu_plugins();
    397         } else {
    398             rmdir( WPMU_PLUGIN_DIR );
    399         }
    400408    }
    401409
     
    403411     * @covers ::get_mu_plugins
    404412     */
    405     public function test_get_mu_plugins_when_mu_plugins_directory_does_not_exist() {
    406         $exists = false;
    407         if ( is_dir( WPMU_PLUGIN_DIR ) ) {
    408             $exists = true;
    409             $this->_back_up_mu_plugins();
    410             rmdir( WPMU_PLUGIN_DIR );
    411         }
    412 
    413         $this->assertSame( array(), get_mu_plugins() );
    414 
    415         // Clean up.
    416         if ( $exists ) {
    417             mkdir( WPMU_PLUGIN_DIR );
    418             $this->_restore_mu_plugins();
    419         }
     413    public function test_get_mu_plugins_should_ignore_index_php_containing_silence_is_golden() {
     414        mkdir( WPMU_PLUGIN_DIR );
     415
     416        $this->_create_plugin( '<?php\n//Silence is golden.', 'index.php', WPMU_PLUGIN_DIR );
     417
     418        $mu_plugins = get_mu_plugins();
     419
     420        unlink( WPMU_PLUGIN_DIR . '/index.php' );
     421        rmdir( WPMU_PLUGIN_DIR );
     422
     423        $this->assertSame( array(), $mu_plugins );
    420424    }
    421425
     
    423427     * @covers ::get_mu_plugins
    424428     */
    425     public function test_get_mu_plugins_should_ignore_index_php_containing_silence_is_golden() {
    426         if ( is_dir( WPMU_PLUGIN_DIR ) ) {
    427             $exists = true;
    428             $this->_back_up_mu_plugins();
    429         } else {
    430             $exists = false;
    431             mkdir( WPMU_PLUGIN_DIR );
    432         }
    433 
    434         $this->_create_plugin( '<?php\n//Silence is golden.', 'index.php', WPMU_PLUGIN_DIR );
    435         $this->assertSame( array(), get_mu_plugins() );
     429    public function test_get_mu_plugins_should_not_ignore_index_php_containing_something_other_than_silence_is_golden() {
     430        mkdir( WPMU_PLUGIN_DIR );
     431
     432        $this->_create_plugin( '<?php\n//Silence is not golden.', 'index.php', WPMU_PLUGIN_DIR );
     433        $found = get_mu_plugins();
    436434
    437435        // Clean up.
    438436        unlink( WPMU_PLUGIN_DIR . '/index.php' );
    439         if ( $exists ) {
    440             $this->_restore_mu_plugins();
    441         } else {
    442             rmdir( WPMU_PLUGIN_DIR );
    443         }
     437        rmdir( WPMU_PLUGIN_DIR );
     438
     439        $this->assertSame( array( 'index.php' ), array_keys( $found ) );
    444440    }
    445441
     
    447443     * @covers ::get_mu_plugins
    448444     */
    449     public function test_get_mu_plugins_should_not_ignore_index_php_containing_something_other_than_silence_is_golden() {
    450         if ( is_dir( WPMU_PLUGIN_DIR ) ) {
    451             $exists = true;
    452             $this->_back_up_mu_plugins();
    453         } else {
    454             $exists = false;
    455             mkdir( WPMU_PLUGIN_DIR );
    456         }
    457 
    458         $this->_create_plugin( '<?php\n//Silence is not golden.', 'index.php', WPMU_PLUGIN_DIR );
    459         $found = get_mu_plugins();
    460         $this->assertSame( array( 'index.php' ), array_keys( $found ) );
    461 
    462         // Clean up.
    463         unlink( WPMU_PLUGIN_DIR . '/index.php' );
    464         if ( $exists ) {
    465             $this->_restore_mu_plugins();
    466         } else {
    467             rmdir( WPMU_PLUGIN_DIR );
    468         }
    469     }
    470 
    471     /**
    472      * @covers ::get_mu_plugins
    473      */
    474445    public function test_get_mu_plugins_should_ignore_files_without_php_extensions() {
    475         if ( is_dir( WPMU_PLUGIN_DIR ) ) {
    476             $exists = true;
    477             $this->_back_up_mu_plugins();
    478         } else {
    479             $exists = false;
    480             mkdir( WPMU_PLUGIN_DIR );
    481         }
     446        mkdir( WPMU_PLUGIN_DIR );
    482447
    483448        $this->_create_plugin( '<?php\n//Test', 'foo.php', WPMU_PLUGIN_DIR );
    484449        $this->_create_plugin( '<?php\n//Test 2', 'bar.txt', WPMU_PLUGIN_DIR );
    485450        $found = get_mu_plugins();
    486         $this->assertSame( array( 'foo.php' ), array_keys( $found ) );
    487451
    488452        // Clean up.
    489453        unlink( WPMU_PLUGIN_DIR . '/foo.php' );
    490454        unlink( WPMU_PLUGIN_DIR . '/bar.txt' );
    491         if ( $exists ) {
    492             $this->_restore_mu_plugins();
    493         } else {
    494             rmdir( WPMU_PLUGIN_DIR );
    495         }
     455
     456        $this->assertSame( array( 'foo.php' ), array_keys( $found ) );
    496457    }
    497458
     
    652613
    653614    /**
    654      * Move existing mu-plugins to wp-content/mu-plugin/backup.
     615     * Move existing mu-plugins to wp-content/mu-plugin-backup.
    655616     *
    656617     * @since 4.2.0
     
    658619     * @access private
    659620     */
    660     private function _back_up_mu_plugins() {
     621    private static function _back_up_mu_plugins() {
    661622        if ( is_dir( WPMU_PLUGIN_DIR ) ) {
    662623            $mu_bu_dir = WP_CONTENT_DIR . '/mu-plugin-backup';
    663             if ( ! is_dir( $mu_bu_dir ) ) {
    664                 mkdir( $mu_bu_dir );
    665             }
    666 
    667             $files_to_move = array();
    668             $mu_plugins    = opendir( WPMU_PLUGIN_DIR );
    669             if ( $mu_plugins ) {
    670                 while ( false !== $plugin = readdir( $mu_plugins ) ) {
    671                     if ( 0 !== strpos( $plugin, '.' ) ) {
    672                         $files_to_move[] = $plugin;
    673                     }
    674                 }
    675             }
    676 
    677             closedir( $mu_plugins );
    678 
    679             foreach ( $files_to_move as $file_to_move ) {
    680                 $f = rename( WPMU_PLUGIN_DIR . '/' . $file_to_move, $mu_bu_dir . '/' . $file_to_move );
    681             }
     624            rename( WPMU_PLUGIN_DIR, $mu_bu_dir );
    682625        }
    683626    }
     
    690633     * @access private
    691634     */
    692     private function _restore_mu_plugins() {
    693         $mu_bu_dir     = WP_CONTENT_DIR . '/mu-plugin-backup';
    694         $files_to_move = array();
    695         $mu_plugins    = @opendir( $mu_bu_dir );
    696         if ( $mu_plugins ) {
    697             while ( false !== $plugin = readdir( $mu_plugins ) ) {
    698                 if ( 0 !== strpos( $plugin, '.' ) ) {
    699                     $files_to_move[] = $plugin;
    700                 }
    701             }
    702         }
    703 
    704         closedir( $mu_plugins );
    705 
    706         foreach ( $files_to_move as $file_to_move ) {
    707             rename( $mu_bu_dir . '/' . $file_to_move, WPMU_PLUGIN_DIR . '/' . $file_to_move );
     635    private static function _restore_mu_plugins() {
     636        $mu_bu_dir = WP_CONTENT_DIR . '/mu-plugin-backup';
     637
     638        if ( is_dir( WPMU_PLUGIN_DIR ) ) {
     639            rmdir( WPMU_PLUGIN_DIR );
    708640        }
    709641
    710642        if ( is_dir( $mu_bu_dir ) ) {
    711             rmdir( $mu_bu_dir );
     643            rename( $mu_bu_dir, WPMU_PLUGIN_DIR );
    712644        }
    713645    }
  • branches/5.7/tests/phpunit/tests/dependencies/jquery.php

    r50287 r50464  
    3838            $this->assertSame( $jquery_scripts[ $dep ], $o->src );
    3939        }
    40     }
    41 
    42     function test_presence_of_jquery_no_conflict() {
    43         $contents   = trim( file_get_contents( ABSPATH . WPINC . '/js/jquery/jquery.js' ) );
    44         $noconflict = 'jQuery.noConflict();';
    45         $end        = substr( $contents, - strlen( $noconflict ) );
    46         $this->assertSame( $noconflict, $end );
    4740    }
    4841
  • branches/5.7/tests/phpunit/tests/dependencies/scripts.php

    r50408 r50464  
    729729        $expected .= "<script type='text/javascript' src='/wp-includes/js/dist/vendor/wp-polyfill{$suffix}.js' id='wp-polyfill-js'></script>\n";
    730730        $expected .= "<script type='text/javascript' id='wp-polyfill-js-after'>\n";
    731         $expected .= "( 'fetch' in window ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-fetch{$suffix}.js\"></scr' + 'ipt>' );( document.contains ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-node-contains{$suffix}.js\"></scr' + 'ipt>' );( window.DOMRect ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-dom-rect{$suffix}.js\"></scr' + 'ipt>' );( window.URL && window.URL.prototype && window.URLSearchParams ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-url{$suffix}.js\"></scr' + 'ipt>' );( window.FormData && window.FormData.prototype.keys ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-formdata{$suffix}.js\"></scr' + 'ipt>' );( Element.prototype.matches && Element.prototype.closest ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-element-closest{$suffix}.js\"></scr' + 'ipt>' );( 'objectFit' in document.documentElement.style ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-object-fit.min.js\"></scr' + 'ipt>' );\n";
     731        $expected .= "( 'fetch' in window ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-fetch{$suffix}.js\"></scr' + 'ipt>' );( document.contains ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-node-contains{$suffix}.js\"></scr' + 'ipt>' );( window.DOMRect ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-dom-rect{$suffix}.js\"></scr' + 'ipt>' );( window.URL && window.URL.prototype && window.URLSearchParams ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-url{$suffix}.js\"></scr' + 'ipt>' );( window.FormData && window.FormData.prototype.keys ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-formdata{$suffix}.js\"></scr' + 'ipt>' );( Element.prototype.matches && Element.prototype.closest ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-element-closest{$suffix}.js\"></scr' + 'ipt>' );( 'objectFit' in document.documentElement.style ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-object-fit{$suffix}.js\"></scr' + 'ipt>' );\n";
    732732        $expected .= "</script>\n";
    733733        $expected .= "<script type='text/javascript' src='/wp-includes/js/dist/dom-ready{$suffix}.js' id='wp-dom-ready-js'></script>\n";
     
    14181418    }
    14191419
    1420     function test_no_source_mapping() {
    1421         $all_files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( dirname( ABSPATH ) . '/build/' ) );
    1422         $js_files  = new RegexIterator( $all_files, '/\.js$/' );
    1423         foreach ( $js_files as $js_file ) {
    1424             $contents = trim( file_get_contents( $js_file ) );
    1425 
    1426             // We allow data: URLs.
    1427             $found = preg_match( '/sourceMappingURL=((?!data:).)/', $contents );
    1428             $this->assertSame( $found, 0, "sourceMappingURL found in $js_file" );
    1429         }
    1430     }
    1431 
    14321420    /**
    14331421     * @ticket 52534
  • branches/5.7/tests/phpunit/tests/formatting/Emoji.php

    r49239 r50464  
    1414     */
    1515    public function test_unfiltered_emoji_cdns() {
     16        // `_print_emoji_detection_script()` assumes `wp-includes/js/wp-emoji-loader.js` is present:
     17        self::touch( ABSPATH . WPINC . '/js/wp-emoji-loader.js' );
    1618        $output = get_echo( '_print_emoji_detection_script' );
    1719
     
    3234        add_filter( 'emoji_svg_url', array( $this, '_filtered_emoji_svn_cdn' ) );
    3335
     36        // `_print_emoji_detection_script()` assumes `wp-includes/js/wp-emoji-loader.js` is present:
     37        self::touch( ABSPATH . WPINC . '/js/wp-emoji-loader.js' );
    3438        $output = get_echo( '_print_emoji_detection_script' );
    3539
     
    5357        add_filter( 'emoji_url', array( $this, '_filtered_emoji_png_cdn' ) );
    5458
     59        // `_print_emoji_detection_script()` assumes `wp-includes/js/wp-emoji-loader.js` is present:
     60        self::touch( ABSPATH . WPINC . '/js/wp-emoji-loader.js' );
    5561        $output = get_echo( '_print_emoji_detection_script' );
    5662
  • branches/5.7/tests/phpunit/tests/oembed/controller.php

    r49603 r50464  
    3535            )
    3636        );
     37
     38        // `get_post_embed_html()` assumes `wp-includes/js/wp-embed.js` is present:
     39        self::touch( ABSPATH . WPINC . '/js/wp-embed.js' );
    3740    }
    3841
  • branches/5.7/tests/phpunit/tests/oembed/getResponseData.php

    r50401 r50464  
    66 */
    77class Tests_oEmbed_Response_Data extends WP_UnitTestCase {
     8    public function setUp() {
     9        parent::setUp();
     10
     11        // `get_post_embed_html()` assumes `wp-includes/js/wp-embed.js` is present:
     12        self::touch( ABSPATH . WPINC . '/js/wp-embed.js' );
     13    }
     14
    815    function test_get_oembed_response_data_non_existent_post() {
    916        $this->assertFalse( get_oembed_response_data( 0, 100 ) );
  • branches/5.7/tests/phpunit/tests/oembed/template.php

    r48937 r50464  
    2323
    2424        $this->assertQueryTrue( 'is_single', 'is_singular', 'is_embed' );
     25
     26        // `print_embed_scripts()` assumes `wp-includes/js/wp-embed-template.js` is present:
     27        self::touch( ABSPATH . WPINC . '/js/wp-embed-template.js' );
    2528
    2629        ob_start();
     
    291294
    292295    /**
     296     * Confirms that no ampersands exist in src/wp-includes/js/wp-embed.js.
     297     *
     298     * See also the `verify:wp-embed` Grunt task for verifying the built file.
     299     *
    293300     * @ticket 34698
    294301     */
     
    296303        $this->assertNotContains( '&', file_get_contents( ABSPATH . WPINC . '/js/wp-embed.js' ) );
    297304    }
    298 
    299     /**
    300      * @ticket 34698
    301      *
    302      * @depends test_js_no_ampersands
    303      *
    304      * The previous test confirms that no ampersands exist in src/wp-includes/js/wp-embed.js.
    305      * However, we must also confirm that UglifyJS does not add ampersands during its
    306      * optimizations (which we tweak to avoid, but indirectly -- understandably, there's
    307      * no "don't add ampersands to my JavaScript file" option).
    308      *
    309      * So this test checks for ampersands in build/wp-includes/js/wp-embed.min.js.
    310      * In many cases, this file will not exist; in those cases, we simply skip the test.
    311      *
    312      * So when would it be run? We have Travis CI run `npm run test` which then runs, in order,
    313      * `qunit:compiled` (which runs the build) and then `phpunit`. Thus, this test will at least be
    314      * run during continuous integration.
    315      *
    316      * However, we need to verify that `qunit:compiled` runs before `phpunit`. So this test also
    317      * does a cheap check for a registered Grunt task called `test` that contains both
    318      * `qunit:compiled` and `phpunit`, in that order.
    319      *
    320      * One final failsafe: The Gruntfile.js assertion takes place before checking for the existence
    321      * of wp-embed.min.js. If the Grunt tasks are significantly refactored later, it could indicate
    322      * that wp-embed.min.js doesn't exist anymore. We wouldn't want the test to silently become one
    323      * that is always skipped, and thus useless.
    324      */
    325     function test_js_no_ampersands_in_compiled() {
    326         $gruntfile = file_get_contents( dirname( ABSPATH ) . '/Gruntfile.js' );
    327 
    328         // Confirm this file *should* exist, otherwise this test will always be skipped.
    329         $test = '/grunt.registerTask\(\s*\'test\',.*\'qunit:compiled\'.*\'phpunit\'/';
    330         $this->assertTrue( (bool) preg_match( $test, $gruntfile ) );
    331 
    332         $file = dirname( ABSPATH ) . '/build/' . WPINC . '/js/wp-embed.min.js';
    333         if ( ! file_exists( $file ) ) {
    334             return;
    335         }
    336         $this->assertNotContains( '&', file_get_contents( $file ) );
    337     }
    338 
    339305}
  • branches/5.7/tests/phpunit/tests/oembed/wpOembed.php

    r48937 r50464  
    1919
    2020        $this->pre_oembed_result_filtered = false;
     21
     22        // `get_post_embed_html()` assumes `wp-includes/js/wp-embed.js` is present:
     23        self::touch( ABSPATH . WPINC . '/js/wp-embed.js' );
    2124    }
    2225
  • branches/5.7/tests/phpunit/tests/shortcode.php

    r49117 r50464  
    747747    function test_php_and_js_shortcode_attribute_regexes_match() {
    748748
    749         $file    = file_get_contents( ABSPATH . WPINC . '/js/shortcode.js' );
     749        $file    = file_get_contents( ABSPATH . 'js/_enqueues/wp/shortcode.js' );
    750750        $matched = preg_match( '|\s+pattern = (\/.+\/)g;|', $file, $matches );
    751751        $php     = get_shortcode_atts_regex();
  • branches/5.7/tests/qunit/index.html

    r50137 r50464  
    153153        <script src="wp-includes/js/shortcode.js"></script>
    154154        <script src="wp-includes/js/api-request.js"></script>
     155        <script src="wp-includes/js/jquery.js"></script>
    155156        <script src="wp-includes/js/wp-api.js"></script>
    156157        <script src="wp-admin/js/customize-controls.js"></script>
  • branches/5.7/wp-tests-config-sample.php

    r47201 r50464  
    22
    33/* Path to the WordPress codebase you'd like to test. Add a forward slash in the end. */
    4 if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) {
    5     define( 'ABSPATH', dirname( __FILE__ ) . '/build/' );
    6 } else {
    7     define( 'ABSPATH', dirname( __FILE__ ) . '/src/' );
    8 }
     4define( 'ABSPATH', dirname( __FILE__ ) . '/src/' );
    95
    106/*
Note: See TracChangeset for help on using the changeset viewer.