Make WordPress Core

Changeset 56246


Ignore:
Timestamp:
07/17/2023 02:04:00 PM (11 months ago)
Author:
joemcgill
Message:

Script Loader: Improve test coverage for wp_print_scripts().

This is a follow-up to [56092], which further improves PHPUnit test coverage and inline docs for ensuring async and defer attributes are being properly handled for scripts that are printed without being enqueued.

Props peterwilsoncc, azaozz, westonruter, joemcgill.
See #58648.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-scripts.php

    r56092 r56246  
    915915        }
    916916
    917         // If the intended strategy is 'defer', limit the initial list of eligibles.
     917        /*
     918         * If the intended strategy is 'defer', limit the initial list of eligible
     919         * strategies, since 'async' can fallback to 'defer', but not vice-versa.
     920         */
    918921        $initial = ( 'defer' === $intended ) ? array( 'defer' ) : null;
    919922
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r56092 r56246  
    29442944        $actual = get_echo( 'wp_print_scripts', array( array( 'wp-tinymce' ) ) );
    29452945
    2946         $this->assertStringNotContainsString( 'async', $actual );
     2946        $this->assertStringNotContainsString( 'async', $actual, 'TinyMCE should not have an async attribute.' );
     2947        $this->assertStringNotContainsString( 'defer', $actual, 'TinyMCE should not have a defer attribute.' );
     2948    }
     2949
     2950    /**
     2951     * Make sure scripts with a loading strategy that are printed
     2952     * without being enqueued are handled properly.
     2953     *
     2954     * @ticket 58648
     2955     *
     2956     * @dataProvider data_provider_delayed_strategies
     2957     */
     2958    public function test_printing_non_enqueued_scripts( $strategy ) {
     2959        wp_register_script( 'test-script', 'test-script.js', array(), false, array( 'strategy' => $strategy ) );
     2960
     2961        $actual = get_echo( 'wp_print_scripts', array( array( 'test-script' ) ) );
     2962
     2963        $this->assertStringContainsString( $strategy, $actual );
    29472964    }
    29482965
Note: See TracChangeset for help on using the changeset viewer.