Make WordPress Core


Ignore:
Timestamp:
04/12/2022 09:38:18 AM (3 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].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.