Make WordPress Core


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.

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.