diff --git a/tests/phpunit/tests/blocks/wpBlockStylesRegistry.php b/tests/phpunit/tests/blocks/wpBlockStylesRegistry.php index 6d3ff4e54a42e..e7c24d387e45a 100644 --- a/tests/phpunit/tests/blocks/wpBlockStylesRegistry.php +++ b/tests/phpunit/tests/blocks/wpBlockStylesRegistry.php @@ -98,4 +98,62 @@ public function test_is_registered_returns_false_for_both_null_params() { 'Both empty block and style name should return false.' ); } + + /** + * Should accept valid string style label. + * The registered style should have the same label. + * + * @ticket 52592 + * + * @covers WP_Block_Styles_Registry::register + * @covers WP_Block_Styles_Registry::is_registered + * @covers WP_Block_Styles_Registry::get_registered_styles_for_block + */ + public function test_register_block_style_with_label() { + $name = 'core/paragraph'; + $style_properties = array( + 'name' => 'fancy', + 'label' => 'Fancy', + ); + $result = $this->registry->register( $name, $style_properties ); + + $this->assertTrue( $result, 'The block style should be registered when the label is a valid string.' ); + $this->assertTrue( + $this->registry->is_registered( $name, 'fancy' ), + 'The block type should have the block style registered when the label is valid.' + ); + $this->assertSame( + $style_properties['label'], + $this->registry->get_registered_styles_for_block( $name )['fancy']['label'], + 'The registered block style should have the same label.' + ); + } + + /** + * Should register the block style when `label` is missing, using `name` as the label. + * + * @ticket 52592 + * + * @covers WP_Block_Styles_Registry::register + * @covers WP_Block_Styles_Registry::is_registered + * @covers WP_Block_Styles_Registry::get_registered_styles_for_block + */ + public function test_register_block_style_without_label() { + $name = 'core/paragraph'; + $style_properties = array( + 'name' => 'fancy', + ); + $result = $this->registry->register( $name, $style_properties ); + + $this->assertTrue( $result, 'The block style should be registered when the label is missing.' ); + $this->assertTrue( + $this->registry->is_registered( $name, 'fancy' ), + 'The block type should have the block style registered when the label is missing.' + ); + $this->assertSame( + $style_properties['name'], + $this->registry->get_registered_styles_for_block( $name )['fancy']['label'], + 'The registered block style should have a name and label equal.' + ); + } }