Skip to content

Commit 8afc34a

Browse files
Tests: Use assertSame() in WP_Theme_JSON tests.
This ensures that not only the return values match the expected results, but also that their type is the same. Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable. Follow-up to [55959], [55986], [57547], [57716], [58244], [58422]. See #60706. git-svn-id: https://develop.svn.wordpress.org/trunk@58478 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 9e94297 commit 8afc34a

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

tests/phpunit/tests/theme/wpThemeJson.php

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5241,20 +5241,20 @@ public function test_internal_syntax_is_converted_to_css_variables() {
52415241
);
52425242
$styles = $result->get_raw_data()['styles'];
52435243

5244-
$this->assertEquals( 'var(--wp--preset--color--primary)', $styles['color']['background'], 'Top level: Assert the originally correct values are still correct.' );
5245-
$this->assertEquals( 'var(--wp--preset--color--secondary)', $styles['color']['text'], 'Top level: Assert the originally correct values are still correct.' );
5244+
$this->assertSame( 'var(--wp--preset--color--primary)', $styles['color']['background'], 'Top level: Assert the originally correct values are still correct.' );
5245+
$this->assertSame( 'var(--wp--preset--color--secondary)', $styles['color']['text'], 'Top level: Assert the originally correct values are still correct.' );
52465246

5247-
$this->assertEquals( 'var(--wp--preset--color--pri)', $styles['elements']['link']['color']['background'], 'Element top level: Assert the originally correct values are still correct.' );
5248-
$this->assertEquals( 'var(--wp--preset--color--sec)', $styles['elements']['link']['color']['text'], 'Element top level: Assert the originally correct values are still correct.' );
5247+
$this->assertSame( 'var(--wp--preset--color--pri)', $styles['elements']['link']['color']['background'], 'Element top level: Assert the originally correct values are still correct.' );
5248+
$this->assertSame( 'var(--wp--preset--color--sec)', $styles['elements']['link']['color']['text'], 'Element top level: Assert the originally correct values are still correct.' );
52495249

5250-
$this->assertEquals( 'var(--wp--preset--font-size--small)', $styles['blocks']['core/post-terms']['typography']['fontSize'], 'Top block level: Assert the originally correct values are still correct.' );
5251-
$this->assertEquals( 'var(--wp--preset--color--secondary)', $styles['blocks']['core/post-terms']['color']['background'], 'Top block level: Assert the internal variables are convert to CSS custom variables.' );
5250+
$this->assertSame( 'var(--wp--preset--font-size--small)', $styles['blocks']['core/post-terms']['typography']['fontSize'], 'Top block level: Assert the originally correct values are still correct.' );
5251+
$this->assertSame( 'var(--wp--preset--color--secondary)', $styles['blocks']['core/post-terms']['color']['background'], 'Top block level: Assert the internal variables are convert to CSS custom variables.' );
52525252

5253-
$this->assertEquals( 'var(--wp--preset--color--p)', $styles['blocks']['core/navigation']['elements']['link']['color']['background'], 'Elements block level: Assert the originally correct values are still correct.' );
5254-
$this->assertEquals( 'var(--wp--preset--color--s)', $styles['blocks']['core/navigation']['elements']['link']['color']['text'], 'Elements block level: Assert the originally correct values are still correct.' );
5253+
$this->assertSame( 'var(--wp--preset--color--p)', $styles['blocks']['core/navigation']['elements']['link']['color']['background'], 'Elements block level: Assert the originally correct values are still correct.' );
5254+
$this->assertSame( 'var(--wp--preset--color--s)', $styles['blocks']['core/navigation']['elements']['link']['color']['text'], 'Elements block level: Assert the originally correct values are still correct.' );
52555255

5256-
$this->assertEquals( 'var(--wp--preset--font-size--s)', $styles['blocks']['core/quote']['variations']['plain']['typography']['fontSize'], 'Style variations: Assert the originally correct values are still correct.' );
5257-
$this->assertEquals( 'var(--wp--preset--color--s)', $styles['blocks']['core/quote']['variations']['plain']['color']['background'], 'Style variations: Assert the internal variables are convert to CSS custom variables.' );
5256+
$this->assertSame( 'var(--wp--preset--font-size--s)', $styles['blocks']['core/quote']['variations']['plain']['typography']['fontSize'], 'Style variations: Assert the originally correct values are still correct.' );
5257+
$this->assertSame( 'var(--wp--preset--color--s)', $styles['blocks']['core/quote']['variations']['plain']['color']['background'], 'Style variations: Assert the internal variables are convert to CSS custom variables.' );
52585258
}
52595259

52605260
/**
@@ -5401,42 +5401,42 @@ public function test_resolve_variables() {
54015401

54025402
$styles = $theme_json::resolve_variables( $theme_json )->get_raw_data()['styles'];
54035403

5404-
$this->assertEquals( $primary_color, $styles['color']['background'], 'Top level: Assert values are converted' );
5405-
$this->assertEquals( $raw_color_value, $styles['color']['text'], 'Top level: Assert raw values stay intact' );
5404+
$this->assertSame( $primary_color, $styles['color']['background'], 'Top level: Assert values are converted' );
5405+
$this->assertSame( $raw_color_value, $styles['color']['text'], 'Top level: Assert raw values stay intact' );
54065406

5407-
$this->assertEquals( $contrast_color, $styles['elements']['button']['color']['text'], 'Elements: color' );
5408-
$this->assertEquals( $small_font, $styles['elements']['button']['typography']['fontSize'], 'Elements: font-size' );
5407+
$this->assertSame( $contrast_color, $styles['elements']['button']['color']['text'], 'Elements: color' );
5408+
$this->assertSame( $small_font, $styles['elements']['button']['typography']['fontSize'], 'Elements: font-size' );
54095409

5410-
$this->assertEquals( $large_font, $styles['blocks']['core/quote']['typography']['fontSize'], 'Blocks: font-size' );
5411-
$this->assertEquals( $primary_color, $styles['blocks']['core/quote']['color']['background'], 'Blocks: color' );
5412-
$this->assertEquals( $raw_color_value, $styles['blocks']['core/post-terms']['color']['background'], 'Blocks: Raw color value stays intact' );
5413-
$this->assertEquals( $small_font, $styles['blocks']['core/post-terms']['typography']['fontSize'], 'Block core/post-terms: font-size' );
5414-
$this->assertEquals(
5410+
$this->assertSame( $large_font, $styles['blocks']['core/quote']['typography']['fontSize'], 'Blocks: font-size' );
5411+
$this->assertSame( $primary_color, $styles['blocks']['core/quote']['color']['background'], 'Blocks: color' );
5412+
$this->assertSame( $raw_color_value, $styles['blocks']['core/post-terms']['color']['background'], 'Blocks: Raw color value stays intact' );
5413+
$this->assertSame( $small_font, $styles['blocks']['core/post-terms']['typography']['fontSize'], 'Block core/post-terms: font-size' );
5414+
$this->assertSame(
54155415
"linear-gradient(90deg, $primary_color 0%, $secondary_color 35%, var(--wp--undefined--color--secondary) 100%)",
54165416
$styles['blocks']['core/more']['color']['background'],
54175417
'Blocks: multiple colors and undefined color'
54185418
);
5419-
$this->assertEquals( 'var(--undefined--font-size--small)', $styles['blocks']['core/more']['typography']['fontSize'], 'Blocks: undefined font-size ' );
5420-
$this->assertEquals( "calc($small_font + 20px)", $styles['blocks']['core/comment-content']['typography']['fontSize'], 'Blocks: font-size in random place' );
5421-
$this->assertEquals( $primary_color, $styles['blocks']['core/comment-content']['color']['text'], 'Blocks: text color with fallback' );
5422-
$this->assertEquals( $primary_color, $styles['blocks']['core/comment-content']['color']['background'], 'Blocks: background color with var as fallback' );
5423-
$this->assertEquals( $primary_color, $styles['blocks']['core/navigation']['elements']['link']['color']['background'], 'Block element: background color' );
5424-
$this->assertEquals( $secondary_color, $styles['blocks']['core/navigation']['elements']['link']['color']['text'], 'Block element: text color' );
5425-
$this->assertEquals( $large_font, $styles['blocks']['core/navigation']['elements']['link']['typography']['fontSize'], 'Block element: font-size' );
5419+
$this->assertSame( 'var(--undefined--font-size--small)', $styles['blocks']['core/more']['typography']['fontSize'], 'Blocks: undefined font-size ' );
5420+
$this->assertSame( "calc($small_font + 20px)", $styles['blocks']['core/comment-content']['typography']['fontSize'], 'Blocks: font-size in random place' );
5421+
$this->assertSame( $primary_color, $styles['blocks']['core/comment-content']['color']['text'], 'Blocks: text color with fallback' );
5422+
$this->assertSame( $primary_color, $styles['blocks']['core/comment-content']['color']['background'], 'Blocks: background color with var as fallback' );
5423+
$this->assertSame( $primary_color, $styles['blocks']['core/navigation']['elements']['link']['color']['background'], 'Block element: background color' );
5424+
$this->assertSame( $secondary_color, $styles['blocks']['core/navigation']['elements']['link']['color']['text'], 'Block element: text color' );
5425+
$this->assertSame( $large_font, $styles['blocks']['core/navigation']['elements']['link']['typography']['fontSize'], 'Block element: font-size' );
54265426

5427-
$this->assertEquals(
5427+
$this->assertSame(
54285428
"var(--undefined--color--primary, $small_font)",
54295429
$styles['blocks']['core/comments']['color']['text'],
54305430
'Blocks: text color with undefined var and fallback'
54315431
);
5432-
$this->assertEquals(
5432+
$this->assertSame(
54335433
$primary_color,
54345434
$styles['blocks']['core/comments']['color']['background'],
54355435
'Blocks: background color with variable and undefined fallback'
54365436
);
54375437

5438-
$this->assertEquals( $small_font, $styles['blocks']['core/quote']['variations']['plain']['typography']['fontSize'], 'Block variations: font-size' );
5439-
$this->assertEquals( $secondary_color, $styles['blocks']['core/quote']['variations']['plain']['color']['background'], 'Block variations: color' );
5438+
$this->assertSame( $small_font, $styles['blocks']['core/quote']['variations']['plain']['typography']['fontSize'], 'Block variations: font-size' );
5439+
$this->assertSame( $secondary_color, $styles['blocks']['core/quote']['variations']['plain']['color']['background'], 'Block variations: color' );
54405440
/*
54415441
* As with wp_get_global_styles(), WP_Theme_JSON::resolve_variables may be called with merged data from
54425442
* WP_Theme_JSON_Resolver. WP_Theme_JSON_Resolver::get_block_data() sets blockGap for supported blocks to `null` if the value is not defined.
@@ -5445,7 +5445,7 @@ public function test_resolve_variables() {
54455445
$styles['blocks']['core/post-template']['spacing']['blockGap'],
54465446
'Blocks: Post Template spacing.blockGap should be null'
54475447
);
5448-
$this->assertEquals(
5448+
$this->assertSame(
54495449
$spacing,
54505450
$styles['blocks']['core/columns']['spacing']['blockGap'],
54515451
'Blocks: Columns spacing.blockGap should match'
@@ -5471,7 +5471,7 @@ public function test_get_block_style_variation_selector( $selector, $expected )
54715471

54725472
$actual = $func->invoke( null, 'custom', $selector );
54735473

5474-
$this->assertEquals( $expected, $actual );
5474+
$this->assertSame( $expected, $actual );
54755475
}
54765476

54775477
/**
@@ -5584,7 +5584,7 @@ public function test_scope_style_node_selectors() {
55845584
),
55855585
);
55865586

5587-
$this->assertEquals( $expected, $actual );
5587+
$this->assertSame( $expected, $actual );
55885588
}
55895589

55905590
/**
@@ -5621,7 +5621,7 @@ public function test_opt_out_of_block_style_variations_by_default() {
56215621
$block_nodes = $func->invoke( null, $theme_json, $selectors );
56225622
$button_variations = $block_nodes[0]['variations'] ?? array();
56235623

5624-
$this->assertEquals( array(), $button_variations );
5624+
$this->assertSame( array(), $button_variations );
56255625
}
56265626

56275627
/**
@@ -5665,6 +5665,6 @@ public function test_opt_in_to_block_style_variations() {
56655665
),
56665666
);
56675667

5668-
$this->assertEquals( $expected, $button_variations );
5668+
$this->assertSame( $expected, $button_variations );
56695669
}
56705670
}

0 commit comments

Comments
 (0)