Skip to content

Commit 86836a7

Browse files
committed
Fix test_block_registers_with_metadata_fixture running in isolation
1 parent 86d45e9 commit 86836a7

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

tests/phpunit/tests/blocks/register.php

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
*/
1111
class Tests_Blocks_Register extends WP_UnitTestCase {
1212

13+
/**
14+
* @var WP_Scripts|null
15+
*/
16+
protected $original_wp_scripts;
17+
18+
/**
19+
* @var WP_Styles|null
20+
*/
21+
protected $original_wp_styles;
22+
1323
/**
1424
* ID for a test post.
1525
*
@@ -46,6 +56,21 @@ public static function wpTearDownAfterClass() {
4656
*/
4757
public function render_stub() {}
4858

59+
/**
60+
* Set up.
61+
*/
62+
public function set_up() {
63+
parent::set_up();
64+
65+
global $wp_scripts, $wp_styles;
66+
$this->original_wp_scripts = $wp_scripts;
67+
$this->original_wp_styles = $wp_styles;
68+
$wp_scripts = null;
69+
$wp_styles = null;
70+
wp_scripts();
71+
wp_styles();
72+
}
73+
4974
/**
5075
* Tear down after each test.
5176
*
@@ -67,6 +92,10 @@ public function tear_down() {
6792
}
6893
}
6994

95+
global $wp_scripts, $wp_styles;
96+
$wp_scripts = $this->original_wp_scripts;
97+
$wp_styles = $this->original_wp_styles;
98+
7099
parent::tear_down();
71100
}
72101

@@ -1003,6 +1032,18 @@ public function test_block_registers_with_metadata_fixture() {
10031032
DIR_TESTDATA . '/blocks/notice'
10041033
);
10051034

1035+
// Register the styles not included in the metadata above.
1036+
$metadata = array(
1037+
'file' => DIR_TESTDATA . '/blocks/notice/block.json',
1038+
'name' => 'tests/notice',
1039+
'style' => 'file:./block.css',
1040+
'viewStyle' => 'file:./block-view.css',
1041+
);
1042+
$this->assertSame( 'tests-notice-style', register_block_style_handle( $metadata, 'style' ) );
1043+
$this->assertSame( 'tests-notice-view-style', register_block_style_handle( $metadata, 'viewStyle' ) );
1044+
$this->assertTrue( wp_style_is( 'tests-notice-style', 'registered' ), 'Expected "tests-notice-style" style to be registered.' );
1045+
$this->assertTrue( wp_style_is( 'tests-notice-view-style', 'registered' ), 'Expected "tests-notice-view-style" style to be registered.' );
1046+
10061047
$this->assertInstanceOf( 'WP_Block_Type', $result );
10071048
$this->assertSame( 2, $result->api_version );
10081049
$this->assertSame( 'tests/notice', $result->name );
@@ -1121,13 +1162,13 @@ public function test_block_registers_with_metadata_fixture() {
11211162
// @ticket 50328
11221163
$this->assertSame(
11231164
wp_normalize_path( realpath( DIR_TESTDATA . '/blocks/notice/block.css' ) ),
1124-
wp_normalize_path( wp_styles()->get_data( 'tests-test-block-style', 'path' ) )
1165+
wp_normalize_path( wp_styles()->get_data( 'tests-notice-style', 'path' ) )
11251166
);
11261167

11271168
// @ticket 59673
11281169
$this->assertSame(
11291170
wp_normalize_path( realpath( DIR_TESTDATA . '/blocks/notice/block-view.css' ) ),
1130-
wp_normalize_path( wp_styles()->get_data( 'tests-test-block-view-style', 'path' ) ),
1171+
wp_normalize_path( wp_styles()->get_data( 'tests-notice-view-style', 'path' ) ),
11311172
'viewStyle asset path is not correct'
11321173
);
11331174

0 commit comments

Comments
 (0)