Make WordPress Core

Changeset 52386


Ignore:
Timestamp:
12/18/2021 09:08:02 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Move the tests for theme features that block themes should support by default to a more appropriate place.

As these tests are intended for the _add_default_theme_supports() function rather than WP_Theme class methods, the tests/theme.php file is a more logical place for them than tests/theme/wpTheme.php.

Follow-up to [52369], [52383].

See #54597.

Location:
trunk/tests/phpunit/tests
Files:
2 edited

Legend:

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

    r52093 r52386  
    701701        );
    702702    }
     703
     704
     705    /**
     706     * Tests that block themes support a feature by default.
     707     *
     708     * @ticket 54597
     709     * @dataProvider data_block_theme_has_default_support
     710     *
     711     * @covers ::_add_default_theme_supports
     712     *
     713     * @param array $support {
     714     *     The feature to check.
     715     *
     716     *     @type string $feature     The feature to check.
     717     *     @type string $sub_feature Optional. The sub-feature to check.
     718     * }
     719     */
     720    public function test_block_theme_has_default_support( $support ) {
     721        $this->helper_requires_block_theme();
     722
     723        $support_data     = array_values( $support );
     724        $support_data_str = implode( ': ', $support_data );
     725
     726        // Remove existing support.
     727        if ( current_theme_supports( ...$support_data ) ) {
     728            remove_theme_support( ...$support_data );
     729        }
     730
     731        $this->assertFalse(
     732            current_theme_supports( ...$support_data ),
     733            "Could not remove support for $support_data_str."
     734        );
     735
     736        do_action( 'setup_theme' );
     737
     738        $this->assertTrue(
     739            current_theme_supports( ...$support_data ),
     740            "Does not have default support for $support_data_str."
     741        );
     742    }
     743
     744    /**
     745     * Data provider.
     746     *
     747     * @return array
     748     */
     749    public function data_block_theme_has_default_support() {
     750        return array(
     751            'post-thumbnails'      => array(
     752                'support' => array(
     753                    'feature' => 'post-thumbnails',
     754                ),
     755            ),
     756            'responsive-embeds'    => array(
     757                'support' => array(
     758                    'feature' => 'responsive-embeds',
     759                ),
     760            ),
     761            'editor-styles'        => array(
     762                'support' => array(
     763                    'feature' => 'editor-styles',
     764                ),
     765            ),
     766            'html5: style'         => array(
     767                'support' => array(
     768                    'feature'     => 'html5',
     769                    'sub_feature' => 'style',
     770                ),
     771            ),
     772            'html5: script'        => array(
     773                'support' => array(
     774                    'feature'     => 'html5',
     775                    'sub_feature' => 'script',
     776                ),
     777            ),
     778            'automatic-feed-links' => array(
     779                'support' => array(
     780                    'feature' => 'automatic-feed-links',
     781                ),
     782            ),
     783        );
     784    }
     785
     786    /**
     787     * Tests that block themes load separate core block assets by default.
     788     *
     789     * @ticket 54597
     790     *
     791     * @covers ::_add_default_theme_supports
     792     * @covers ::wp_should_load_separate_core_block_assets
     793     */
     794    public function test_block_theme_should_load_separate_core_block_assets_by_default() {
     795        $this->helper_requires_block_theme();
     796
     797        add_filter( 'should_load_separate_core_block_assets', '__return_false' );
     798
     799        $this->assertFalse(
     800            wp_should_load_separate_core_block_assets(),
     801            'Could not disable loading separate core block assets.'
     802        );
     803
     804        do_action( 'setup_theme' );
     805
     806        $this->assertTrue(
     807            wp_should_load_separate_core_block_assets(),
     808            'Block themes do not load separate core block assets by default.'
     809        );
     810    }
     811
     812    /**
     813     * Helper function to ensure that a block theme is available and active.
     814     */
     815    private function helper_requires_block_theme() {
     816        // No need to switch if we're already on a block theme.
     817        if ( wp_is_block_theme() ) {
     818            return;
     819        }
     820
     821        $block_theme = 'twentytwentytwo';
     822
     823        // Skip if the block theme is not available.
     824        if ( ! wp_get_theme( $block_theme )->exists() ) {
     825            $this->markTestSkipped( "$block_theme must be available." );
     826        }
     827
     828        switch_theme( $block_theme );
     829
     830        // Skip if we could not switch to the block theme.
     831        if ( wp_get_theme()->stylesheet !== $block_theme ) {
     832            $this->markTestSkipped( "Could not switch to $block_theme." );
     833        }
     834    }
    703835}
  • trunk/tests/phpunit/tests/theme/wpTheme.php

    r52383 r52386  
    354354        );
    355355    }
    356 
    357     /**
    358      * Tests that block themes support a feature by default.
    359      *
    360      * @ticket 54597
    361      * @dataProvider data_block_theme_has_default_support
    362      *
    363      * @covers ::_add_default_theme_supports
    364      *
    365      * @param array $support {
    366      *     The feature to check.
    367      *
    368      *     @type string $feature     The feature to check.
    369      *     @type string $sub_feature Optional. The sub-feature to check.
    370      * }
    371      */
    372     public function test_block_theme_has_default_support( $support ) {
    373         $this->helper_requires_block_theme();
    374 
    375         $support_data     = array_values( $support );
    376         $support_data_str = implode( ': ', $support_data );
    377 
    378         // Remove existing support.
    379         if ( current_theme_supports( ...$support_data ) ) {
    380             remove_theme_support( ...$support_data );
    381         }
    382 
    383         $this->assertFalse(
    384             current_theme_supports( ...$support_data ),
    385             "Could not remove support for $support_data_str."
    386         );
    387 
    388         do_action( 'setup_theme' );
    389 
    390         $this->assertTrue(
    391             current_theme_supports( ...$support_data ),
    392             "Does not have default support for $support_data_str."
    393         );
    394     }
    395 
    396     /**
    397      * Data provider.
    398      *
    399      * @return array
    400      */
    401     public function data_block_theme_has_default_support() {
    402         return array(
    403             'post-thumbnails'      => array(
    404                 'support' => array(
    405                     'feature' => 'post-thumbnails',
    406                 ),
    407             ),
    408             'responsive-embeds'    => array(
    409                 'support' => array(
    410                     'feature' => 'responsive-embeds',
    411                 ),
    412             ),
    413             'editor-styles'        => array(
    414                 'support' => array(
    415                     'feature' => 'editor-styles',
    416                 ),
    417             ),
    418             'html5: style'         => array(
    419                 'support' => array(
    420                     'feature'     => 'html5',
    421                     'sub_feature' => 'style',
    422                 ),
    423             ),
    424             'html5: script'        => array(
    425                 'support' => array(
    426                     'feature'     => 'html5',
    427                     'sub_feature' => 'script',
    428                 ),
    429             ),
    430             'automatic-feed-links' => array(
    431                 'support' => array(
    432                     'feature' => 'automatic-feed-links',
    433                 ),
    434             ),
    435         );
    436     }
    437 
    438     /**
    439      * Tests that block themes load separate core block assets by default.
    440      *
    441      * @ticket 54597
    442      *
    443      * @covers ::wp_should_load_separate_core_block_assets
    444      */
    445     public function test_block_theme_should_load_separate_core_block_assets_by_default() {
    446         $this->helper_requires_block_theme();
    447 
    448         add_filter( 'should_load_separate_core_block_assets', '__return_false' );
    449 
    450         $this->assertFalse(
    451             wp_should_load_separate_core_block_assets(),
    452             'Could not disable loading separate core block assets.'
    453         );
    454 
    455         do_action( 'setup_theme' );
    456 
    457         $this->assertTrue(
    458             wp_should_load_separate_core_block_assets(),
    459             'Block themes do not load separate core block assets by default.'
    460         );
    461     }
    462 
    463     /**
    464      * Helper function to ensure that a block theme is available and active.
    465      */
    466     private function helper_requires_block_theme() {
    467         // No need to switch if we're already on a block theme.
    468         if ( wp_is_block_theme() ) {
    469             return;
    470         }
    471 
    472         $block_theme        = 'twentytwentytwo';
    473         $block_theme_object = new WP_Theme( $block_theme, WP_CONTENT_DIR . '/themes' );
    474 
    475         // Skip if the block theme is not available.
    476         if ( ! $block_theme_object->exists() ) {
    477             $this->markTestSkipped( "$block_theme must be available." );
    478         }
    479 
    480         switch_theme( $block_theme );
    481 
    482         // Skip if we could not switch to the block theme.
    483         if ( wp_get_theme()->stylesheet !== $block_theme ) {
    484             $this->markTestSkipped( "Could not switch to $block_theme." );
    485         }
    486     }
    487356}
Note: See TracChangeset for help on using the changeset viewer.