| | 356 | |
| | 357 | /** |
| | 358 | * Tests that block themes support a feature by default. |
| | 359 | * |
| | 360 | * @ticket 54597 |
| | 361 | * @dataProvider data_block_theme_has_default_support |
| | 362 | * |
| | 363 | * @covers ::_add_default_theme_supports |
| | 364 | * |
| | 365 | * @param array $support { |
| | 366 | * The feature to check. |
| | 367 | * |
| | 368 | * @type string $feature The feature to check. |
| | 369 | * @type string $sub_feature Optional. The sub-feature to check. |
| | 370 | * } |
| | 371 | */ |
| | 372 | public function test_block_theme_has_default_support( $support ) { |
| | 373 | $this->helper_requires_block_theme(); |
| | 374 | |
| | 375 | $support_data = array_values( $support ); |
| | 376 | $support_data_str = implode( ': ', $support_data ); |
| | 377 | |
| | 378 | // Remove existing support. |
| | 379 | if ( current_theme_supports( ...$support_data ) ) { |
| | 380 | remove_theme_support( ...$support_data ); |
| | 381 | } |
| | 382 | |
| | 383 | $this->assertFalse( |
| | 384 | current_theme_supports( ...$support_data ), |
| | 385 | "Could not remove support for $support_data_str." |
| | 386 | ); |
| | 387 | |
| | 388 | do_action( 'setup_theme' ); |
| | 389 | |
| | 390 | $this->assertTrue( |
| | 391 | current_theme_supports( ...$support_data ), |
| | 392 | "Does not have default support for $support_data_str." |
| | 393 | ); |
| | 394 | } |
| | 395 | |
| | 396 | /** |
| | 397 | * Data provider. |
| | 398 | * |
| | 399 | * @return array |
| | 400 | */ |
| | 401 | public function data_block_theme_has_default_support() { |
| | 402 | return array( |
| | 403 | 'post-thumbnails' => array( |
| | 404 | 'support' => array( |
| | 405 | 'feature' => 'post-thumbnails', |
| | 406 | ), |
| | 407 | ), |
| | 408 | 'responsive-embeds' => array( |
| | 409 | 'support' => array( |
| | 410 | 'feature' => 'responsive-embeds', |
| | 411 | ), |
| | 412 | ), |
| | 413 | 'editor-styles' => array( |
| | 414 | 'support' => array( |
| | 415 | 'feature' => 'editor-styles', |
| | 416 | ), |
| | 417 | ), |
| | 418 | 'html5: style' => array( |
| | 419 | 'support' => array( |
| | 420 | 'feature' => 'html5', |
| | 421 | 'sub_feature' => 'style', |
| | 422 | ), |
| | 423 | ), |
| | 424 | 'html5: script' => array( |
| | 425 | 'support' => array( |
| | 426 | 'feature' => 'html5', |
| | 427 | 'sub_feature' => 'script', |
| | 428 | ), |
| | 429 | ), |
| | 430 | 'automatic-feed-links' => array( |
| | 431 | 'support' => array( |
| | 432 | 'feature' => 'automatic-feed-links', |
| | 433 | ), |
| | 434 | ), |
| | 435 | ); |
| | 436 | } |
| | 437 | |
| | 438 | /** |
| | 439 | * Tests that block themes load separate core block assets by default. |
| | 440 | * |
| | 441 | * @ticket 54597 |
| | 442 | * |
| | 443 | * @covers WP_Hook::should_load_separate_core_block_assets |
| | 444 | */ |
| | 445 | public function test_block_theme_should_load_separate_core_block_assets_by_default() { |
| | 446 | $this->helper_requires_block_theme(); |
| | 447 | |
| | 448 | add_filter( 'should_load_separate_core_block_assets', '__return_false' ); |
| | 449 | |
| | 450 | $this->assertFalse( |
| | 451 | wp_should_load_separate_core_block_assets(), |
| | 452 | 'Could not disable loading separate core block assets.' |
| | 453 | ); |
| | 454 | |
| | 455 | do_action( 'setup_theme' ); |
| | 456 | |
| | 457 | $this->assertTrue( |
| | 458 | wp_should_load_separate_core_block_assets(), |
| | 459 | 'Block themes do not load separate core block assets by default.' |
| | 460 | ); |
| | 461 | } |
| | 462 | |
| | 463 | /** |
| | 464 | * Helper function to ensure that a block theme is available and active. |
| | 465 | */ |
| | 466 | private function helper_requires_block_theme() { |
| | 467 | // Make sure we're on a block theme. |
| | 468 | if ( ! wp_get_theme()->is_block_theme() ) { |
| | 469 | $block_theme = 'twentytwentytwo'; |
| | 470 | $block_theme_object = new WP_Theme( $block_theme, WP_CONTENT_DIR . '/themes' ); |
| | 471 | |
| | 472 | // Skip if the block theme is not available. |
| | 473 | if ( ! $block_theme_object->exists() ) { |
| | 474 | $this->markTestSkipped( "$block_theme must be available." ); |
| | 475 | } |
| | 476 | |
| | 477 | switch_theme( $block_theme ); |
| | 478 | |
| | 479 | // Skip if we could not switch to the block theme. |
| | 480 | if ( wp_get_theme()->stylesheet !== $block_theme ) { |
| | 481 | $this->markTestSkipped( "Could not switch to $block_theme." ); |
| | 482 | } |
| | 483 | } |
| | 484 | } |