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/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}
Note: See TracChangeset for help on using the changeset viewer.