Skip to content

Commit

Permalink
Improve maintainability of theme json class tests. (#62463)
Browse files Browse the repository at this point in the history
Co-authored-by: tellthemachines <[email protected]>
Co-authored-by: aaronrobertshaw <[email protected]>
Co-authored-by: andrewserong <[email protected]>
  • Loading branch information
4 people authored Jun 17, 2024
1 parent 48e81e9 commit 4011f4b
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 336 deletions.
85 changes: 0 additions & 85 deletions phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,91 +101,6 @@ function fail_if_died( $message ) {
// Enable the widget block editor.
tests_add_filter( 'gutenberg_use_widgets_block_editor', '__return_true' );

/**
* Register test block prior to theme.json generating metadata.
*
* This new block is used to test experimental selectors. It is registered
* via `tests_add_filter()` here during bootstrapping so that it occurs prior
* to theme.json generating block metadata. Once a core block, such as Image,
* uses feature level selectors we could remove this in favour of testing via
* the core block.
*/
function gutenberg_register_test_block_for_feature_selectors() {
WP_Block_Type_Registry::get_instance()->register(
'test/test',
array(
'api_version' => 3,
'attributes' => array(
'textColor' => array(
'type' => 'string',
),
'style' => array(
'type' => 'object',
),
),
'supports' => array(
'__experimentalBorder' => array(
'radius' => true,
'__experimentalSelector' => '.inner',
),
'color' => array(
'text' => true,
),
'spacing' => array(
'padding' => true,
'__experimentalSelector' => '.inner',
),
'typography' => array(
'fontSize' => true,
'__experimentalSelector' => '.sub-heading',
),
'__experimentalSelector' => '.wp-block-test, .wp-block-test__wrapper',
),
)
);

WP_Block_Type_Registry::get_instance()->register(
'my/block-with-selectors',
array(
'api_version' => 2,
'attributes' => array(
'textColor' => array(
'type' => 'string',
),
'style' => array(
'type' => 'object',
),
),
'supports' => array(
'__experimentalBorder' => array(
'radius' => true,
),
'color' => array(
'background' => true,
'text' => true,
),
'spacing' => array(
'padding' => true,
),
'typography' => array(
'fontSize' => true,
),
),
'selectors' => array(
'root' => '.custom-root-selector',
'border' => array(
'root' => '.custom-root-selector img',
),
'color' => array(
'text' => '.custom-root-selector > figcaption',
),
'typography' => '.custom-root-selector > figcaption',
),
)
);
}
tests_add_filter( 'init', 'gutenberg_register_test_block_for_feature_selectors' );

// Start up the WP testing environment.
require $_tests_dir . '/includes/bootstrap.php';

Expand Down
Loading

1 comment on commit 4011f4b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 4011f4b.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9542404660
📝 Reported issues:

Please sign in to comment.