Make WordPress Core

Changeset 53153


Ignore:
Timestamp:
04/12/2022 09:38:18 AM (5 years ago)
Author:
gziolo
Message:

Tests: Improve test cleanup for block supports

Let's unregister the block in the tear_down method. The block will be unregistered even if the test fails.

Props ramonopoly, antonvlasenko.
See #55505.
Follow-up [53085], [53076].

Location:
trunk/tests/phpunit/tests/block-supports
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/block-supports/border.php

    r53128 r53153  
    55class Test_Block_Supports_Border extends WP_UnitTestCase {
    66        /**
     7         * @var string|null
     8         */
     9        private $test_block_name;
     10
     11        function set_up() {
     12                parent::set_up();
     13                $this->test_block_name = null;
     14        }
     15
     16        function tear_down() {
     17                unregister_block_type( $this->test_block_name );
     18                $this->test_block_name = null;
     19                parent::set_up();
     20        }
     21
     22        /**
    723         * @ticket 55505
    824         *
    … …  
    1026         */
    1127        function test_border_color_slug_with_numbers_is_kebab_cased_properly() {
    12                 $block_name = 'test/border-color-slug-with-numbers-is-kebab-cased-properly';
     28                $this->test_block_name = 'test/border-color-slug-with-numbers-is-kebab-cased-properly';
    1329                register_block_type(
    14                         $block_name,
     30                        $this->test_block_name,
    1531                        array(
    1632                                'api_version' => 2,
    … …  
    3450                );
    3551                $registry   = WP_Block_Type_Registry::get_instance();
    36                 $block_type = $registry->get_registered( $block_name );
     52                $block_type = $registry->get_registered( $this->test_block_name );
    3753                $block_atts = array(
    3854                        'borderColor' => 'red',
    … …  
    5369
    5470                $this->assertSame( $expected, $actual );
    55                 unregister_block_type( $block_name );
    5671        }
    5772
    … …  
    6277         */
    6378        function test_border_with_skipped_serialization_block_supports() {
    64                 $block_name = 'test/border-with-skipped-serialization-block-supports';
     79                $this->test_block_name = 'test/border-with-skipped-serialization-block-supports';
    6580                register_block_type(
    66                         $block_name,
     81                        $this->test_block_name,
    6782                        array(
    6883                                'api_version' => 2,
    … …  
    8499                );
    85100                $registry   = WP_Block_Type_Registry::get_instance();
    86                 $block_type = $registry->get_registered( $block_name );
     101                $block_type = $registry->get_registered( $this->test_block_name );
    87102                $block_atts = array(
    88103                        'style' => array(
    … …  
    100115
    101116                $this->assertSame( $expected, $actual );
    102                 unregister_block_type( $block_name );
    103117        }
    104118
    … …  
    109123         */
    110124        function test_radius_with_individual_skipped_serialization_block_supports() {
    111                 $block_name = 'test/radius-with-individual-skipped-serialization-block-supports';
     125                $this->test_block_name = 'test/radius-with-individual-skipped-serialization-block-supports';
    112126                register_block_type(
    113                         $block_name,
     127                        $this->test_block_name,
    114128                        array(
    115129                                'api_version' => 2,
    … …  
    131145                );
    132146                $registry   = WP_Block_Type_Registry::get_instance();
    133                 $block_type = $registry->get_registered( $block_name );
     147                $block_type = $registry->get_registered( $this->test_block_name );
    134148                $block_atts = array(
    135149                        'style' => array(
    … …  
    149163
    150164                $this->assertSame( $expected, $actual );
    151                 unregister_block_type( $block_name );
    152165        }
    153166}
  • trunk/tests/phpunit/tests/block-supports/colors.php

    r53128 r53153  
    55class Tests_Block_Supports_Colors extends WP_UnitTestCase {
    66        /**
     7         * @var string|null
     8         */
     9        private $test_block_name;
     10
     11        function set_up() {
     12                parent::set_up();
     13                $this->test_block_name = null;
     14        }
     15
     16        function tear_down() {
     17                unregister_block_type( $this->test_block_name );
     18                $this->test_block_name = null;
     19                parent::set_up();
     20        }
     21
     22        /**
    723         * @ticket 54337
    824         *
    … …  
    1026         */
    1127        function test_color_slugs_with_numbers_are_kebab_cased_properly() {
     28                $this->test_block_name = 'test/color-slug-with-numbers';
    1229                register_block_type(
    13                         'test/color-slug-with-numbers',
     30                        $this->test_block_name,
    1431                        array(
    1532                                'api_version' => 2,
    … …  
    3552                );
    3653                $registry   = WP_Block_Type_Registry::get_instance();
    37                 $block_type = $registry->get_registered( 'test/color-slug-with-numbers' );
     54                $block_type = $registry->get_registered( $this->test_block_name );
    3855
    3956                $block_atts = array(
    … …  
    4764
    4865                $this->assertSame( $expected, $actual );
    49                 unregister_block_type( 'test/color-slug-with-numbers' );
    5066        }
    5167
    … …  
    5672         */
    5773        function test_color_with_skipped_serialization_block_supports() {
    58                 $block_name = 'test/color-with-skipped-serialization-block-supports';
     74                $this->test_block_name = 'test/color-with-skipped-serialization-block-supports';
    5975                register_block_type(
    60                         $block_name,
     76                        $this->test_block_name,
    6177                        array(
    6278                                'api_version' => 2,
    … …  
    7793
    7894                $registry   = WP_Block_Type_Registry::get_instance();
    79                 $block_type = $registry->get_registered( $block_name );
     95                $block_type = $registry->get_registered( $this->test_block_name );
    8096                $block_atts = array(
    8197                        'style' => array(
    … …  
    91107
    92108                $this->assertSame( $expected, $actual );
    93                 unregister_block_type( $block_name );
    94109        }
    95110
    … …  
    100115         */
    101116        function test_gradient_with_individual_skipped_serialization_block_supports() {
    102                 $block_name = 'test/gradient-with-individual-skipped-serialization-block-support';
     117                $this->test_block_name = 'test/gradient-with-individual-skipped-serialization-block-support';
    103118                register_block_type(
    104                         $block_name,
     119                        $this->test_block_name,
    105120                        array(
    106121                                'api_version' => 2,
    … …  
    121136
    122137                $registry   = WP_Block_Type_Registry::get_instance();
    123                 $block_type = $registry->get_registered( $block_name );
     138                $block_type = $registry->get_registered( $this->test_block_name );
    124139                $block_atts = array(
    125140                        'style' => array(
    … …  
    137152
    138153                $this->assertSame( $expected, $actual );
    139                 unregister_block_type( $block_name );
    140154        }
    141155}
  • trunk/tests/phpunit/tests/block-supports/spacing.php

    r53128 r53153  
    55class Test_Block_Supports_Spacing extends WP_UnitTestCase {
    66        /**
     7         * @var string|null
     8         */
     9        private $test_block_name;
     10
     11        function set_up() {
     12                parent::set_up();
     13                $this->test_block_name = null;
     14        }
     15
     16        function tear_down() {
     17                unregister_block_type( $this->test_block_name );
     18                $this->test_block_name = null;
     19                parent::set_up();
     20        }
     21
     22        /**
    723         * @ticket 55505
    824         *
    … …  
    1026         */
    1127        function test_spacing_style_is_applied() {
    12                 $block_name = 'test/spacing-style-is-applied';
     28                $this->test_block_name = 'test/spacing-style-is-applied';
    1329                register_block_type(
    14                         $block_name,
     30                        $this->test_block_name,
    1531                        array(
    1632                                'api_version' => 2,
    … …  
    3046                );
    3147                $registry   = WP_Block_Type_Registry::get_instance();
    32                 $block_type = $registry->get_registered( $block_name );
     48                $block_type = $registry->get_registered( $this->test_block_name );
    3349                $block_atts = array(
    3450                        'style' => array(
    … …  
    5268
    5369                $this->assertSame( $expected, $actual );
    54                 unregister_block_type( $block_name );
    5570        }
    5671
    … …  
    6176         */
    6277        function test_spacing_with_skipped_serialization_block_supports() {
    63                 $block_name = 'test/spacing-with-skipped-serialization-block-supports';
     78                $this->test_block_name = 'test/spacing-with-skipped-serialization-block-supports';
    6479                register_block_type(
    65                         $block_name,
     80                        $this->test_block_name,
    6681                        array(
    6782                                'api_version' => 2,
    … …  
    8297                );
    8398                $registry   = WP_Block_Type_Registry::get_instance();
    84                 $block_type = $registry->get_registered( $block_name );
     99                $block_type = $registry->get_registered( $this->test_block_name );
    85100                $block_atts = array(
    86101                        'style' => array(
    … …  
    102117
    103118                $this->assertSame( $expected, $actual );
    104                 unregister_block_type( $block_name );
    105119        }
    106120
    … …  
    111125         */
    112126        function test_margin_with_individual_skipped_serialization_block_supports() {
    113                 $block_name = 'test/margin-with-individual-skipped-serialization-block-supports';
     127                $this->test_block_name = 'test/margin-with-individual-skipped-serialization-block-supports';
    114128                register_block_type(
    115                         $block_name,
     129                        $this->test_block_name,
    116130                        array(
    117131                                'api_version' => 2,
    … …  
    132146                );
    133147                $registry   = WP_Block_Type_Registry::get_instance();
    134                 $block_type = $registry->get_registered( $block_name );
     148                $block_type = $registry->get_registered( $this->test_block_name );
    135149                $block_atts = array(
    136150                        'style' => array(
    … …  
    154168
    155169                $this->assertSame( $expected, $actual );
    156                 unregister_block_type( $block_name );
    157170        }
    158171}
  • trunk/tests/phpunit/tests/block-supports/typography.php

    r53128 r53153  
    55class Tests_Block_Supports_Typography extends WP_UnitTestCase {
    66        /**
     7         * @var string|null
     8         */
     9        private $test_block_name;
     10
     11        function set_up() {
     12                parent::set_up();
     13                $this->test_block_name = null;
     14        }
     15
     16        function tear_down() {
     17                unregister_block_type( $this->test_block_name );
     18                $this->test_block_name = null;
     19                parent::set_up();
     20        }
     21
     22        /**
    723         * @ticket 54337
    824         *
    … …  
    1026         */
    1127        function test_font_size_slug_with_numbers_is_kebab_cased_properly() {
    12                 register_block_type(
    13                         'test/font-size-slug-with-numbers',
     28                $this->test_block_name = 'test/font-size-slug-with-numbers';
     29                register_block_type(
     30                        $this->test_block_name,
    1431                        array(
    1532                                'api_version' => 2,
    … …  
    2744                );
    2845                $registry   = WP_Block_Type_Registry::get_instance();
    29                 $block_type = $registry->get_registered( 'test/font-size-slug-with-numbers' );
     46                $block_type = $registry->get_registered( $this->test_block_name );
    3047
    3148                $block_atts = array( 'fontSize' => 'h1' );
    … …  
    3552
    3653                $this->assertSame( $expected, $actual );
    37                 unregister_block_type( 'test/font-size-slug-with-numbers' );
    3854        }
    3955        /**
    … …  
    4359         */
    4460        function test_font_family_with_legacy_inline_styles_using_a_value() {
    45                 $block_name = 'test/font-family-with-inline-styles-using-value';
    46                 register_block_type(
    47                         $block_name,
     61                $this->test_block_name = 'test/font-family-with-inline-styles-using-value';
     62                register_block_type(
     63                        $this->test_block_name,
    4864                        array(
    4965                                'api_version' => 2,
    … …  
    6177                );
    6278                $registry   = WP_Block_Type_Registry::get_instance();
    63                 $block_type = $registry->get_registered( $block_name );
     79                $block_type = $registry->get_registered( $this->test_block_name );
    6480                $block_atts = array( 'style' => array( 'typography' => array( 'fontFamily' => 'serif' ) ) );
    6581
    … …  
    6884
    6985                $this->assertSame( $expected, $actual );
    70                 unregister_block_type( $block_name );
    7186        }
    7287
    … …  
    7792         */
    7893        function test_typography_with_skipped_serialization_block_supports() {
    79                 $block_name = 'test/typography-with-skipped-serialization-block-supports';
    80                 register_block_type(
    81                         $block_name,
     94                $this->test_block_name = 'test/typography-with-skipped-serialization-block-supports';
     95                register_block_type(
     96                        $this->test_block_name,
    8297                        array(
    8398                                'api_version' => 2,
    … …  
    99114                );
    100115                $registry   = WP_Block_Type_Registry::get_instance();
    101                 $block_type = $registry->get_registered( $block_name );
     116                $block_type = $registry->get_registered( $this->test_block_name );
    102117                $block_atts = array(
    103118                        'style' => array(
    … …  
    115130
    116131                $this->assertSame( $expected, $actual );
    117                 unregister_block_type( $block_name );
    118132        }
    119133
    … …  
    124138         */
    125139        function test_letter_spacing_with_individual_skipped_serialization_block_supports() {
    126                 $block_name = 'test/letter-spacing-with-individua-skipped-serialization-block-supports';
    127                 register_block_type(
    128                         $block_name,
     140                $this->test_block_name = 'test/letter-spacing-with-individua-skipped-serialization-block-supports';
     141                register_block_type(
     142                        $this->test_block_name,
    129143                        array(
    130144                                'api_version' => 2,
    … …  
    145159                );
    146160                $registry   = WP_Block_Type_Registry::get_instance();
    147                 $block_type = $registry->get_registered( $block_name );
     161                $block_type = $registry->get_registered( $this->test_block_name );
    148162                $block_atts = array( 'style' => array( 'typography' => array( 'letterSpacing' => '22px' ) ) );
    149163
    … …  
    152166
    153167                $this->assertSame( $expected, $actual );
    154                 unregister_block_type( $block_name );
    155168        }
    156169        /**
    … …  
    160173         */
    161174        function test_font_family_with_legacy_inline_styles_using_a_css_var() {
    162                 $block_name = 'test/font-family-with-inline-styles-using-css-var';
    163                 register_block_type(
    164                         $block_name,
     175                $this->test_block_name = 'test/font-family-with-inline-styles-using-css-var';
     176                register_block_type(
     177                        $this->test_block_name,
    165178                        array(
    166179                                'api_version' => 2,
    … …  
    178191                );
    179192                $registry   = WP_Block_Type_Registry::get_instance();
    180                 $block_type = $registry->get_registered( $block_name );
     193                $block_type = $registry->get_registered( $this->test_block_name );
    181194                $block_atts = array( 'style' => array( 'typography' => array( 'fontFamily' => 'var:preset|font-family|h1' ) ) );
    182195
    … …  
    185198
    186199                $this->assertSame( $expected, $actual );
    187                 unregister_block_type( $block_name );
    188200        }
    189201        /**
    … …  
    193205         */
    194206        function test_font_family_with_class() {
    195                 $block_name = 'test/font-family-with-class';
    196                 register_block_type(
    197                         $block_name,
     207                $this->test_block_name = 'test/font-family-with-class';
     208                register_block_type(
     209                        $this->test_block_name,
    198210                        array(
    199211                                'api_version' => 2,
    … …  
    211223                );
    212224                $registry   = WP_Block_Type_Registry::get_instance();
    213                 $block_type = $registry->get_registered( $block_name );
     225                $block_type = $registry->get_registered( $this->test_block_name );
    214226                $block_atts = array( 'fontFamily' => 'h1' );
    215227
    … …  
    218230
    219231                $this->assertSame( $expected, $actual );
    220                 unregister_block_type( $block_name );
    221232        }
    222233
Note: See TracChangeset for help on using the changeset viewer.