- Timestamp:
- 02/08/2024 08:55:18 AM (10 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/block-bindings/wpBlockBindingsRegistry.php
r57375 r57562 14 14 class Tests_Blocks_wpBlockBindingsRegistry extends WP_UnitTestCase { 15 15 16 const TEST_SOURCE_NAME = 'test/source'; 17 const TEST_SOURCE_PROPERTIES = array( 18 'label' => 'Test source', 19 ); 16 public static $test_source_name = 'test/source'; 17 public static $test_source_properties = array(); 20 18 21 19 /** … … 36 34 37 35 $this->registry = new WP_Block_Bindings_Registry(); 36 37 self::$test_source_properties = array( 38 'label' => 'Test source', 39 'get_value_callback' => function () { 40 return 'test-value'; 41 }, 42 ); 38 43 } 39 44 … … 59 64 */ 60 65 public function test_register_invalid_non_string_names() { 61 $result = $this->registry->register( 1, self:: TEST_SOURCE_PROPERTIES);66 $result = $this->registry->register( 1, self::$test_source_properties ); 62 67 $this->assertFalse( $result ); 63 68 } … … 73 78 */ 74 79 public function test_register_invalid_names_without_namespace() { 75 $result = $this->registry->register( 'post-meta', self:: TEST_SOURCE_PROPERTIES);80 $result = $this->registry->register( 'post-meta', self::$test_source_properties ); 76 81 $this->assertFalse( $result ); 77 82 } … … 101 106 */ 102 107 public function test_register_invalid_uppercase_characters() { 103 $result = $this->registry->register( 'Core/PostMeta', self::TEST_SOURCE_PROPERTIES ); 108 $result = $this->registry->register( 'Core/PostMeta', self::$test_source_properties ); 109 $this->assertFalse( $result ); 110 } 111 112 /** 113 * Should reject block bindings registration without a label. 114 * 115 * @ticket 60282 116 * 117 * @covers WP_Block_Bindings_Registry::register 118 * 119 * @expectedIncorrectUsage WP_Block_Bindings_Registry::register 120 */ 121 public function test_register_invalid_missing_label() { 122 123 // Remove the label from the properties. 124 unset( self::$test_source_properties['label'] ); 125 126 $result = $this->registry->register( self::$test_source_name, self::$test_source_properties ); 127 $this->assertFalse( $result ); 128 } 129 130 /** 131 * Should reject block bindings registration without a get_value_callback. 132 * 133 * @ticket 60282 134 * 135 * @covers WP_Block_Bindings_Registry::register 136 * 137 * @expectedIncorrectUsage WP_Block_Bindings_Registry::register 138 */ 139 public function test_register_invalid_missing_get_value_callback() { 140 141 // Remove the get_value_callback from the properties. 142 unset( self::$test_source_properties['get_value_callback'] ); 143 144 $result = $this->registry->register( self::$test_source_name, self::$test_source_properties ); 145 $this->assertFalse( $result ); 146 } 147 148 /** 149 * Should reject block bindings registration if `get_value_callback` is not a callable. 150 * 151 * @ticket 60282 152 * 153 * @covers WP_Block_Bindings_Registry::register 154 * 155 * @expectedIncorrectUsage WP_Block_Bindings_Registry::register 156 */ 157 public function test_register_invalid_incorrect_callback_type() { 158 159 self::$test_source_properties['get_value_callback'] = 'not-a-callback'; 160 161 $result = $this->registry->register( self::$test_source_name, self::$test_source_properties ); 104 162 $this->assertFalse( $result ); 105 163 } … … 111 169 * 112 170 * @covers WP_Block_Bindings_Registry::register 171 * @covers WP_Block_Bindings_Source::__construct 113 172 */ 114 173 public function test_register_block_binding_source() { 115 $result = $this->registry->register( self:: TEST_SOURCE_NAME, self::TEST_SOURCE_PROPERTIES);116 $this->assert Same(117 array_merge(118 array( 'name' => self::TEST_SOURCE_NAME ),119 self:: TEST_SOURCE_PROPERTIES174 $result = $this->registry->register( self::$test_source_name, self::$test_source_properties ); 175 $this->assertEquals( 176 new WP_Block_Bindings_Source( 177 self::$test_source_name, 178 self::$test_source_properties 120 179 ), 121 180 $result … … 144 203 * @covers WP_Block_Bindings_Registry::register 145 204 * @covers WP_Block_Bindings_Registry::unregister 205 * WP_Block_Bindings_Source::__construct 146 206 */ 147 207 public function test_unregister_block_source() { 148 $this->registry->register( self:: TEST_SOURCE_NAME, self::TEST_SOURCE_PROPERTIES);149 150 $result = $this->registry->unregister( self:: TEST_SOURCE_NAME);151 $this->assert Same(152 array_merge(153 array( 'name' => self::TEST_SOURCE_NAME ),154 self:: TEST_SOURCE_PROPERTIES208 $this->registry->register( self::$test_source_name, self::$test_source_properties ); 209 210 $result = $this->registry->unregister( self::$test_source_name ); 211 $this->assertEquals( 212 new WP_Block_Bindings_Source( 213 self::$test_source_name, 214 self::$test_source_properties 155 215 ), 156 216 $result … … 165 225 * @covers WP_Block_Bindings_Registry::register 166 226 * @covers WP_Block_Bindings_Registry::get_all_registered 227 * WP_Block_Bindings_Source::__construct 167 228 */ 168 229 public function test_get_all_registered() { 169 230 $source_one_name = 'test/source-one'; 170 $source_one_properties = self:: TEST_SOURCE_PROPERTIES;231 $source_one_properties = self::$test_source_properties; 171 232 $this->registry->register( $source_one_name, $source_one_properties ); 172 233 173 234 $source_two_name = 'test/source-two'; 174 $source_two_properties = self:: TEST_SOURCE_PROPERTIES;235 $source_two_properties = self::$test_source_properties; 175 236 $this->registry->register( $source_two_name, $source_two_properties ); 176 237 177 238 $source_three_name = 'test/source-three'; 178 $source_three_properties = self:: TEST_SOURCE_PROPERTIES;239 $source_three_properties = self::$test_source_properties; 179 240 $this->registry->register( $source_three_name, $source_three_properties ); 180 241 181 242 $expected = array( 182 $source_one_name => array_merge( array( 'name' => $source_one_name ), $source_one_properties ),183 $source_two_name => array_merge( array( 'name' => $source_two_name ), $source_two_properties ),184 $source_three_name => array_merge( array( 'name' => $source_three_name ), $source_three_properties ),243 $source_one_name => new WP_Block_Bindings_Source( $source_one_name, $source_one_properties ), 244 $source_two_name => new WP_Block_Bindings_Source( $source_two_name, $source_two_properties ), 245 $source_three_name => new WP_Block_Bindings_Source( $source_three_name, $source_three_properties ), 185 246 ); 186 247 187 248 $registered = $this->registry->get_all_registered(); 188 $this->assert Same( $expected, $registered );249 $this->assertEquals( $expected, $registered ); 189 250 } 190 251 … … 198 259 */ 199 260 public function test_get_registered_rejects_unknown_source_name() { 200 $this->registry->register( self:: TEST_SOURCE_NAME, self::TEST_SOURCE_PROPERTIES);261 $this->registry->register( self::$test_source_name, self::$test_source_properties ); 201 262 202 263 $source = $this->registry->get_registered( 'test/unknown-source' ); … … 211 272 * @covers WP_Block_Bindings_Registry::register 212 273 * @covers WP_Block_Bindings_Registry::get_registered 274 * @covers WP_Block_Bindings_Source::__construct 213 275 */ 214 276 public function test_get_registered() { 215 277 $source_one_name = 'test/source-one'; 216 $source_one_properties = self:: TEST_SOURCE_PROPERTIES;278 $source_one_properties = self::$test_source_properties; 217 279 $this->registry->register( $source_one_name, $source_one_properties ); 218 280 219 281 $source_two_name = 'test/source-two'; 220 $source_two_properties = self:: TEST_SOURCE_PROPERTIES;282 $source_two_properties = self::$test_source_properties; 221 283 $this->registry->register( $source_two_name, $source_two_properties ); 222 284 223 285 $source_three_name = 'test/source-three'; 224 $source_three_properties = self:: TEST_SOURCE_PROPERTIES;286 $source_three_properties = self::$test_source_properties; 225 287 $this->registry->register( $source_three_name, $source_three_properties ); 226 288 227 $result = $this->registry->get_registered( 'test/source-two' ); 228 $this->assertSame( 229 array_merge( 230 array( 'name' => $source_two_name ), 231 $source_two_properties 232 ), 289 $expected = new WP_Block_Bindings_Source( $source_two_name, $source_two_properties ); 290 $result = $this->registry->get_registered( 'test/source-two' ); 291 292 $this->assertEquals( 293 $expected, 233 294 $result 234 295 ); … … 256 317 */ 257 318 public function test_is_registered_for_known_source() { 258 $this->registry->register( self:: TEST_SOURCE_NAME, self::TEST_SOURCE_PROPERTIES);259 260 $result = $this->registry->is_registered( self:: TEST_SOURCE_NAME);319 $this->registry->register( self::$test_source_name, self::$test_source_properties ); 320 321 $result = $this->registry->is_registered( self::$test_source_name ); 261 322 $this->assertTrue( $result ); 262 323 }
Note: See TracChangeset
for help on using the changeset viewer.