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/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.