Make WordPress Core


Ignore:
Timestamp:
04/12/2022 09:38:18 AM (2 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/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}
Note: See TracChangeset for help on using the changeset viewer.