Skip to content

Commit 40bb25c

Browse files
committed
Improve block styles check
1 parent 60ec9b7 commit 40bb25c

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

phpunit/class-wp-theme-json-resolver-test.php

+16-4
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,10 @@ public function test_get_merged_data_returns_origin_default() {
415415
$settings = $theme_json->get_settings();
416416
$styles = $theme_json->get_styles_block_nodes();
417417
$this->assertTrue( isset( $settings['color']['palette']['default'] ), 'core palette is present' );
418-
$this->assertFalse( isset( $styles[4] ) , 'block styles are not present' );
418+
$block_styles = array_filter( $styles, function( $element ) {
419+
return isset( $element['name'] ) && $element['name'] === 'my/block-with-styles';
420+
} );
421+
$this->assertTrue( count( $block_styles ) === 0 , 'block styles are not present' );
419422
$this->assertFalse( isset( $settings['color']['palette']['theme'] ), 'theme palette is not present' );
420423
$this->assertFalse( isset( $settings['color']['palette']['custom'] ), 'user palette is not present' );
421424

@@ -439,7 +442,10 @@ public function test_get_merged_data_returns_origin_blocks() {
439442
$settings = $theme_json->get_settings();
440443
$styles = $theme_json->get_styles_block_nodes();
441444
$this->assertTrue( isset( $settings['color']['palette']['default'] ), 'core palette is present' );
442-
$this->assertSame( $styles[4]['name'], 'my/block-with-styles' , 'block styles are present' );
445+
$block_styles = array_filter( $styles, function( $element ) {
446+
return isset( $element['name'] ) && $element['name'] === 'my/block-with-styles';
447+
} );
448+
$this->assertTrue( count( $block_styles ) === 1 , 'block styles are present' );
443449
$this->assertFalse( isset( $settings['color']['palette']['theme'] ), 'theme palette is not present' );
444450
$this->assertFalse( isset( $settings['color']['palette']['custom'] ), 'user palette is not present' );
445451

@@ -463,7 +469,10 @@ public function test_get_merged_data_returns_origin_theme() {
463469
$settings = $theme_json->get_settings();
464470
$styles = $theme_json->get_styles_block_nodes();
465471
$this->assertTrue( isset( $settings['color']['palette']['default'] ), 'core palette is present' );
466-
$this->assertSame( $styles[4]['name'], 'my/block-with-styles' , 'block styles are present' );
472+
$block_styles = array_filter( $styles, function( $element ) {
473+
return isset( $element['name'] ) && $element['name'] === 'my/block-with-styles';
474+
} );
475+
$this->assertTrue( count( $block_styles ) === 1 , 'block styles are present' );
467476
$this->assertTrue( isset( $settings['color']['palette']['theme'] ), 'theme palette is present' );
468477
$this->assertFalse( isset( $settings['color']['palette']['custom'] ), 'user palette is not present' );
469478

@@ -487,7 +496,10 @@ public function test_get_merged_data_returns_origin_custom() {
487496
$settings = $theme_json->get_settings();
488497
$styles = $theme_json->get_styles_block_nodes();
489498
$this->assertTrue( isset( $settings['color']['palette']['default'] ), 'core palette is present' );
490-
$this->assertSame( $styles[4]['name'], 'my/block-with-styles' , 'block styles are present' );
499+
$block_styles = array_filter( $styles, function( $element ) {
500+
return isset( $element['name'] ) && $element['name'] === 'my/block-with-styles';
501+
} );
502+
$this->assertTrue( count( $block_styles ) === 1 , 'block styles are present' );
491503
$this->assertTrue( isset( $settings['color']['palette']['theme'] ), 'theme palette is present' );
492504
$this->assertTrue( isset( $settings['color']['palette']['custom'] ), 'user palette is present' );
493505

0 commit comments

Comments
 (0)