Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (5 years 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/WPTheme.php

    r47122 r48937  
    3737
    3838        // Meta.
    39         $this->assertEquals( 'My Theme', $theme->get( 'Name' ) );
    40         $this->assertEquals( 'http://example.org/', $theme->get( 'ThemeURI' ) );
    41         $this->assertEquals( 'An example theme', $theme->get( 'Description' ) );
    42         $this->assertEquals( 'Minnie Bannister', $theme->get( 'Author' ) );
    43         $this->assertEquals( 'http://example.com/', $theme->get( 'AuthorURI' ) );
    44         $this->assertEquals( '1.3', $theme->get( 'Version' ) );
    45         $this->assertEquals( '', $theme->get( 'Template' ) );
    46         $this->assertEquals( 'publish', $theme->get( 'Status' ) );
    47         $this->assertEquals( array(), $theme->get( 'Tags' ) );
     39        $this->assertSame( 'My Theme', $theme->get( 'Name' ) );
     40        $this->assertSame( 'http://example.org/', $theme->get( 'ThemeURI' ) );
     41        $this->assertSame( 'An example theme', $theme->get( 'Description' ) );
     42        $this->assertSame( 'Minnie Bannister', $theme->get( 'Author' ) );
     43        $this->assertSame( 'http://example.com/', $theme->get( 'AuthorURI' ) );
     44        $this->assertSame( '1.3', $theme->get( 'Version' ) );
     45        $this->assertSame( '', $theme->get( 'Template' ) );
     46        $this->assertSame( 'publish', $theme->get( 'Status' ) );
     47        $this->assertSame( array(), $theme->get( 'Tags' ) );
    4848
    4949        // Important.
    50         $this->assertEquals( 'theme1', $theme->get_stylesheet() );
    51         $this->assertEquals( 'theme1', $theme->get_template() );
     50        $this->assertSame( 'theme1', $theme->get_stylesheet() );
     51        $this->assertSame( 'theme1', $theme->get_template() );
    5252    }
    5353
     
    5656
    5757        // Meta.
    58         $this->assertEquals( 'My Subdir Theme', $theme->get( 'Name' ) );
    59         $this->assertEquals( 'http://example.org/', $theme->get( 'ThemeURI' ) );
    60         $this->assertEquals( 'An example theme in a sub directory', $theme->get( 'Description' ) );
    61         $this->assertEquals( 'Mr. WordPress', $theme->get( 'Author' ) );
    62         $this->assertEquals( 'http://wordpress.org/', $theme->get( 'AuthorURI' ) );
    63         $this->assertEquals( '0.1', $theme->get( 'Version' ) );
    64         $this->assertEquals( '', $theme->get( 'Template' ) );
    65         $this->assertEquals( 'publish', $theme->get( 'Status' ) );
    66         $this->assertEquals( array(), $theme->get( 'Tags' ) );
     58        $this->assertSame( 'My Subdir Theme', $theme->get( 'Name' ) );
     59        $this->assertSame( 'http://example.org/', $theme->get( 'ThemeURI' ) );
     60        $this->assertSame( 'An example theme in a sub directory', $theme->get( 'Description' ) );
     61        $this->assertSame( 'Mr. WordPress', $theme->get( 'Author' ) );
     62        $this->assertSame( 'http://wordpress.org/', $theme->get( 'AuthorURI' ) );
     63        $this->assertSame( '0.1', $theme->get( 'Version' ) );
     64        $this->assertSame( '', $theme->get( 'Template' ) );
     65        $this->assertSame( 'publish', $theme->get( 'Status' ) );
     66        $this->assertSame( array(), $theme->get( 'Tags' ) );
    6767
    6868        // Important.
    69         $this->assertEquals( 'subdir/theme2', $theme->get_stylesheet() );
    70         $this->assertEquals( 'subdir/theme2', $theme->get_template() );
     69        $this->assertSame( 'subdir/theme2', $theme->get_stylesheet() );
     70        $this->assertSame( 'subdir/theme2', $theme->get_template() );
    7171    }
    7272
     
    7979
    8080        // Meta.
    81         $this->assertEquals( 'My Subdir Theme', $theme->get( 'Name' ) );
    82         $this->assertEquals( 'http://example.org/', $theme->get( 'ThemeURI' ) );
    83         $this->assertEquals( 'An example theme in a sub directory', $theme->get( 'Description' ) );
    84         $this->assertEquals( 'Mr. WordPress', $theme->get( 'Author' ) );
    85         $this->assertEquals( 'http://wordpress.org/', $theme->get( 'AuthorURI' ) );
    86         $this->assertEquals( '0.1', $theme->get( 'Version' ) );
    87         $this->assertEquals( '', $theme->get( 'Template' ) );
    88         $this->assertEquals( 'publish', $theme->get( 'Status' ) );
    89         $this->assertEquals( array(), $theme->get( 'Tags' ) );
     81        $this->assertSame( 'My Subdir Theme', $theme->get( 'Name' ) );
     82        $this->assertSame( 'http://example.org/', $theme->get( 'ThemeURI' ) );
     83        $this->assertSame( 'An example theme in a sub directory', $theme->get( 'Description' ) );
     84        $this->assertSame( 'Mr. WordPress', $theme->get( 'Author' ) );
     85        $this->assertSame( 'http://wordpress.org/', $theme->get( 'AuthorURI' ) );
     86        $this->assertSame( '0.1', $theme->get( 'Version' ) );
     87        $this->assertSame( '', $theme->get( 'Template' ) );
     88        $this->assertSame( 'publish', $theme->get( 'Status' ) );
     89        $this->assertSame( array(), $theme->get( 'Tags' ) );
    9090
    9191        // Important.
    92         $this->assertEquals( 'subdir/theme2', $theme->get_stylesheet() );
    93         $this->assertEquals( 'subdir/theme2', $theme->get_template() );
     92        $this->assertSame( 'subdir/theme2', $theme->get_stylesheet() );
     93        $this->assertSame( 'subdir/theme2', $theme->get_template() );
    9494    }
    9595
     
    100100        $theme = new WP_Theme( 'theme with spaces', $this->theme_root . '/subdir' );
    101101        // Make sure subdir/ is considered part of the stylesheet, as we must avoid encoding /'s.
    102         $this->assertEquals( 'subdir/theme with spaces', $theme->get_stylesheet() );
     102        $this->assertSame( 'subdir/theme with spaces', $theme->get_stylesheet() );
    103103
    104104        // Check that in a URI path, we have raw URL encoding (spaces become %20).
    105105        // Don't try to verify the complete URI path. get_theme_root_uri() breaks down quickly.
    106         $this->assertEquals( 'theme%20with%20spaces', basename( $theme->get_stylesheet_directory_uri() ) );
    107         $this->assertEquals( 'theme%20with%20spaces', basename( $theme->get_template_directory_uri() ) );
     106        $this->assertSame( 'theme%20with%20spaces', basename( $theme->get_stylesheet_directory_uri() ) );
     107        $this->assertSame( 'theme%20with%20spaces', basename( $theme->get_template_directory_uri() ) );
    108108
    109109        // Check that wp_customize_url() uses URL encoding, as it is a query arg (spaces become +).
    110         $this->assertEquals( admin_url( 'customize.php?theme=theme+with+spaces' ), wp_customize_url( 'theme with spaces' ) );
     110        $this->assertSame( admin_url( 'customize.php?theme=theme+with+spaces' ), wp_customize_url( 'theme with spaces' ) );
    111111    }
    112112
     
    119119        add_filter( 'template', $callback );
    120120
    121         $this->assertEquals( get_theme_root_uri() . '/subdir/theme%20with%20spaces', get_stylesheet_directory_uri() );
    122         $this->assertEquals( get_theme_root_uri() . '/subdir/theme%20with%20spaces', get_template_directory_uri() );
     121        $this->assertSame( get_theme_root_uri() . '/subdir/theme%20with%20spaces', get_stylesheet_directory_uri() );
     122        $this->assertSame( get_theme_root_uri() . '/subdir/theme%20with%20spaces', get_template_directory_uri() );
    123123
    124124        remove_filter( 'stylesheet', $callback );
     
    135135    function test_display_method_on_get_method_failure() {
    136136        $theme = new WP_Theme( 'nonexistent', $this->theme_root );
    137         $this->assertEquals( 'nonexistent', $theme->get( 'Name' ) );
     137        $this->assertSame( 'nonexistent', $theme->get( 'Name' ) );
    138138        $this->assertFalse( $theme->get( 'AuthorURI' ) );
    139139        $this->assertFalse( $theme->get( 'Tags' ) );
     
    148148        $errors = $theme->errors();
    149149        $this->assertWPError( $errors );
    150         $this->assertEquals( 'theme_child_invalid', $errors->get_error_code() );
     150        $this->assertSame( 'theme_child_invalid', $errors->get_error_code() );
    151151    }
    152152
Note: See TracChangeset for help on using the changeset viewer.