77 * @since 5.0.0
88 *
99 * @group blocks
10+ *
11+ * @coversDefaultClass WP_Block_Type_Registry
1012 */
1113class Tests_Blocks_wpBlockTypeRegistry extends WP_UnitTestCase {
1214
@@ -41,57 +43,42 @@ public function tear_down() {
4143 }
4244
4345 /**
44- * Should reject numbers
46+ * Should reject invalid block names.
4547 *
4648 * @ticket 45097
4749 *
48- * @expectedIncorrectUsage WP_Block_Type_Registry::register
49- */
50- public function test_invalid_non_string_names () {
51- $ result = $ this ->registry ->register ( 1 , array () );
52- $ this ->assertFalse ( $ result );
53- }
54-
55- /**
56- * Should reject blocks without a namespace
50+ * @covers ::register
5751 *
58- * @ticket 45097
52+ * @dataProvider data_invalid_block_names
5953 *
6054 * @expectedIncorrectUsage WP_Block_Type_Registry::register
6155 */
62- public function test_invalid_names_without_namespace ( ) {
63- $ result = $ this ->registry ->register ( ' paragraph ' , array () );
56+ public function test_invalid_block_names ( $ name ) {
57+ $ result = $ this ->registry ->register ( $ name , array () );
6458 $ this ->assertFalse ( $ result );
6559 }
6660
6761 /**
68- * Should reject blocks with invalid characters
69- *
70- * @ticket 45097
62+ * Data provider for test_invalid_block_names().
7163 *
72- * @expectedIncorrectUsage WP_Block_Type_Registry::register
64+ * @return array<string, array{ 0: mixed }>
7365 */
74- public function test_invalid_characters () {
75- $ result = $ this ->registry ->register ( 'still/_doing_it_wrong ' , array () );
76- $ this ->assertFalse ( $ result );
66+ public function data_invalid_block_names (): array {
67+ return array (
68+ 'non-string name ' => array ( 1 ),
69+ 'no namespace ' => array ( 'paragraph ' ),
70+ 'invalid characters ' => array ( 'still/_doing_it_wrong ' ),
71+ 'uppercase characters ' => array ( 'Core/Paragraph ' ),
72+ );
7773 }
7874
7975 /**
80- * Should reject blocks with uppercase characters
76+ * Should accept valid block names.
8177 *
8278 * @ticket 45097
8379 *
84- * @expectedIncorrectUsage WP_Block_Type_Registry::register
85- */
86- public function test_uppercase_characters () {
87- $ result = $ this ->registry ->register ( 'Core/Paragraph ' , array () );
88- $ this ->assertFalse ( $ result );
89- }
90-
91- /**
92- * Should accept valid block names
93- *
94- * @ticket 45097
80+ * @covers ::register
81+ * @covers ::get_registered
9582 */
9683 public function test_register_block_type () {
9784 $ name = 'core/paragraph ' ;
@@ -106,10 +93,12 @@ public function test_register_block_type() {
10693 }
10794
10895 /**
109- * Should fail to re-register the same block
96+ * Should fail to re-register the same block.
11097 *
11198 * @ticket 45097
11299 *
100+ * @covers ::register
101+ *
113102 * @expectedIncorrectUsage WP_Block_Type_Registry::register
114103 */
115104 public function test_register_block_type_twice () {
@@ -125,9 +114,11 @@ public function test_register_block_type_twice() {
125114 }
126115
127116 /**
128- * Should accept a WP_Block_Type instance
117+ * Should accept a WP_Block_Type instance.
129118 *
130119 * @ticket 45097
120+ *
121+ * @covers ::register
131122 */
132123 public function test_register_block_type_instance () {
133124 $ block_type = new WP_Fake_Block_Type ( 'core/fake ' );
@@ -137,10 +128,12 @@ public function test_register_block_type_instance() {
137128 }
138129
139130 /**
140- * Unregistering should fail if a block is not registered
131+ * Unregistering should fail if a block is not registered.
141132 *
142133 * @ticket 45097
143134 *
135+ * @covers ::unregister
136+ *
144137 * @expectedIncorrectUsage WP_Block_Type_Registry::unregister
145138 */
146139 public function test_unregister_not_registered_block () {
@@ -149,9 +142,12 @@ public function test_unregister_not_registered_block() {
149142 }
150143
151144 /**
152- * Should unregister existing blocks
145+ * Should unregister existing blocks.
153146 *
154147 * @ticket 45097
148+ *
149+ * @covers ::unregister
150+ * @covers ::is_registered
155151 */
156152 public function test_unregister_block_type () {
157153 $ name = 'core/paragraph ' ;
@@ -168,6 +164,8 @@ public function test_unregister_block_type() {
168164
169165 /**
170166 * @ticket 45097
167+ *
168+ * @covers ::get_all_registered
171169 */
172170 public function test_get_all_registered () {
173171 $ names = array ( 'core/paragraph ' , 'core/image ' , 'core/blockquote ' );
0 commit comments