Changeset 61469 for trunk/tests/phpunit/tests/block-template.php
- Timestamp:
- 01/11/2026 06:34:57 AM (2 months ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/block-template.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/block-template.php
r61090 r61469 313 313 314 314 /** 315 * Tests that `get_the_block_template_html()` adds a skip link when a MAIN element is present. 316 * 317 * @ticket 64361 318 * @covers ::get_the_block_template_html 319 */ 320 public function test_get_the_block_template_html_adds_skip_link_when_main_present() { 321 global $_wp_current_template_id, $_wp_current_template_content; 322 323 $_wp_current_template_id = get_stylesheet() . '//index'; 324 $_wp_current_template_content = '<main>Content</main>'; 325 326 $processor = new WP_HTML_Tag_Processor( get_the_block_template_html() ); 327 $this->assertTrue( 328 $processor->next_tag( 329 array( 330 'tag_name' => 'A', 331 'class_name' => 'skip-link', 332 ) 333 ), 334 'Expected skip link was not added to the block template HTML.' 335 ); 336 $this->assertSame( 'wp-skip-link', $processor->get_attribute( 'id' ), 'Unexpected ID on skip link.' ); 337 $this->assertTrue( $processor->has_class( 'screen-reader-text' ), 'Expected "screen-reader-text" class on skip link.' ); 338 } 339 340 /** 341 * Tests that `get_the_block_template_html()` does not add a skip link when the skip-link action is unhooked. 342 * 343 * @ticket 64361 344 * @covers ::get_the_block_template_html 345 * 346 * @dataProvider data_provider_skip_link_actions 347 */ 348 public function test_get_the_block_template_html_does_not_add_skip_link_when_action_unhooked( string $action, string $callback ) { 349 global $_wp_current_template_id, $_wp_current_template_content; 350 351 $_wp_current_template_id = get_stylesheet() . '//index'; 352 $_wp_current_template_content = '<main>Content</main>'; 353 354 remove_action( $action, $callback ); 355 356 $processor = new WP_HTML_Tag_Processor( get_the_block_template_html() ); 357 $this->assertFalse( 358 $processor->next_tag( 359 array( 360 'tag_name' => 'A', 361 'class_name' => 'skip-link', 362 ) 363 ), 364 'Unexpected skip link was added to the block template HTML when the action was unhooked.' 365 ); 366 } 367 368 /** 369 * Data provider for test_get_the_block_template_html_does_not_add_skip_link_when_action_unhooked. 370 * 371 * @return array<string, array<string, string>> 372 */ 373 public function data_provider_skip_link_actions(): array { 374 return array( 375 'the_block_template_skip_link' => array( 376 'action' => 'wp_footer', 377 'callback' => 'the_block_template_skip_link', 378 ), 379 'wp_enqueue_block_template_skip_link' => array( 380 'action' => 'wp_enqueue_scripts', 381 'callback' => 'wp_enqueue_block_template_skip_link', 382 ), 383 ); 384 } 385 386 /** 315 387 * @ticket 58319 316 388 *
Note: See TracChangeset
for help on using the changeset viewer.