- Timestamp:
- 02/16/2024 12:53:16 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/block-bindings/wpBlockBindingsRegistry.php
r57562 r57641 40 40 return 'test-value'; 41 41 }, 42 'uses_context' => array( 'sourceContext' ), 42 43 ); 43 44 } … … 158 159 159 160 self::$test_source_properties['get_value_callback'] = 'not-a-callback'; 161 162 $result = $this->registry->register( self::$test_source_name, self::$test_source_properties ); 163 $this->assertFalse( $result ); 164 } 165 166 /** 167 * Should reject block bindings registration if `uses_context` is not an array. 168 * 169 * @ticket 60525 170 * 171 * @covers WP_Block_Bindings_Registry::register 172 * 173 * @expectedIncorrectUsage WP_Block_Bindings_Registry::register 174 */ 175 public function test_register_invalid_string_uses_context() { 176 177 self::$test_source_properties['uses_context'] = 'not-an-array'; 160 178 161 179 $result = $this->registry->register( self::$test_source_name, self::$test_source_properties ); … … 180 198 $result 181 199 ); 200 $this->assertSame( 'test/source', $result->name ); 201 $this->assertSame( 'Test source', $result->label ); 202 $this->assertSame( 203 'test-value', 204 $result->get_value( array(), null, '' ) 205 ); 206 $this->assertEquals( array( 'sourceContext' ), $result->uses_context ); 182 207 } 183 208 … … 322 347 $this->assertTrue( $result ); 323 348 } 349 350 /** 351 * Tests merging `uses_context` from multiple sources. 352 * 353 * @ticket 60525 354 * 355 * @covers ::register_block_bindings_source 356 * @covers WP_Block_Type::get_uses_context 357 */ 358 public function test_merging_uses_context_from_multiple_sources() { 359 $get_value_callback = function () { 360 return 'Anything'; 361 }; 362 363 $block_registry = WP_Block_Type_Registry::get_instance(); 364 $original_uses_context = $block_registry->get_registered( 'core/paragraph' )->uses_context; 365 366 register_block_bindings_source( 367 'test/source-one', 368 array( 369 'label' => 'Test Source One', 370 'get_value_callback' => $get_value_callback, 371 'uses_context' => array( 'commonContext', 'sourceOneContext' ), 372 ) 373 ); 374 375 register_block_bindings_source( 376 'test/source-two', 377 array( 378 'label' => 'Test Source Two', 379 'get_value_callback' => $get_value_callback, 380 'uses_context' => array( 'commonContext', 'sourceTwoContext' ), 381 ) 382 ); 383 384 $new_uses_context = $block_registry->get_registered( 'core/paragraph' )->uses_context; 385 // Checks that the resulting `uses_context` contains the values from both sources. 386 $this->assertContains( 'commonContext', $new_uses_context ); 387 $this->assertContains( 'sourceOneContext', $new_uses_context ); 388 $this->assertContains( 'sourceTwoContext', $new_uses_context ); 389 // Checks that the resulting `uses_context` added 3 unique items. 390 $this->assertSame( count( $original_uses_context ) + 3, count( $new_uses_context ) ); 391 // Checks that the array isn't sparse to prevent issues in the editor. 392 $this->assertSame( array_key_last( $new_uses_context ), count( $new_uses_context ) - 1 ); 393 } 324 394 }
Note: See TracChangeset
for help on using the changeset viewer.