Changeset 60951 for trunk/tests/phpunit/tests/blocks/wpBlock.php
- Timestamp:
- 10/16/2025 11:30:56 PM (12 months ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/blocks/wpBlock.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/blocks/wpBlock.php
r60930 r60951 544 544 'expected_script_modules' => array( 'static-view-script-module', 'static-child-view-script-module', 'dynamic-view-script-module' ), 545 545 ), 546 'admin_bar_assets_enqueued_in_block' => array( 547 'set_up' => static function () { 548 wp_enqueue_script( 'admin-bar' ); 549 wp_enqueue_style( 'admin-bar' ); 550 551 add_filter( 552 'render_block_core/static', 553 static function ( $content ) { 554 $processor = new WP_HTML_Tag_Processor( $content ); 555 $processor->next_tag(); 556 $processor->add_class( wp_script_is( 'admin-bar', 'enqueued' ) ? 'yes-admin-bar-script-enqueued' : 'not-admin-bar-script-enqueued' ); 557 $processor->add_class( wp_style_is( 'admin-bar', 'enqueued' ) ? 'yes-admin-bar-style-enqueued' : 'not-admin-bar-style-enqueued' ); 558 return $processor->get_updated_html(); 559 }, 560 10, 561 3 562 ); 563 }, 564 'block_markup' => '<!-- wp:static --><div class="static"></div><!-- /wp:static -->', 565 'expected_rendered_block' => ' 566 <div class="static yes-admin-bar-script-enqueued yes-admin-bar-style-enqueued"></div> 567 ', 568 'expected_styles' => array( 'static-view-style', 'admin-bar' ), 569 'expected_scripts' => array( 'static-view-script', 'admin-bar' ), 570 'expected_script_modules' => array( 'static-view-script-module' ), 571 ), 572 'enqueues_in_wp_head_block' => array( 573 'set_up' => static function () { 574 remove_all_actions( 'wp_head' ); 575 remove_all_actions( 'wp_enqueue_scripts' ); 576 577 add_action( 'wp_head', 'wp_enqueue_scripts', 1 ); 578 add_action( 'wp_head', 'wp_print_styles', 8 ); 579 add_action( 'wp_head', 'wp_print_head_scripts', 9 ); 580 remove_action( 'wp_print_styles', 'print_emoji_styles' ); 581 582 add_action( 583 'wp_enqueue_scripts', 584 static function () { 585 wp_enqueue_script( 'for-footer', '/footer.js', array(), null, array( 'in_footer' => true ) ); 586 } 587 ); 588 add_action( 589 'wp_head', 590 static function () { 591 wp_enqueue_style( 'for-footer', '/footer.css', array(), null ); 592 }, 593 10000 594 ); 595 }, 596 'block_markup' => '<!-- wp:wp-head /-->', 597 'expected_rendered_block' => '', 598 'expected_styles' => array( 'for-footer' ), 599 'expected_scripts' => array( 'for-footer' ), 600 'expected_script_modules' => array(), 601 ), 546 602 ); 547 603 } … … 563 619 $set_up(); 564 620 } 621 622 $this->registry->register( 623 'core/wp-head', 624 array( 625 'render_callback' => static function () { 626 return get_echo( 'wp_head' ); 627 }, 628 ) 629 ); 630 565 631 wp_register_style( 'static-view-style', home_url( '/static-view-style.css' ) ); 566 632 wp_register_script( 'static-view-script', home_url( '/static-view-script.js' ) ); … … 609 675 $rendered_block = $block->render(); 610 676 677 $this->assertSameSets( $expected_styles, wp_styles()->queue, 'Enqueued styles do not meet expectations' ); 678 $this->assertSameSets( $expected_scripts, wp_scripts()->queue, 'Enqueued scripts do not meet expectations' ); 679 $this->assertSameSets( $expected_script_modules, wp_script_modules()->get_queue(), 'Enqueued script modules do not meet expectations' ); 680 611 681 $this->assertEqualHTML( 612 682 $expected_rendered_block, … … 615 685 "Rendered block does not contain expected HTML:\n$rendered_block" 616 686 ); 617 618 remove_action( 'wp_print_styles', 'print_emoji_styles' );619 620 $actual_styles = array();621 $printed_styles = get_echo( 'wp_print_styles' );622 $processor = new WP_HTML_Tag_Processor( $printed_styles );623 while ( $processor->next_tag( array( 'tag_name' => 'LINK' ) ) ) {624 if ( 1 === preg_match( '/^(.+)-css$/', $processor->get_attribute( 'id' ), $matches ) ) {625 $actual_styles[] = $matches[1];626 }627 }628 $this->assertSameSets( $expected_styles, $actual_styles, 'Enqueued styles do not meet expectations' );629 630 $actual_scripts = array();631 $printed_scripts = get_echo( 'wp_print_scripts' );632 $processor = new WP_HTML_Tag_Processor( $printed_scripts );633 while ( $processor->next_tag( array( 'tag_name' => 'SCRIPT' ) ) ) {634 if ( 1 === preg_match( '/^(.+)-js$/', $processor->get_attribute( 'id' ), $matches ) ) {635 $actual_scripts[] = $matches[1];636 }637 }638 $this->assertSameSets( $expected_scripts, $actual_scripts, 'Enqueued scripts do not meet expectations' );639 640 $actual_script_modules = array();641 $printed_script_modules = get_echo( array( wp_script_modules(), 'print_enqueued_script_modules' ) );642 $processor = new WP_HTML_Tag_Processor( $printed_script_modules );643 while ( $processor->next_tag( array( 'tag_name' => 'SCRIPT' ) ) ) {644 if ( 1 === preg_match( '/^(.+)-js-module$/', $processor->get_attribute( 'id' ), $matches ) ) {645 $actual_script_modules[] = $matches[1];646 }647 }648 $this->assertSameSets( $expected_script_modules, $actual_script_modules, 'Enqueued script modules do not meet expectations' );649 687 } 650 688
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)