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