diff --git a/phpunit/block-supports/border-test.php b/phpunit/block-supports/border-test.php index bf09bc39ee0876..11e9891c192c95 100644 --- a/phpunit/block-supports/border-test.php +++ b/phpunit/block-supports/border-test.php @@ -7,11 +7,26 @@ */ class WP_Block_Supports_Border_Test extends WP_UnitTestCase { + /** + * @var string|null + */ + private $test_block_name; + + function setUp() { + parent::setUp(); + $this->test_block_name = null; + } + + function tearDown() { + unregister_block_type( $this->test_block_name ); + $this->test_block_name = null; + parent::tearDown(); + } function test_border_color_slug_with_numbers_is_kebab_cased_properly() { - $block_name = 'test/border-color-slug-with-numbers-is-kebab-cased-properly'; + $this->test_block_name = 'test/border-color-slug-with-numbers-is-kebab-cased-properly'; register_block_type( - $block_name, + $this->test_block_name, array( 'api_version' => 2, 'attributes' => array( @@ -33,7 +48,7 @@ function test_border_color_slug_with_numbers_is_kebab_cased_properly() { ) ); $registry = WP_Block_Type_Registry::get_instance(); - $block_type = $registry->get_registered( $block_name ); + $block_type = $registry->get_registered( $this->test_block_name ); $block_atts = array( 'borderColor' => 'red', 'style' => array( @@ -52,13 +67,12 @@ function test_border_color_slug_with_numbers_is_kebab_cased_properly() { ); $this->assertSame( $expected, $actual ); - unregister_block_type( $block_name ); } function test_border_with_skipped_serialization_block_supports() { - $block_name = 'test/border-with-skipped-serialization-block-supports'; + $this->test_block_name = 'test/border-with-skipped-serialization-block-supports'; register_block_type( - $block_name, + $this->test_block_name, array( 'api_version' => 2, 'attributes' => array( @@ -78,7 +92,7 @@ function test_border_with_skipped_serialization_block_supports() { ) ); $registry = WP_Block_Type_Registry::get_instance(); - $block_type = $registry->get_registered( $block_name ); + $block_type = $registry->get_registered( $this->test_block_name ); $block_atts = array( 'style' => array( 'border' => array( @@ -94,13 +108,12 @@ function test_border_with_skipped_serialization_block_supports() { $expected = array(); $this->assertSame( $expected, $actual ); - unregister_block_type( $block_name ); } function test_radius_with_individual_skipped_serialization_block_supports() { - $block_name = 'test/radius-with-individual-skipped-serialization-block-supports'; + $this->test_block_name = 'test/radius-with-individual-skipped-serialization-block-supports'; register_block_type( - $block_name, + $this->test_block_name, array( 'api_version' => 2, 'attributes' => array( @@ -120,7 +133,7 @@ function test_radius_with_individual_skipped_serialization_block_supports() { ) ); $registry = WP_Block_Type_Registry::get_instance(); - $block_type = $registry->get_registered( $block_name ); + $block_type = $registry->get_registered( $this->test_block_name ); $block_atts = array( 'style' => array( 'border' => array( @@ -138,6 +151,5 @@ function test_radius_with_individual_skipped_serialization_block_supports() { ); $this->assertSame( $expected, $actual ); - unregister_block_type( $block_name ); } } diff --git a/phpunit/block-supports/colors-test.php b/phpunit/block-supports/colors-test.php index 88e3994eb226b2..a9708c569c1f76 100644 --- a/phpunit/block-supports/colors-test.php +++ b/phpunit/block-supports/colors-test.php @@ -7,10 +7,26 @@ */ class WP_Block_Supports_Colors_Test extends WP_UnitTestCase { + /** + * @var string|null + */ + private $test_block_name; + + function setUp() { + parent::setUp(); + $this->test_block_name = null; + } + + function tearDown() { + unregister_block_type( $this->test_block_name ); + $this->test_block_name = null; + parent::tearDown(); + } function test_color_slugs_with_numbers_are_kebab_cased_properly() { + $this->test_block_name = 'test/color-slug-with-numbers'; register_block_type( - 'test/color-slug-with-numbers', + $this->test_block_name, array( 'api_version' => 2, 'attributes' => array( @@ -34,7 +50,7 @@ function test_color_slugs_with_numbers_are_kebab_cased_properly() { ) ); $registry = WP_Block_Type_Registry::get_instance(); - $block_type = $registry->get_registered( 'test/color-slug-with-numbers' ); + $block_type = $registry->get_registered( $this->test_block_name ); $block_atts = array( 'textColor' => 'fg1', @@ -46,13 +62,12 @@ function test_color_slugs_with_numbers_are_kebab_cased_properly() { $expected = array( 'class' => 'has-text-color has-fg-1-color has-background has-bg-2-background-color has-background has-gr-3-gradient-background' ); $this->assertSame( $expected, $actual ); - unregister_block_type( 'test/color-slug-with-numbers' ); } function test_color_with_skipped_serialization_block_supports() { - $block_name = 'test/color-with-skipped-serialization-block-supports'; + $this->test_block_name = 'test/color-with-skipped-serialization-block-supports'; register_block_type( - $block_name, + $this->test_block_name, array( 'api_version' => 2, 'attributes' => array( @@ -71,7 +86,7 @@ function test_color_with_skipped_serialization_block_supports() { ); $registry = WP_Block_Type_Registry::get_instance(); - $block_type = $registry->get_registered( $block_name ); + $block_type = $registry->get_registered( $this->test_block_name ); $block_atts = array( 'style' => array( 'color' => array( @@ -85,13 +100,12 @@ function test_color_with_skipped_serialization_block_supports() { $expected = array(); $this->assertSame( $expected, $actual ); - unregister_block_type( $block_name ); } function test_gradient_with_individual_skipped_serialization_block_supports() { - $block_name = 'test/gradient-with-individual-skipped-serialization-block-support'; + $this->test_block_name = 'test/gradient-with-individual-skipped-serialization-block-support'; register_block_type( - $block_name, + $this->test_block_name, array( 'api_version' => 2, 'attributes' => array( @@ -110,7 +124,7 @@ function test_gradient_with_individual_skipped_serialization_block_supports() { ); $registry = WP_Block_Type_Registry::get_instance(); - $block_type = $registry->get_registered( $block_name ); + $block_type = $registry->get_registered( $this->test_block_name ); $block_atts = array( 'style' => array( 'color' => array( @@ -126,6 +140,5 @@ function test_gradient_with_individual_skipped_serialization_block_supports() { ); $this->assertSame( $expected, $actual ); - unregister_block_type( $block_name ); } } diff --git a/phpunit/block-supports/spacing-test.php b/phpunit/block-supports/spacing-test.php index 324514b15a4e4d..618c809b84f6ad 100644 --- a/phpunit/block-supports/spacing-test.php +++ b/phpunit/block-supports/spacing-test.php @@ -7,11 +7,26 @@ */ class WP_Block_Supports_Spacing_Test extends WP_UnitTestCase { + /** + * @var string|null + */ + private $test_block_name; + + function setUp() { + parent::setUp(); + $this->test_block_name = null; + } + + function tearDown() { + unregister_block_type( $this->test_block_name ); + $this->test_block_name = null; + parent::tearDown(); + } function test_spacing_style_is_applied() { - $block_name = 'test/spacing-style-is-applied'; + $this->test_block_name = 'test/spacing-style-is-applied'; register_block_type( - $block_name, + $this->test_block_name, array( 'api_version' => 2, 'attributes' => array( @@ -29,7 +44,7 @@ function test_spacing_style_is_applied() { ) ); $registry = WP_Block_Type_Registry::get_instance(); - $block_type = $registry->get_registered( $block_name ); + $block_type = $registry->get_registered( $this->test_block_name ); $block_atts = array( 'style' => array( 'spacing' => array( @@ -51,13 +66,12 @@ function test_spacing_style_is_applied() { ); $this->assertSame( $expected, $actual ); - unregister_block_type( $block_name ); } function test_spacing_with_skipped_serialization_block_supports() { - $block_name = 'test/spacing-with-skipped-serialization-block-supports'; + $this->test_block_name = 'test/spacing-with-skipped-serialization-block-supports'; register_block_type( - $block_name, + $this->test_block_name, array( 'api_version' => 2, 'attributes' => array( @@ -76,7 +90,7 @@ function test_spacing_with_skipped_serialization_block_supports() { ) ); $registry = WP_Block_Type_Registry::get_instance(); - $block_type = $registry->get_registered( $block_name ); + $block_type = $registry->get_registered( $this->test_block_name ); $block_atts = array( 'style' => array( 'spacing' => array( @@ -96,13 +110,12 @@ function test_spacing_with_skipped_serialization_block_supports() { $expected = array(); $this->assertSame( $expected, $actual ); - unregister_block_type( $block_name ); } function test_margin_with_individual_skipped_serialization_block_supports() { - $block_name = 'test/margin-with-individual-skipped-serialization-block-supports'; + $this->test_block_name = 'test/margin-with-individual-skipped-serialization-block-supports'; register_block_type( - $block_name, + $this->test_block_name, array( 'api_version' => 2, 'attributes' => array( @@ -121,7 +134,7 @@ function test_margin_with_individual_skipped_serialization_block_supports() { ) ); $registry = WP_Block_Type_Registry::get_instance(); - $block_type = $registry->get_registered( $block_name ); + $block_type = $registry->get_registered( $this->test_block_name ); $block_atts = array( 'style' => array( 'spacing' => array( @@ -143,6 +156,5 @@ function test_margin_with_individual_skipped_serialization_block_supports() { ); $this->assertSame( $expected, $actual ); - unregister_block_type( $block_name ); } } diff --git a/phpunit/block-supports/typography-test.php b/phpunit/block-supports/typography-test.php index 312b86f6a0b389..d41218a974ac64 100644 --- a/phpunit/block-supports/typography-test.php +++ b/phpunit/block-supports/typography-test.php @@ -7,10 +7,26 @@ */ class WP_Block_Supports_Typography_Test extends WP_UnitTestCase { + /** + * @var string|null + */ + private $test_block_name; + + function setUp() { + parent::setUp(); + $this->test_block_name = null; + } + + function tearDown() { + unregister_block_type( $this->test_block_name ); + $this->test_block_name = null; + parent::tearDown(); + } function test_font_size_slug_with_numbers_is_kebab_cased_properly() { + $this->test_block_name = 'test/font-size-slug-with-numbers'; register_block_type( - 'test/font-size-slug-with-numbers', + $this->test_block_name, array( 'api_version' => 2, 'attributes' => array( @@ -26,7 +42,7 @@ function test_font_size_slug_with_numbers_is_kebab_cased_properly() { ) ); $registry = WP_Block_Type_Registry::get_instance(); - $block_type = $registry->get_registered( 'test/font-size-slug-with-numbers' ); + $block_type = $registry->get_registered( $this->test_block_name ); $block_atts = array( 'fontSize' => 'h1' ); @@ -34,13 +50,12 @@ function test_font_size_slug_with_numbers_is_kebab_cased_properly() { $expected = array( 'class' => 'has-h-1-font-size' ); $this->assertSame( $expected, $actual ); - unregister_block_type( 'test/font-size-slug-with-numbers' ); } function test_font_family_with_legacy_inline_styles_using_a_value() { - $block_name = 'test/font-family-with-inline-styles-using-value'; + $this->test_block_name = 'test/font-family-with-inline-styles-using-value'; register_block_type( - $block_name, + $this->test_block_name, array( 'api_version' => 2, 'attributes' => array( @@ -56,20 +71,19 @@ function test_font_family_with_legacy_inline_styles_using_a_value() { ) ); $registry = WP_Block_Type_Registry::get_instance(); - $block_type = $registry->get_registered( $block_name ); + $block_type = $registry->get_registered( $this->test_block_name ); $block_atts = array( 'style' => array( 'typography' => array( 'fontFamily' => 'serif' ) ) ); $actual = gutenberg_apply_typography_support( $block_type, $block_atts ); $expected = array( 'style' => 'font-family: serif;' ); $this->assertSame( $expected, $actual ); - unregister_block_type( $block_name ); } function test_typography_with_skipped_serialization_block_supports() { - $block_name = 'test/typography-with-skipped-serialization-block-supports'; + $this->test_block_name = 'test/typography-with-skipped-serialization-block-supports'; register_block_type( - $block_name, + $this->test_block_name, array( 'api_version' => 2, 'attributes' => array( @@ -89,7 +103,7 @@ function test_typography_with_skipped_serialization_block_supports() { ) ); $registry = WP_Block_Type_Registry::get_instance(); - $block_type = $registry->get_registered( $block_name ); + $block_type = $registry->get_registered( $this->test_block_name ); $block_atts = array( 'style' => array( 'typography' => array( @@ -105,13 +119,12 @@ function test_typography_with_skipped_serialization_block_supports() { $expected = array(); $this->assertSame( $expected, $actual ); - unregister_block_type( $block_name ); } function test_letter_spacing_with_individual_skipped_serialization_block_supports() { - $block_name = 'test/letter-spacing-with-individua-skipped-serialization-block-supports'; + $this->test_block_name = 'test/letter-spacing-with-individua-skipped-serialization-block-supports'; register_block_type( - $block_name, + $this->test_block_name, array( 'api_version' => 2, 'attributes' => array( @@ -130,20 +143,19 @@ function test_letter_spacing_with_individual_skipped_serialization_block_support ) ); $registry = WP_Block_Type_Registry::get_instance(); - $block_type = $registry->get_registered( $block_name ); + $block_type = $registry->get_registered( $this->test_block_name ); $block_atts = array( 'style' => array( 'typography' => array( 'letterSpacing' => '22px' ) ) ); $actual = gutenberg_apply_typography_support( $block_type, $block_atts ); $expected = array(); $this->assertSame( $expected, $actual ); - unregister_block_type( $block_name ); } function test_font_family_with_legacy_inline_styles_using_a_css_var() { - $block_name = 'test/font-family-with-inline-styles-using-css-var'; + $this->test_block_name = 'test/font-family-with-inline-styles-using-css-var'; register_block_type( - $block_name, + $this->test_block_name, array( 'api_version' => 2, 'attributes' => array( @@ -159,20 +171,19 @@ function test_font_family_with_legacy_inline_styles_using_a_css_var() { ) ); $registry = WP_Block_Type_Registry::get_instance(); - $block_type = $registry->get_registered( $block_name ); + $block_type = $registry->get_registered( $this->test_block_name ); $block_atts = array( 'style' => array( 'typography' => array( 'fontFamily' => 'var:preset|font-family|h1' ) ) ); $actual = gutenberg_apply_typography_support( $block_type, $block_atts ); $expected = array( 'style' => 'font-family: var(--wp--preset--font-family--h-1);' ); $this->assertSame( $expected, $actual ); - unregister_block_type( $block_name ); } function test_font_family_with_class() { - $block_name = 'test/font-family-with-class'; + $this->test_block_name = 'test/font-family-with-class'; register_block_type( - $block_name, + $this->test_block_name, array( 'api_version' => 2, 'attributes' => array( @@ -188,14 +199,12 @@ function test_font_family_with_class() { ) ); $registry = WP_Block_Type_Registry::get_instance(); - $block_type = $registry->get_registered( $block_name ); + $block_type = $registry->get_registered( $this->test_block_name ); $block_atts = array( 'fontFamily' => 'h1' ); $actual = gutenberg_apply_typography_support( $block_type, $block_atts ); $expected = array( 'class' => 'has-h-1-font-family' ); $this->assertSame( $expected, $actual ); - unregister_block_type( $block_name ); } - }