Make WordPress Core

Changeset 58478


Ignore:
Timestamp:
06/24/2024 03:12:53 PM (5 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme/wpThemeJson.php

    r58466 r58478  
    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.' );
    5246 
    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.' );
    5249 
    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.' );
    5252 
    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.' );
    5255 
    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.' );
     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.' );
     5246
     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.' );
     5249
     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.' );
     5252
     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.' );
     5255
     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
     
    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' );
    5406 
    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' );
    5409 
    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(
     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' );
     5406
     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' );
     5409
     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' );
    5426 
    5427         $this->assertEquals(
     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' );
     5426
     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'],
     
    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
     
    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'],
     
    54725472        $actual = $func->invoke( null, 'custom', $selector );
    54735473
    5474         $this->assertEquals( $expected, $actual );
     5474        $this->assertSame( $expected, $actual );
    54755475    }
    54765476
     
    55855585        );
    55865586
    5587         $this->assertEquals( $expected, $actual );
     5587        $this->assertSame( $expected, $actual );
    55885588    }
    55895589
     
    56225622        $button_variations = $block_nodes[0]['variations'] ?? array();
    56235623
    5624         $this->assertEquals( array(), $button_variations );
     5624        $this->assertSame( array(), $button_variations );
    56255625    }
    56265626
     
    56665666        );
    56675667
    5668         $this->assertEquals( $expected, $button_variations );
     5668        $this->assertSame( $expected, $button_variations );
    56695669    }
    56705670}
Note: See TracChangeset for help on using the changeset viewer.