Skip to content

Commit

Permalink
Remove bootstrap filter and do it inline (in the test)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed May 2, 2024
1 parent 5edf884 commit b641060
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
12 changes: 0 additions & 12 deletions phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,6 @@ function gutenberg_register_test_block_for_feature_selectors() {
}
tests_add_filter( 'init', 'gutenberg_register_test_block_for_feature_selectors' );

// Used in class-wp-theme-json-test.php to mock theme file URIs.
function gutenberg_tests_filter_theme_file_uri( $file ) {
// Tests can pass a file path with `example/` to return a dummy absolute theme file URI.
if ( strpos( $file, 'example/' ) ) {
$file_name = explode( 'example/', $file )[1];
return 'https://example.org/wp-content/themes/example-theme/example/' . $file_name;
}
// Default active theme URI.
return get_stylesheet_directory_uri() . '/' . $file;
}
tests_add_filter( 'theme_file_uri', 'gutenberg_tests_filter_theme_file_uri' );

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

Expand Down
13 changes: 13 additions & 0 deletions phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4880,7 +4880,20 @@ public function test_get_top_level_background_image_styles() {
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
);
$expected_styles = "body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }:where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){gap: 0.5em;}.is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}.is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}.is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}.is-layout-constrained > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}.is-layout-constrained > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}.is-layout-constrained > .aligncenter{margin-left: auto !important;margin-right: auto !important;}.is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}.is-layout-flex{flex-wrap: wrap;align-items: center;}.is-layout-flex > :is(*, div){margin: 0;}body .is-layout-grid{display: grid;}.is-layout-grid > :is(*, div){margin: 0;}html{min-height: calc(100% - var(--wp-admin--admin-bar--height, 0px));}:where(body){background-image: url('https://example.org/wp-content/themes/example-theme/example/img/image.png');}";

/*
* This filter callback normalizes the return value from `get_theme_file_uri`
* to guard against changes in test environments.
* The test suite otherwise returns full system dir path, e.g.,
* /wordpress-phpunit/includes/../data/themedir1/default/example/img/image.png
*/
$filter_theme_file_uri_callback = function ( $file ) {
return 'https://example.org/wp-content/themes/example-theme/example/' . explode( 'example/', $file )[1];
};
add_filter( 'theme_file_uri', $filter_theme_file_uri_callback );
$this->assertSame( $expected_styles, $theme_json->resolve_theme_file_uris()->get_stylesheet(), 'Styles returned from "::resolve_theme_file_uris()->get_stylesheet()" with resolved top-level theme background images do not match expected string' );
remove_filter( 'theme_file_uri', $filter_theme_file_uri_callback );

$this->assertSame( $expected_data, $theme_json->get_data(), 'Styles returned from "::get_data()" with resolved top-level theme background images do not match expected array' );
}

Expand Down

0 comments on commit b641060

Please sign in to comment.