Make WordPress Core

Changeset 55567


Ignore:
Timestamp:
03/20/2023 06:20:05 PM (2 years ago)
Author:
hellofromTonya
Message:

Tests: Add test class for wp_enqueue_stored_styles().

[54214] added the wp_enqueue_stored_styles() tests and clean_up_global_scope() reset global method to Tests_Theme_wpGetGlobalStylesheet.

This changeset relocates those tests a new test class specifically for wp_enqueue_stored_styles() and removes Tests_Theme_wpGetGlobalStylesheet::clean_up_global_scope() method.

Why not relocate the clean_up_global_scope() method to the new test class?
The test class extends from WP_Theme_UnitTestCase which includes this method.

Follow-up to [54214], [54703].

Props costdev.
See #57841.

Location:
trunk/tests/phpunit/tests/theme
Files:
1 added
1 edited

Legend:

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

    r55148 r55567  
    5555    }
    5656
    57     /**
    58      * Cleans up global scope.
    59      *
    60      * @global WP_Styles $wp_styles
    61      */
    62     public function clean_up_global_scope() {
    63         global $wp_styles;
    64         parent::clean_up_global_scope();
    65         $wp_styles = null;
    66     }
    67 
    6857    public function filter_set_theme_root() {
    6958        return $this->theme_root;
     
    211200    }
    212201
    213     /**
    214      * Tests that stored CSS is enqueued.
    215      *
    216      * @ticket 56467
    217      *
    218      * @covers ::wp_enqueue_stored_styles
    219      */
    220     public function test_should_enqueue_stored_styles() {
    221         $core_styles_to_enqueue = array(
    222             array(
    223                 'selector'     => '.saruman',
    224                 'declarations' => array(
    225                     'color'        => 'white',
    226                     'height'       => '100px',
    227                     'border-style' => 'solid',
    228                 ),
    229             ),
    230         );
    231 
    232         // Enqueues a block supports (core styles).
    233         wp_style_engine_get_stylesheet_from_css_rules(
    234             $core_styles_to_enqueue,
    235             array(
    236                 'context' => 'block-supports',
    237             )
    238         );
    239 
    240         $my_styles_to_enqueue = array(
    241             array(
    242                 'selector'     => '.gandalf',
    243                 'declarations' => array(
    244                     'color'        => 'grey',
    245                     'height'       => '90px',
    246                     'border-style' => 'dotted',
    247                 ),
    248             ),
    249         );
    250 
    251         // Enqueues some other styles.
    252         wp_style_engine_get_stylesheet_from_css_rules(
    253             $my_styles_to_enqueue,
    254             array(
    255                 'context' => 'my-styles',
    256             )
    257         );
    258 
    259         wp_enqueue_stored_styles( array( 'prettify' => false ) );
    260 
    261         $this->assertSame(
    262             array( '.saruman{color:white;height:100px;border-style:solid;}' ),
    263             wp_styles()->registered['core-block-supports']->extra['after'],
    264             'Registered styles with handle of "core-block-supports" do not match expected value from Style Engine store.'
    265         );
    266 
    267         $this->assertSame(
    268             array( '.gandalf{color:grey;height:90px;border-style:dotted;}' ),
    269             wp_styles()->registered['wp-style-engine-my-styles']->extra['after'],
    270             'Registered styles with handle of "wp-style-engine-my-styles" do not match expected value from the Style Engine store.'
    271         );
    272     }
    273202    /**
    274203     * Tests that switching themes recalculates the stylesheet.
Note: See TracChangeset for help on using the changeset viewer.