| | 75 | |
| | 76 | /** |
| | 77 | * Should accept valid string style label. |
| | 78 | * The registered style should have the same label. |
| | 79 | * |
| | 80 | * @ticket 52592 |
| | 81 | * |
| | 82 | * @covers WP_Block_Styles_Registry::register |
| | 83 | * @covers WP_Block_Styles_Registry::is_registered |
| | 84 | * @covers WP_Block_Styles_Registry::get_registered_styles_for_block |
| | 85 | */ |
| | 86 | public function test_register_block_style_with_string_style_label() { |
| | 87 | $name = 'core/paragraph'; |
| | 88 | $style_properties = array( |
| | 89 | 'name' => 'fancy', |
| | 90 | 'label' => 'Fancy', |
| | 91 | ); |
| | 92 | $result = $this->registry->register( $name, $style_properties ); |
| | 93 | |
| | 94 | $this->assertTrue( $result, 'The block style should be registered when the label is a valid string.' ); |
| | 95 | $this->assertTrue( |
| | 96 | $this->registry->is_registered( $name, 'fancy' ), |
| | 97 | 'The block type should have the block style registered when the label is valid.' |
| | 98 | ); |
| | 99 | $this->assertEquals( |
| | 100 | $style_properties['label'], |
| | 101 | $this->registry->get_registered_styles_for_block( $name )['fancy']['label'], |
| | 102 | 'The registered block style should have the same label.' |
| | 103 | ); |
| | 104 | } |
| | 105 | |
| | 106 | /** |
| | 107 | * Should not accept invalid style label. |
| | 108 | * |
| | 109 | * @ticket 52592 |
| | 110 | * |
| | 111 | * @covers WP_Block_Styles_Registry::register |
| | 112 | * @covers WP_Block_Styles_Registry::is_registered |
| | 113 | */ |
| | 114 | public function test_register_block_style_with_invalid_style_label() { |
| | 115 | $name = 'core/paragraph'; |
| | 116 | $style_properties = array( |
| | 117 | 'name' => 'fancy', |
| | 118 | ); |
| | 119 | |
| | 120 | $this->setExpectedIncorrectUsage( 'WP_Block_Styles_Registry::register' ); |
| | 121 | |
| | 122 | $result = $this->registry->register( $name, $style_properties ); |
| | 123 | $this->assertFalse( $result, 'The block style should not be registered when the label property is missing.' ); |
| | 124 | $this->assertFalse( |
| | 125 | $this->registry->is_registered( $name, 'fancy' ), |
| | 126 | 'The block type should not have the block style registered when the label property is missing.' |
| | 127 | ); |
| | 128 | |
| | 129 | $style_properties['label'] = ['Fancy']; |
| | 130 | |
| | 131 | $result = $this->registry->register( $name, $style_properties ); |
| | 132 | $this->assertFalse( $result, 'The block style should not be registered when the label property is not a string.' ); |
| | 133 | $this->assertFalse( |
| | 134 | $this->registry->is_registered( $name, 'fancy' ), |
| | 135 | 'The block type should not have the block style registered when the label property is not a string.' |
| | 136 | ); |
| | 137 | } |