Changeset 57790 for trunk/tests/phpunit/tests/block-template-utils.php
- Timestamp:
- 03/07/2024 02:10:31 PM (11 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/block-template-utils.php
r56983 r57790 88 88 89 89 /** 90 * Tear down after each test. 91 * 92 * @since 6.5.0 93 */ 94 public function tear_down() { 95 global $wp_current_filter; 96 97 if ( 98 'rest_pre_insert_wp_template' === current_filter() || 99 'rest_pre_insert_wp_template_part' === current_filter() 100 ) { 101 array_pop( $wp_current_filter ); 102 } 103 104 if ( WP_Block_Type_Registry::get_instance()->is_registered( 'tests/hooked-block' ) ) { 105 unregister_block_type( 'tests/hooked-block' ); 106 } 107 108 parent::tear_down(); 109 } 110 111 /** 90 112 * @ticket 59338 91 113 * … … 391 413 $this->assertTrue( $has_html_files, 'contains at least one html file' ); 392 414 } 415 416 /** 417 * @ticket 60671 418 * 419 * @covers inject_ignored_hooked_blocks_metadata_attributes 420 */ 421 public function test_inject_ignored_hooked_blocks_metadata_attributes_into_template() { 422 global $wp_current_filter; 423 // Mock currently set filter. 424 $wp_current_filter[] = 'rest_pre_insert_wp_template'; 425 426 register_block_type( 427 'tests/hooked-block', 428 array( 429 'block_hooks' => array( 430 'tests/anchor-block' => 'after', 431 ), 432 ) 433 ); 434 435 $id = self::TEST_THEME . '//' . 'my_template'; 436 $request = new WP_REST_Request( 'POST', '/wp/v2/templates/' . $id ); 437 438 $changes = new stdClass(); 439 $changes->post_content = '<!-- wp:tests/anchor-block -->Hello<!-- /wp:tests/anchor-block -->'; 440 441 $post = inject_ignored_hooked_blocks_metadata_attributes( $changes, $request ); 442 $this->assertSame( 443 '<!-- wp:tests/anchor-block {"metadata":{"ignoredHookedBlocks":["tests/hooked-block"]}} -->Hello<!-- /wp:tests/anchor-block -->', 444 $post->post_content, 445 'The hooked block was not injected into the anchor block\'s ignoredHookedBlocks metadata.' 446 ); 447 } 448 449 /** 450 * @ticket 60671 451 * 452 * @covers inject_ignored_hooked_blocks_metadata_attributes 453 */ 454 public function test_inject_ignored_hooked_blocks_metadata_attributes_into_template_part() { 455 global $wp_current_filter; 456 // Mock currently set filter. 457 $wp_current_filter[] = 'rest_pre_insert_wp_template_part'; 458 459 register_block_type( 460 'tests/hooked-block', 461 array( 462 'block_hooks' => array( 463 'tests/anchor-block' => 'after', 464 ), 465 ) 466 ); 467 468 $id = self::TEST_THEME . '//' . 'my_template_part'; 469 $request = new WP_REST_Request( 'POST', '/wp/v2/template-parts/' . $id ); 470 471 $changes = new stdClass(); 472 $changes->post_content = '<!-- wp:tests/anchor-block -->Hello<!-- /wp:tests/anchor-block -->'; 473 474 $post = inject_ignored_hooked_blocks_metadata_attributes( $changes, $request ); 475 $this->assertSame( 476 '<!-- wp:tests/anchor-block {"metadata":{"ignoredHookedBlocks":["tests/hooked-block"]}} -->Hello<!-- /wp:tests/anchor-block -->', 477 $post->post_content, 478 'The hooked block was not injected into the anchor block\'s ignoredHookedBlocks metadata.' 479 ); 480 } 393 481 }
Note: See TracChangeset
for help on using the changeset viewer.