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/xmlrpc/wp/getOptions.php

    r47122 r48937  
    99        $result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'username', 'password' ) );
    1010        $this->assertIXRError( $result );
    11         $this->assertEquals( 403, $result->code );
     11        $this->assertSame( 403, $result->code );
    1212    }
    1313
     
    1717        $result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'subscriber', 'subscriber' ) );
    1818        $this->assertInternalType( 'array', $result );
    19         $this->assertEquals( 'WordPress', $result['software_name']['value'] );
     19        $this->assertSame( 'WordPress', $result['software_name']['value'] );
    2020    }
    2121
     
    2626        $this->assertInternalType( 'array', $result );
    2727
    28         $this->assertEquals( get_option( 'default_comment_status' ), $result['default_comment_status']['value'] );
     28        $this->assertSame( get_option( 'default_comment_status' ), $result['default_comment_status']['value'] );
    2929        $this->assertFalse( $result['default_comment_status']['readonly'] );
    3030    }
     
    4141
    4242        // Read-only options.
    43         $this->assertEquals( 'WordPress', $result['software_name']['value'] );
     43        $this->assertSame( 'WordPress', $result['software_name']['value'] );
    4444        $this->assertTrue( $result['software_name']['readonly'] );
    4545
    46         $this->assertEquals( $wp_version, $result['software_version']['value'] );
     46        $this->assertSame( $wp_version, $result['software_version']['value'] );
    4747        $this->assertTrue( $result['software_version']['readonly'] );
    4848
    49         $this->assertEquals( get_site_url(), $result['blog_url']['value'] );
     49        $this->assertSame( get_site_url(), $result['blog_url']['value'] );
    5050        $this->assertTrue( $result['blog_url']['readonly'] );
    5151
    52         $this->assertEquals( wp_login_url(), $result['login_url']['value'] );
     52        $this->assertSame( wp_login_url(), $result['login_url']['value'] );
    5353        $this->assertTrue( $result['login_url']['readonly'] );
    5454
    55         $this->assertEquals( get_admin_url(), $result['admin_url']['value'] );
     55        $this->assertSame( get_admin_url(), $result['admin_url']['value'] );
    5656        $this->assertTrue( $result['admin_url']['readonly'] );
    5757
    58         $this->assertEquals( get_option( 'image_default_link_type' ), $result['image_default_link_type']['value'] );
     58        $this->assertSame( get_option( 'image_default_link_type' ), $result['image_default_link_type']['value'] );
    5959        $this->assertTrue( $result['image_default_link_type']['readonly'] );
    6060
    61         $this->assertEquals( get_option( 'image_default_size' ), $result['image_default_size']['value'] );
     61        $this->assertSame( get_option( 'image_default_size' ), $result['image_default_size']['value'] );
    6262        $this->assertTrue( $result['image_default_size']['readonly'] );
    6363
    64         $this->assertEquals( get_option( 'image_default_align' ), $result['image_default_align']['value'] );
     64        $this->assertSame( get_option( 'image_default_align' ), $result['image_default_align']['value'] );
    6565        $this->assertTrue( $result['image_default_align']['readonly'] );
    6666
    67         $this->assertEquals( get_template(), $result['template']['value'] );
     67        $this->assertSame( get_template(), $result['template']['value'] );
    6868        $this->assertTrue( $result['template']['readonly'] );
    6969
    70         $this->assertEquals( get_stylesheet(), $result['stylesheet']['value'] );
     70        $this->assertSame( get_stylesheet(), $result['stylesheet']['value'] );
    7171        $this->assertTrue( $result['stylesheet']['readonly'] );
    7272
    73         $this->assertEquals( current_theme_supports( 'post-thumbnails' ), $result['post_thumbnail']['value'] );
     73        $this->assertSame( current_theme_supports( 'post-thumbnails' ), $result['post_thumbnail']['value'] );
    7474        $this->assertTrue( $result['post_thumbnail']['readonly'] );
    7575
    7676        // Updatable options.
    77         $this->assertEquals( get_option( 'gmt_offset' ), $result['time_zone']['value'] );
     77        $this->assertSame( get_option( 'gmt_offset' ), $result['time_zone']['value'] );
    7878        $this->assertTrue( $result['time_zone']['readonly'] );
    7979
    80         $this->assertEquals( get_option( 'blogname' ), $result['blog_title']['value'] );
     80        $this->assertSame( get_option( 'blogname' ), $result['blog_title']['value'] );
    8181        $this->assertTrue( $result['blog_title']['readonly'] );
    8282
    83         $this->assertEquals( get_option( 'blogdescription' ), $result['blog_tagline']['value'] );
     83        $this->assertSame( get_option( 'blogdescription' ), $result['blog_tagline']['value'] );
    8484        $this->assertTrue( $result['blog_tagline']['readonly'] );
    8585
    86         $this->assertEquals( get_option( 'date_format' ), $result['date_format']['value'] );
     86        $this->assertSame( get_option( 'date_format' ), $result['date_format']['value'] );
    8787        $this->assertTrue( $result['date_format']['readonly'] );
    8888
    89         $this->assertEquals( get_option( 'time_format' ), $result['time_format']['value'] );
     89        $this->assertSame( get_option( 'time_format' ), $result['time_format']['value'] );
    9090        $this->assertTrue( $result['time_format']['readonly'] );
    9191
    92         $this->assertEquals( get_option( 'users_can_register' ), $result['users_can_register']['value'] );
     92        $this->assertSame( get_option( 'users_can_register' ), $result['users_can_register']['value'] );
    9393        $this->assertTrue( $result['users_can_register']['readonly'] );
    9494
    95         $this->assertEquals( get_option( 'thumbnail_size_w' ), $result['thumbnail_size_w']['value'] );
     95        $this->assertSame( get_option( 'thumbnail_size_w' ), $result['thumbnail_size_w']['value'] );
    9696        $this->assertTrue( $result['thumbnail_size_w']['readonly'] );
    9797
    98         $this->assertEquals( get_option( 'thumbnail_size_h' ), $result['thumbnail_size_h']['value'] );
     98        $this->assertSame( get_option( 'thumbnail_size_h' ), $result['thumbnail_size_h']['value'] );
    9999        $this->assertTrue( $result['thumbnail_size_h']['readonly'] );
    100100
    101         $this->assertEquals( get_option( 'thumbnail_crop' ), $result['thumbnail_crop']['value'] );
     101        $this->assertSame( get_option( 'thumbnail_crop' ), $result['thumbnail_crop']['value'] );
    102102        $this->assertTrue( $result['thumbnail_crop']['readonly'] );
    103103
    104         $this->assertEquals( get_option( 'medium_size_w' ), $result['medium_size_w']['value'] );
     104        $this->assertSame( get_option( 'medium_size_w' ), $result['medium_size_w']['value'] );
    105105        $this->assertTrue( $result['medium_size_w']['readonly'] );
    106106
    107         $this->assertEquals( get_option( 'medium_size_h' ), $result['medium_size_h']['value'] );
     107        $this->assertSame( get_option( 'medium_size_h' ), $result['medium_size_h']['value'] );
    108108        $this->assertTrue( $result['medium_size_h']['readonly'] );
    109109
    110         $this->assertEquals( get_option( 'large_size_w' ), $result['large_size_w']['value'] );
     110        $this->assertSame( get_option( 'large_size_w' ), $result['large_size_w']['value'] );
    111111        $this->assertTrue( $result['large_size_w']['readonly'] );
    112112
    113         $this->assertEquals( get_option( 'large_size_h' ), $result['large_size_h']['value'] );
     113        $this->assertSame( get_option( 'large_size_h' ), $result['large_size_h']['value'] );
    114114        $this->assertTrue( $result['large_size_h']['readonly'] );
    115115
    116         $this->assertEquals( get_option( 'default_comment_status' ), $result['default_comment_status']['value'] );
     116        $this->assertSame( get_option( 'default_comment_status' ), $result['default_comment_status']['value'] );
    117117        $this->assertTrue( $result['default_comment_status']['readonly'] );
    118118
    119         $this->assertEquals( get_option( 'default_ping_status' ), $result['default_ping_status']['value'] );
     119        $this->assertSame( get_option( 'default_ping_status' ), $result['default_ping_status']['value'] );
    120120        $this->assertTrue( $result['default_ping_status']['readonly'] );
    121121    }
     
    130130
    131131        // Read-only options.
    132         $this->assertEquals( 'WordPress', $result['software_name']['value'] );
     132        $this->assertSame( 'WordPress', $result['software_name']['value'] );
    133133        $this->assertTrue( $result['software_name']['readonly'] );
    134134
    135         $this->assertEquals( $wp_version, $result['software_version']['value'] );
     135        $this->assertSame( $wp_version, $result['software_version']['value'] );
    136136        $this->assertTrue( $result['software_version']['readonly'] );
    137137
    138         $this->assertEquals( get_site_url(), $result['blog_url']['value'] );
     138        $this->assertSame( get_site_url(), $result['blog_url']['value'] );
    139139        $this->assertTrue( $result['blog_url']['readonly'] );
    140140
    141         $this->assertEquals( wp_login_url(), $result['login_url']['value'] );
     141        $this->assertSame( wp_login_url(), $result['login_url']['value'] );
    142142        $this->assertTrue( $result['login_url']['readonly'] );
    143143
    144         $this->assertEquals( get_admin_url(), $result['admin_url']['value'] );
     144        $this->assertSame( get_admin_url(), $result['admin_url']['value'] );
    145145        $this->assertTrue( $result['admin_url']['readonly'] );
    146146
    147         $this->assertEquals( get_option( 'image_default_link_type' ), $result['image_default_link_type']['value'] );
     147        $this->assertSame( get_option( 'image_default_link_type' ), $result['image_default_link_type']['value'] );
    148148        $this->assertTrue( $result['image_default_link_type']['readonly'] );
    149149
    150         $this->assertEquals( get_option( 'image_default_size' ), $result['image_default_size']['value'] );
     150        $this->assertSame( get_option( 'image_default_size' ), $result['image_default_size']['value'] );
    151151        $this->assertTrue( $result['image_default_size']['readonly'] );
    152152
    153         $this->assertEquals( get_option( 'image_default_align' ), $result['image_default_align']['value'] );
     153        $this->assertSame( get_option( 'image_default_align' ), $result['image_default_align']['value'] );
    154154        $this->assertTrue( $result['image_default_align']['readonly'] );
    155155
    156         $this->assertEquals( get_template(), $result['template']['value'] );
     156        $this->assertSame( get_template(), $result['template']['value'] );
    157157        $this->assertTrue( $result['template']['readonly'] );
    158158
    159         $this->assertEquals( get_stylesheet(), $result['stylesheet']['value'] );
     159        $this->assertSame( get_stylesheet(), $result['stylesheet']['value'] );
    160160        $this->assertTrue( $result['stylesheet']['readonly'] );
    161161
    162         $this->assertEquals( current_theme_supports( 'post-thumbnails' ), $result['post_thumbnail']['value'] );
     162        $this->assertSame( current_theme_supports( 'post-thumbnails' ), $result['post_thumbnail']['value'] );
    163163        $this->assertTrue( $result['post_thumbnail']['readonly'] );
    164164
    165165        // Updatable options.
    166         $this->assertEquals( get_option( 'gmt_offset' ), $result['time_zone']['value'] );
     166        $this->assertSame( get_option( 'gmt_offset' ), $result['time_zone']['value'] );
    167167        $this->assertFalse( $result['time_zone']['readonly'] );
    168168
    169         $this->assertEquals( get_option( 'blogname' ), $result['blog_title']['value'] );
     169        $this->assertSame( get_option( 'blogname' ), $result['blog_title']['value'] );
    170170        $this->assertFalse( $result['blog_title']['readonly'] );
    171171
    172         $this->assertEquals( get_option( 'blogdescription' ), $result['blog_tagline']['value'] );
     172        $this->assertSame( get_option( 'blogdescription' ), $result['blog_tagline']['value'] );
    173173        $this->assertFalse( $result['blog_tagline']['readonly'] );
    174174
    175         $this->assertEquals( get_option( 'date_format' ), $result['date_format']['value'] );
     175        $this->assertSame( get_option( 'date_format' ), $result['date_format']['value'] );
    176176        $this->assertFalse( $result['date_format']['readonly'] );
    177177
    178         $this->assertEquals( get_option( 'time_format' ), $result['time_format']['value'] );
     178        $this->assertSame( get_option( 'time_format' ), $result['time_format']['value'] );
    179179        $this->assertFalse( $result['time_format']['readonly'] );
    180180
    181         $this->assertEquals( get_option( 'users_can_register' ), $result['users_can_register']['value'] );
     181        $this->assertSame( get_option( 'users_can_register' ), $result['users_can_register']['value'] );
    182182        $this->assertFalse( $result['users_can_register']['readonly'] );
    183183
    184         $this->assertEquals( get_option( 'thumbnail_size_w' ), $result['thumbnail_size_w']['value'] );
     184        $this->assertSame( get_option( 'thumbnail_size_w' ), $result['thumbnail_size_w']['value'] );
    185185        $this->assertFalse( $result['thumbnail_size_w']['readonly'] );
    186186
    187         $this->assertEquals( get_option( 'thumbnail_size_h' ), $result['thumbnail_size_h']['value'] );
     187        $this->assertSame( get_option( 'thumbnail_size_h' ), $result['thumbnail_size_h']['value'] );
    188188        $this->assertFalse( $result['thumbnail_size_h']['readonly'] );
    189189
    190         $this->assertEquals( get_option( 'thumbnail_crop' ), $result['thumbnail_crop']['value'] );
     190        $this->assertSame( get_option( 'thumbnail_crop' ), $result['thumbnail_crop']['value'] );
    191191        $this->assertFalse( $result['thumbnail_crop']['readonly'] );
    192192
    193         $this->assertEquals( get_option( 'medium_size_w' ), $result['medium_size_w']['value'] );
     193        $this->assertSame( get_option( 'medium_size_w' ), $result['medium_size_w']['value'] );
    194194        $this->assertFalse( $result['medium_size_w']['readonly'] );
    195195
    196         $this->assertEquals( get_option( 'medium_size_h' ), $result['medium_size_h']['value'] );
     196        $this->assertSame( get_option( 'medium_size_h' ), $result['medium_size_h']['value'] );
    197197        $this->assertFalse( $result['medium_size_h']['readonly'] );
    198198
    199         $this->assertEquals( get_option( 'large_size_w' ), $result['large_size_w']['value'] );
     199        $this->assertSame( get_option( 'large_size_w' ), $result['large_size_w']['value'] );
    200200        $this->assertFalse( $result['large_size_w']['readonly'] );
    201201
    202         $this->assertEquals( get_option( 'large_size_h' ), $result['large_size_h']['value'] );
     202        $this->assertSame( get_option( 'large_size_h' ), $result['large_size_h']['value'] );
    203203        $this->assertFalse( $result['large_size_h']['readonly'] );
    204204
    205         $this->assertEquals( get_option( 'default_comment_status' ), $result['default_comment_status']['value'] );
     205        $this->assertSame( get_option( 'default_comment_status' ), $result['default_comment_status']['value'] );
    206206        $this->assertFalse( $result['default_comment_status']['readonly'] );
    207207
    208         $this->assertEquals( get_option( 'default_ping_status' ), $result['default_ping_status']['value'] );
     208        $this->assertSame( get_option( 'default_ping_status' ), $result['default_ping_status']['value'] );
    209209        $this->assertFalse( $result['default_ping_status']['readonly'] );
    210210    }
Note: See TracChangeset for help on using the changeset viewer.