Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions tests/phpunit/tests/blocks/wpBlockStylesRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);
}
}
Loading