Skip to content

Commit 682f534

Browse files
Tests: Add unit tests for a label fallback in WP_Block_Styles_Registry::register().
Follow-up to [59760]. Props Rahmohn, mukesh27, SergeyBiryukov. See #63167. git-svn-id: https://develop.svn.wordpress.org/trunk@61186 602fd350-edb4-49c9-b593-d223f7449a82
1 parent eb513c2 commit 682f534

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/phpunit/tests/blocks/wpBlockStylesRegistry.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @since 6.6.0
88
*
99
* @group blocks
10+
* @coversDefaultClass WP_Block_Styles_Registry
1011
*/
1112
class Tests_Blocks_wpBlockStylesRegistry extends WP_UnitTestCase {
1213

@@ -67,6 +68,63 @@ public function test_register_block_style_with_array_of_block_names() {
6768
$this->assertTrue( $this->registry->is_registered( 'core/group', 'plain' ) );
6869
}
6970

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+
70128
/**
71129
* @ticket 63957
72130
*/

0 commit comments

Comments
 (0)