WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (17 months ago)
Author:
SergeyBiryukov
Message:

Tests: First pass at using assertSame() instead of assertEquals() in most of the unit 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.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

File:
1 edited

Legend:

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

    r47921 r48937  
    4747        $themes = get_themes();
    4848        $theme  = get_theme( 'WordPress Default' );
    49         $this->assertEquals( $themes['WordPress Default'], $theme );
     49        $this->assertSame( $themes['WordPress Default'], $theme );
    5050
    5151        $this->assertFalse( empty( $theme ) );
     
    5353        // echo gen_tests_array( 'theme', $theme );
    5454
    55         $this->assertEquals( 'WordPress Default', $theme['Name'] );
    56         $this->assertEquals( 'WordPress Default', $theme['Title'] );
    57         $this->assertEquals( 'The default WordPress theme based on the famous <a href="http://binarybonsai.com/kubrick/">Kubrick</a>.', $theme['Description'] );
    58         $this->assertEquals( '<a href="http://binarybonsai.com/">Michael Heilemann</a>', $theme['Author'] );
    59         $this->assertEquals( '1.6', $theme['Version'] );
    60         $this->assertEquals( 'default', $theme['Template'] );
    61         $this->assertEquals( 'default', $theme['Stylesheet'] );
     55        $this->assertSame( 'WordPress Default', $theme['Name'] );
     56        $this->assertSame( 'WordPress Default', $theme['Title'] );
     57        $this->assertSame( 'The default WordPress theme based on the famous <a href="http://binarybonsai.com/kubrick/">Kubrick</a>.', $theme['Description'] );
     58        $this->assertSame( '<a href="http://binarybonsai.com/">Michael Heilemann</a>', $theme['Author'] );
     59        $this->assertSame( '1.6', $theme['Version'] );
     60        $this->assertSame( 'default', $theme['Template'] );
     61        $this->assertSame( 'default', $theme['Stylesheet'] );
    6262
    6363        $this->assertContains( $this->theme_root . '/default/functions.php', $theme['Template Files'] );
     
    6565        $this->assertContains( $this->theme_root . '/default/style.css', $theme['Stylesheet Files'] );
    6666
    67         $this->assertEquals( $this->theme_root . '/default', $theme['Template Dir'] );
    68         $this->assertEquals( $this->theme_root . '/default', $theme['Stylesheet Dir'] );
    69         $this->assertEquals( 'publish', $theme['Status'] );
    70         $this->assertEquals( '', $theme['Parent Theme'] );
     67        $this->assertSame( $this->theme_root . '/default', $theme['Template Dir'] );
     68        $this->assertSame( $this->theme_root . '/default', $theme['Stylesheet Dir'] );
     69        $this->assertSame( 'publish', $theme['Status'] );
     70        $this->assertSame( '', $theme['Parent Theme'] );
    7171    }
    7272
     
    8282        // echo gen_tests_array( 'theme', $theme );
    8383
    84         $this->assertEquals( 'Sandbox', $theme['Name'] );
    85         $this->assertEquals( 'Sandbox', $theme['Title'] );
    86         $this->assertEquals( 'A theme with powerful, semantic CSS selectors and the ability to add new skins.', $theme['Description'] );
    87         $this->assertEquals( '<a href="http://andy.wordpress.com/">Andy Skelton</a> &amp; <a href="http://www.plaintxt.org/">Scott Allan Wallick</a>', $theme['Author'] );
    88         $this->assertEquals( '0.6.1-wpcom', $theme['Version'] );
    89         $this->assertEquals( 'sandbox', $theme['Template'] );
    90         $this->assertEquals( 'sandbox', $theme['Stylesheet'] );
     84        $this->assertSame( 'Sandbox', $theme['Name'] );
     85        $this->assertSame( 'Sandbox', $theme['Title'] );
     86        $this->assertSame( 'A theme with powerful, semantic CSS selectors and the ability to add new skins.', $theme['Description'] );
     87        $this->assertSame( '<a href="http://andy.wordpress.com/">Andy Skelton</a> &amp; <a href="http://www.plaintxt.org/">Scott Allan Wallick</a>', $theme['Author'] );
     88        $this->assertSame( '0.6.1-wpcom', $theme['Version'] );
     89        $this->assertSame( 'sandbox', $theme['Template'] );
     90        $this->assertSame( 'sandbox', $theme['Stylesheet'] );
    9191
    9292        $template_files = $theme['Template Files'];
    9393
    94         $this->assertEquals( $this->theme_root . '/sandbox/functions.php', reset( $template_files ) );
    95         $this->assertEquals( $this->theme_root . '/sandbox/index.php', next( $template_files ) );
     94        $this->assertSame( $this->theme_root . '/sandbox/functions.php', reset( $template_files ) );
     95        $this->assertSame( $this->theme_root . '/sandbox/index.php', next( $template_files ) );
    9696
    9797        $stylesheet_files = $theme['Stylesheet Files'];
    9898
    99         $this->assertEquals( $this->theme_root . '/sandbox/style.css', reset( $stylesheet_files ) );
    100 
    101         $this->assertEquals( $this->theme_root . '/sandbox', $theme['Template Dir'] );
    102         $this->assertEquals( $this->theme_root . '/sandbox', $theme['Stylesheet Dir'] );
    103         $this->assertEquals( 'publish', $theme['Status'] );
    104         $this->assertEquals( '', $theme['Parent Theme'] );
     99        $this->assertSame( $this->theme_root . '/sandbox/style.css', reset( $stylesheet_files ) );
     100
     101        $this->assertSame( $this->theme_root . '/sandbox', $theme['Template Dir'] );
     102        $this->assertSame( $this->theme_root . '/sandbox', $theme['Stylesheet Dir'] );
     103        $this->assertSame( 'publish', $theme['Status'] );
     104        $this->assertSame( '', $theme['Parent Theme'] );
    105105
    106106    }
     
    119119        // echo gen_tests_array( 'theme', $theme );
    120120
    121         $this->assertEquals( 'Stylesheet Only', $theme['Name'] );
    122         $this->assertEquals( 'Stylesheet Only', $theme['Title'] );
    123         $this->assertEquals( 'A three-column widget-ready theme in dark blue.', $theme['Description'] );
    124         $this->assertEquals( '<a href="http://www.example.com/">Henry Crun</a>', $theme['Author'] );
    125         $this->assertEquals( '1.0', $theme['Version'] );
    126         $this->assertEquals( 'sandbox', $theme['Template'] );
    127         $this->assertEquals( 'stylesheetonly', $theme['Stylesheet'] );
     121        $this->assertSame( 'Stylesheet Only', $theme['Name'] );
     122        $this->assertSame( 'Stylesheet Only', $theme['Title'] );
     123        $this->assertSame( 'A three-column widget-ready theme in dark blue.', $theme['Description'] );
     124        $this->assertSame( '<a href="http://www.example.com/">Henry Crun</a>', $theme['Author'] );
     125        $this->assertSame( '1.0', $theme['Version'] );
     126        $this->assertSame( 'sandbox', $theme['Template'] );
     127        $this->assertSame( 'stylesheetonly', $theme['Stylesheet'] );
    128128        $this->assertContains( $this->theme_root . '/sandbox/functions.php', $theme['Template Files'] );
    129129        $this->assertContains( $this->theme_root . '/sandbox/index.php', $theme['Template Files'] );
     
    131131        $this->assertContains( $this->theme_root . '/stylesheetonly/style.css', $theme['Stylesheet Files'] );
    132132
    133         $this->assertEquals( $this->theme_root . '/sandbox', $theme['Template Dir'] );
    134         $this->assertEquals( $this->theme_root . '/stylesheetonly', $theme['Stylesheet Dir'] );
    135         $this->assertEquals( 'publish', $theme['Status'] );
    136         $this->assertEquals( 'Sandbox', $theme['Parent Theme'] );
     133        $this->assertSame( $this->theme_root . '/sandbox', $theme['Template Dir'] );
     134        $this->assertSame( $this->theme_root . '/stylesheetonly', $theme['Stylesheet Dir'] );
     135        $this->assertSame( 'publish', $theme['Status'] );
     136        $this->assertSame( 'Sandbox', $theme['Parent Theme'] );
    137137
    138138    }
     
    170170        sort( $expected );
    171171
    172         $this->assertEquals( $expected, $theme_names );
     172        $this->assertSame( $expected, $theme_names );
    173173    }
    174174
     
    193193        );
    194194
    195         $this->assertEquals( $expected, get_broken_themes() );
     195        $this->assertSame( $expected, get_broken_themes() );
    196196    }
    197197
     
    220220        $theme_data = get_theme_data( DIR_TESTDATA . '/themedir1/theme1/style.css' );
    221221
    222         $this->assertEquals( 'My Theme', $theme_data['Name'] );
    223         $this->assertEquals( 'http://example.org/', $theme_data['URI'] );
    224         $this->assertEquals( 'An example theme', $theme_data['Description'] );
    225         $this->assertEquals( '<a href="http://example.com/">Minnie Bannister</a>', $theme_data['Author'] );
    226         $this->assertEquals( 'http://example.com/', $theme_data['AuthorURI'] );
    227         $this->assertEquals( '1.3', $theme_data['Version'] );
    228         $this->assertEquals( '', $theme_data['Template'] );
    229         $this->assertEquals( 'publish', $theme_data['Status'] );
    230         $this->assertEquals( array(), $theme_data['Tags'] );
    231         $this->assertEquals( 'My Theme', $theme_data['Title'] );
    232         $this->assertEquals( 'Minnie Bannister', $theme_data['AuthorName'] );
     222        $this->assertSame( 'My Theme', $theme_data['Name'] );
     223        $this->assertSame( 'http://example.org/', $theme_data['URI'] );
     224        $this->assertSame( 'An example theme', $theme_data['Description'] );
     225        $this->assertSame( '<a href="http://example.com/">Minnie Bannister</a>', $theme_data['Author'] );
     226        $this->assertSame( 'http://example.com/', $theme_data['AuthorURI'] );
     227        $this->assertSame( '1.3', $theme_data['Version'] );
     228        $this->assertSame( '', $theme_data['Template'] );
     229        $this->assertSame( 'publish', $theme_data['Status'] );
     230        $this->assertSame( array(), $theme_data['Tags'] );
     231        $this->assertSame( 'My Theme', $theme_data['Title'] );
     232        $this->assertSame( 'Minnie Bannister', $theme_data['AuthorName'] );
    233233    }
    234234
     
    239239        $theme_data = get_theme_data( $this->theme_root . '/subdir/theme2/style.css' );
    240240
    241         $this->assertEquals( 'My Subdir Theme', $theme_data['Name'] );
    242         $this->assertEquals( 'http://example.org/', $theme_data['URI'] );
    243         $this->assertEquals( 'An example theme in a sub directory', $theme_data['Description'] );
    244         $this->assertEquals( '<a href="http://wordpress.org/">Mr. WordPress</a>', $theme_data['Author'] );
    245         $this->assertEquals( 'http://wordpress.org/', $theme_data['AuthorURI'] );
    246         $this->assertEquals( '0.1', $theme_data['Version'] );
    247         $this->assertEquals( '', $theme_data['Template'] );
    248         $this->assertEquals( 'publish', $theme_data['Status'] );
    249         $this->assertEquals( array(), $theme_data['Tags'] );
    250         $this->assertEquals( 'My Subdir Theme', $theme_data['Title'] );
    251         $this->assertEquals( 'Mr. WordPress', $theme_data['AuthorName'] );
     241        $this->assertSame( 'My Subdir Theme', $theme_data['Name'] );
     242        $this->assertSame( 'http://example.org/', $theme_data['URI'] );
     243        $this->assertSame( 'An example theme in a sub directory', $theme_data['Description'] );
     244        $this->assertSame( '<a href="http://wordpress.org/">Mr. WordPress</a>', $theme_data['Author'] );
     245        $this->assertSame( 'http://wordpress.org/', $theme_data['AuthorURI'] );
     246        $this->assertSame( '0.1', $theme_data['Version'] );
     247        $this->assertSame( '', $theme_data['Template'] );
     248        $this->assertSame( 'publish', $theme_data['Status'] );
     249        $this->assertSame( array(), $theme_data['Tags'] );
     250        $this->assertSame( 'My Subdir Theme', $theme_data['Title'] );
     251        $this->assertSame( 'Mr. WordPress', $theme_data['AuthorName'] );
    252252    }
    253253
Note: See TracChangeset for help on using the changeset viewer.