|
7 | 7 | * @since 6.6.0 |
8 | 8 | * |
9 | 9 | * @group blocks |
| 10 | + * @coversDefaultClass WP_Block_Styles_Registry |
10 | 11 | */ |
11 | 12 | class Tests_Blocks_wpBlockStylesRegistry extends WP_UnitTestCase { |
12 | 13 |
|
@@ -67,6 +68,63 @@ public function test_register_block_style_with_array_of_block_names() { |
67 | 68 | $this->assertTrue( $this->registry->is_registered( 'core/group', 'plain' ) ); |
68 | 69 | } |
69 | 70 |
|
| 71 | + /** |
| 72 | + * Should accept valid string style label. The registered style should have the same label. |
| 73 | + * |
| 74 | + * @ticket 52592 |
| 75 | + * |
| 76 | + * @covers ::register |
| 77 | + * @covers ::is_registered |
| 78 | + * @covers ::get_registered_styles_for_block |
| 79 | + */ |
| 80 | + public function test_register_block_style_with_label() { |
| 81 | + $name = 'core/paragraph'; |
| 82 | + $style_properties = array( |
| 83 | + 'name' => 'fancy', |
| 84 | + 'label' => 'Fancy', |
| 85 | + ); |
| 86 | + $result = $this->registry->register( $name, $style_properties ); |
| 87 | + |
| 88 | + $this->assertTrue( $result, 'The block style should be registered when the label is a valid string.' ); |
| 89 | + $this->assertTrue( |
| 90 | + $this->registry->is_registered( $name, 'fancy' ), |
| 91 | + 'The block type should have the block style registered when the label is valid.' |
| 92 | + ); |
| 93 | + $this->assertSame( |
| 94 | + $style_properties['label'], |
| 95 | + $this->registry->get_registered_styles_for_block( $name )['fancy']['label'], |
| 96 | + 'The registered block style should have the same label.' |
| 97 | + ); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Should register the block style when `label` is missing, using `name` as the label. |
| 102 | + * |
| 103 | + * @ticket 52592 |
| 104 | + * |
| 105 | + * @covers ::register |
| 106 | + * @covers ::is_registered |
| 107 | + * @covers ::get_registered_styles_for_block |
| 108 | + */ |
| 109 | + public function test_register_block_style_without_label() { |
| 110 | + $name = 'core/paragraph'; |
| 111 | + $style_properties = array( |
| 112 | + 'name' => 'fancy', |
| 113 | + ); |
| 114 | + $result = $this->registry->register( $name, $style_properties ); |
| 115 | + |
| 116 | + $this->assertTrue( $result, 'The block style should be registered when the label is missing.' ); |
| 117 | + $this->assertTrue( |
| 118 | + $this->registry->is_registered( $name, 'fancy' ), |
| 119 | + 'The block type should have the block style registered when the label is missing.' |
| 120 | + ); |
| 121 | + $this->assertSame( |
| 122 | + $style_properties['name'], |
| 123 | + $this->registry->get_registered_styles_for_block( $name )['fancy']['label'], |
| 124 | + 'The registered block style label should be the same as the name.' |
| 125 | + ); |
| 126 | + } |
| 127 | + |
70 | 128 | /** |
71 | 129 | * @ticket 63957 |
72 | 130 | */ |
|
0 commit comments