Make WordPress Core

Changeset 50283


Ignore:
Timestamp:
02/10/2021 01:23:42 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Replace most instances of assertEquals() in phpunit/includes/ with assertSame().

Follow-up to [48937], [48939], [48940], [48944].

Props johnbillion, jrf, SergeyBiryukov.
See #38266, #52482.

Location:
trunk/tests/phpunit/includes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/testcase-canonical.php

    r49603 r50283  
    309309        // Just test the path and query if present.
    310310        if ( isset( $expected['url'] ) ) {
    311             $this->assertEquals( $expected['url'], $parsed_can_url['path'] . ( ! empty( $parsed_can_url['query'] ) ? '?' . $parsed_can_url['query'] : '' ), $ticket_ref );
     311            $this->assertSame( $expected['url'], $parsed_can_url['path'] . ( ! empty( $parsed_can_url['query'] ) ? '?' . $parsed_can_url['query'] : '' ), $ticket_ref );
    312312        }
    313313
     
    329329            // $_qv should not contain any elements which are set in $query_vars already
    330330            // (i.e. $_GET vars should not be present in the Rewrite).
    331             $this->assertEquals( array(), array_intersect( $query_vars, $_qv ), 'Query vars are duplicated from the Rewrite into $_GET; ' . $ticket_ref );
     331            $this->assertSame( array(), array_intersect( $query_vars, $_qv ), 'Query vars are duplicated from the Rewrite into $_GET; ' . $ticket_ref );
    332332
    333333            $query_vars = array_merge( $query_vars, $_qv );
  • trunk/tests/phpunit/includes/testcase-rest-api.php

    r49606 r50283  
    99
    1010        $this->assertWPError( $response );
    11         $this->assertEquals( $code, $response->get_error_code() );
     11        $this->assertSame( $code, $response->get_error_code() );
    1212
    1313        if ( null !== $status ) {
    1414            $data = $response->get_error_data();
    1515            $this->assertArrayHasKey( 'status', $data );
    16             $this->assertEquals( $status, $data['status'] );
     16            $this->assertSame( $status, $data['status'] );
    1717        }
    1818    }
  • trunk/tests/phpunit/includes/testcase-rest-post-type-controller.php

    r47122 r50283  
    77
    88        // Standard fields.
    9         $this->assertEquals( $post->ID, $data['id'] );
    10         $this->assertEquals( $post->post_name, $data['slug'] );
    11         $this->assertEquals( get_permalink( $post->ID ), $data['link'] );
     9        $this->assertSame( $post->ID, $data['id'] );
     10        $this->assertSame( $post->post_name, $data['slug'] );
     11        $this->assertSame( get_permalink( $post->ID ), $data['link'] );
    1212        if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) {
    1313            $post_date_gmt = gmdate( 'Y-m-d H:i:s', strtotime( $post->post_date ) - ( get_option( 'gmt_offset' ) * 3600 ) );
    14             $this->assertEquals( mysql_to_rfc3339( $post_date_gmt ), $data['date_gmt'] );
    15         } else {
    16             $this->assertEquals( mysql_to_rfc3339( $post->post_date_gmt ), $data['date_gmt'] );
    17         }
    18         $this->assertEquals( mysql_to_rfc3339( $post->post_date ), $data['date'] );
     14            $this->assertSame( mysql_to_rfc3339( $post_date_gmt ), $data['date_gmt'] );
     15        } else {
     16            $this->assertSame( mysql_to_rfc3339( $post->post_date_gmt ), $data['date_gmt'] );
     17        }
     18        $this->assertSame( mysql_to_rfc3339( $post->post_date ), $data['date'] );
    1919
    2020        if ( '0000-00-00 00:00:00' === $post->post_modified_gmt ) {
    2121            $post_modified_gmt = gmdate( 'Y-m-d H:i:s', strtotime( $post->post_modified ) - ( get_option( 'gmt_offset' ) * 3600 ) );
    22             $this->assertEquals( mysql_to_rfc3339( $post_modified_gmt ), $data['modified_gmt'] );
    23         } else {
    24             $this->assertEquals( mysql_to_rfc3339( $post->post_modified_gmt ), $data['modified_gmt'] );
    25         }
    26         $this->assertEquals( mysql_to_rfc3339( $post->post_modified ), $data['modified'] );
     22            $this->assertSame( mysql_to_rfc3339( $post_modified_gmt ), $data['modified_gmt'] );
     23        } else {
     24            $this->assertSame( mysql_to_rfc3339( $post->post_modified_gmt ), $data['modified_gmt'] );
     25        }
     26        $this->assertSame( mysql_to_rfc3339( $post->post_modified ), $data['modified'] );
    2727
    2828        // Author.
     
    3838            if ( $post->post_parent ) {
    3939                if ( is_int( $data['parent'] ) ) {
    40                     $this->assertEquals( $post->post_parent, $data['parent'] );
     40                    $this->assertSame( $post->post_parent, $data['parent'] );
    4141                } else {
    42                     $this->assertEquals( $post->post_parent, $data['parent']['id'] );
     42                    $this->assertSame( $post->post_parent, $data['parent']['id'] );
    4343                    $this->check_get_post_response( $data['parent'], get_post( $data['parent']['id'] ), 'view-parent' );
    4444                }
     
    5252        // Page attributes.
    5353        if ( $post_type_obj->hierarchical && post_type_supports( $post->post_type, 'page-attributes' ) ) {
    54             $this->assertEquals( $post->menu_order, $data['menu_order'] );
     54            $this->assertSame( $post->menu_order, $data['menu_order'] );
    5555        } else {
    5656            $this->assertFalse( isset( $data['menu_order'] ) );
     
    5959        // Comments.
    6060        if ( post_type_supports( $post->post_type, 'comments' ) ) {
    61             $this->assertEquals( $post->comment_status, $data['comment_status'] );
    62             $this->assertEquals( $post->ping_status, $data['ping_status'] );
     61            $this->assertSame( $post->comment_status, $data['comment_status'] );
     62            $this->assertSame( $post->ping_status, $data['ping_status'] );
    6363        } else {
    6464            $this->assertFalse( isset( $data['comment_status'] ) );
     
    6767
    6868        if ( 'post' === $post->post_type ) {
    69             $this->assertEquals( is_sticky( $post->ID ), $data['sticky'] );
     69            $this->assertSame( is_sticky( $post->ID ), $data['sticky'] );
    7070        }
    7171
    7272        if ( 'post' === $post->post_type && 'edit' === $context ) {
    73             $this->assertEquals( $post->post_password, $data['password'] );
     73            $this->assertSame( $post->post_password, $data['password'] );
    7474        }
    7575
    7676        if ( 'page' === $post->post_type ) {
    77             $this->assertEquals( get_page_template_slug( $post->ID ), $data['template'] );
     77            $this->assertSame( get_page_template_slug( $post->ID ), $data['template'] );
    7878        }
    7979
    8080        if ( post_type_supports( $post->post_type, 'thumbnail' ) ) {
    81             $this->assertEquals( (int) get_post_thumbnail_id( $post->ID ), $data['featured_media'] );
     81            $this->assertSame( (int) get_post_thumbnail_id( $post->ID ), $data['featured_media'] );
    8282        } else {
    8383            $this->assertFalse( isset( $data['featured_media'] ) );
     
    8888            $post_format = get_post_format( $post->ID );
    8989            if ( empty( $post_format ) ) {
    90                 $this->assertEquals( 'standard', $data['format'] );
    91             } else {
    92                 $this->assertEquals( get_post_format( $post->ID ), $data['format'] );
     90                $this->assertSame( 'standard', $data['format'] );
     91            } else {
     92                $this->assertSame( get_post_format( $post->ID ), $data['format'] );
    9393            }
    9494        } else {
     
    9999        if ( post_type_supports( $post->post_type, 'title' ) ) {
    100100            add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) );
    101             $this->assertEquals( get_the_title( $post->ID ), $data['title']['rendered'] );
     101            $this->assertSame( get_the_title( $post->ID ), $data['title']['rendered'] );
    102102            remove_filter( 'protected_title_format', array( $this, 'protected_title_format' ) );
    103103            if ( 'edit' === $context ) {
    104                 $this->assertEquals( $post->post_title, $data['title']['raw'] );
     104                $this->assertSame( $post->post_title, $data['title']['raw'] );
    105105            } else {
    106106                $this->assertFalse( isset( $data['title']['raw'] ) );
     
    113113            // TODO: Apply content filter for more accurate testing.
    114114            if ( ! $post->post_password ) {
    115                 $this->assertEquals( wpautop( $post->post_content ), $data['content']['rendered'] );
     115                $this->assertSame( wpautop( $post->post_content ), $data['content']['rendered'] );
    116116            }
    117117
    118118            if ( 'edit' === $context ) {
    119                 $this->assertEquals( $post->post_content, $data['content']['raw'] );
     119                $this->assertSame( $post->post_content, $data['content']['raw'] );
    120120            } else {
    121121                $this->assertFalse( isset( $data['content']['raw'] ) );
     
    128128            if ( empty( $post->post_password ) ) {
    129129                // TODO: Apply excerpt filter for more accurate testing.
    130                 $this->assertEquals( wpautop( $post->post_excerpt ), $data['excerpt']['rendered'] );
     130                $this->assertSame( wpautop( $post->post_excerpt ), $data['excerpt']['rendered'] );
    131131            } else {
    132132                // TODO: Better testing for excerpts for password protected posts.
    133133            }
    134134            if ( 'edit' === $context ) {
    135                 $this->assertEquals( $post->post_excerpt, $data['excerpt']['raw'] );
     135                $this->assertSame( $post->post_excerpt, $data['excerpt']['raw'] );
    136136            } else {
    137137                $this->assertFalse( isset( $data['excerpt']['raw'] ) );
     
    141141        }
    142142
    143         $this->assertEquals( $post->post_status, $data['status'] );
    144         $this->assertEquals( $post->guid, $data['guid']['rendered'] );
     143        $this->assertSame( $post->post_status, $data['status'] );
     144        $this->assertSame( $post->guid, $data['guid']['rendered'] );
    145145
    146146        if ( 'edit' === $context ) {
    147             $this->assertEquals( $post->guid, $data['guid']['raw'] );
     147            $this->assertSame( $post->guid, $data['guid']['raw'] );
    148148        }
    149149
     
    154154            sort( $terms );
    155155            sort( $data[ $taxonomy->rest_base ] );
    156             $this->assertEquals( $terms, $data[ $taxonomy->rest_base ] );
     156            $this->assertSame( $terms, $data[ $taxonomy->rest_base ] );
    157157        }
    158158
     
    162162            $links     = test_rest_expand_compact_links( $links );
    163163            $post_type = get_post_type_object( $data['type'] );
    164             $this->assertEquals( $links['self'][0]['href'], rest_url( 'wp/v2/' . $post_type->rest_base . '/' . $data['id'] ) );
    165             $this->assertEquals( $links['collection'][0]['href'], rest_url( 'wp/v2/' . $post_type->rest_base ) );
    166             $this->assertEquals( $links['about'][0]['href'], rest_url( 'wp/v2/types/' . $data['type'] ) );
     164            $this->assertSame( $links['self'][0]['href'], rest_url( 'wp/v2/' . $post_type->rest_base . '/' . $data['id'] ) );
     165            $this->assertSame( $links['collection'][0]['href'], rest_url( 'wp/v2/' . $post_type->rest_base ) );
     166            $this->assertSame( $links['about'][0]['href'], rest_url( 'wp/v2/types/' . $data['type'] ) );
    167167
    168168            if ( post_type_supports( $post->post_type, 'author' ) && $data['author'] ) {
    169                 $this->assertEquals( $links['author'][0]['href'], rest_url( 'wp/v2/users/' . $data['author'] ) );
     169                $this->assertSame( $links['author'][0]['href'], rest_url( 'wp/v2/users/' . $data['author'] ) );
    170170            }
    171171
    172172            if ( post_type_supports( $post->post_type, 'comments' ) ) {
    173                 $this->assertEquals( $links['replies'][0]['href'], add_query_arg( 'post', $data['id'], rest_url( 'wp/v2/comments' ) ) );
     173                $this->assertSame( $links['replies'][0]['href'], add_query_arg( 'post', $data['id'], rest_url( 'wp/v2/comments' ) ) );
    174174            }
    175175
    176176            if ( post_type_supports( $post->post_type, 'revisions' ) ) {
    177                 $this->assertEquals( $links['version-history'][0]['href'], rest_url( 'wp/v2/' . $post_type->rest_base . '/' . $data['id'] . '/revisions' ) );
     177                $this->assertSame( $links['version-history'][0]['href'], rest_url( 'wp/v2/' . $post_type->rest_base . '/' . $data['id'] . '/revisions' ) );
    178178            }
    179179
    180180            if ( $post_type->hierarchical && ! empty( $data['parent'] ) ) {
    181                 $this->assertEquals( $links['up'][0]['href'], rest_url( 'wp/v2/' . $post_type->rest_base . '/' . $data['parent'] ) );
     181                $this->assertSame( $links['up'][0]['href'], rest_url( 'wp/v2/' . $post_type->rest_base . '/' . $data['parent'] ) );
    182182            }
    183183
    184184            if ( ! in_array( $data['type'], array( 'attachment', 'nav_menu_item', 'revision' ), true ) ) {
    185                 $this->assertEquals( $links['https://api.w.org/attachment'][0]['href'], add_query_arg( 'parent', $data['id'], rest_url( 'wp/v2/media' ) ) );
     185                $this->assertSame( $links['https://api.w.org/attachment'][0]['href'], add_query_arg( 'parent', $data['id'], rest_url( 'wp/v2/media' ) ) );
    186186            }
    187187
    188188            if ( ! empty( $data['featured_media'] ) ) {
    189                 $this->assertEquals( $links['https://api.w.org/featuredmedia'][0]['href'], rest_url( 'wp/v2/media/' . $data['featured_media'] ) );
     189                $this->assertSame( $links['https://api.w.org/featuredmedia'][0]['href'], rest_url( 'wp/v2/media/' . $data['featured_media'] ) );
    190190            }
    191191
    192192            $num = 0;
    193193            foreach ( $taxonomies as $key => $taxonomy ) {
    194                 $this->assertEquals( $taxonomy->name, $links['https://api.w.org/term'][ $num ]['attributes']['taxonomy'] );
    195                 $this->assertEquals( add_query_arg( 'post', $data['id'], rest_url( 'wp/v2/' . $taxonomy->rest_base ) ), $links['https://api.w.org/term'][ $num ]['href'] );
     194                $this->assertSame( $taxonomy->name, $links['https://api.w.org/term'][ $num ]['attributes']['taxonomy'] );
     195                $this->assertSame( add_query_arg( 'post', $data['id'], rest_url( 'wp/v2/' . $taxonomy->rest_base ) ), $links['https://api.w.org/term'][ $num ]['href'] );
    196196                $num++;
    197197            }
     
    203203        $this->assertNotWPError( $response );
    204204        $response = rest_ensure_response( $response );
    205         $this->assertEquals( 200, $response->get_status() );
     205        $this->assertSame( 200, $response->get_status() );
    206206
    207207        $headers = $response->get_headers();
     
    236236        $this->assertNotWPError( $response );
    237237        $response = rest_ensure_response( $response );
    238         $this->assertEquals( 200, $response->get_status() );
     238        $this->assertSame( 200, $response->get_status() );
    239239
    240240        $data = $response->get_data();
     
    248248        $response = rest_ensure_response( $response );
    249249
    250         $this->assertEquals( 201, $response->get_status() );
     250        $this->assertSame( 201, $response->get_status() );
    251251        $headers = $response->get_headers();
    252252        $this->assertArrayHasKey( 'Location', $headers );
     
    261261        $response = rest_ensure_response( $response );
    262262
    263         $this->assertEquals( 200, $response->get_status() );
     263        $this->assertSame( 200, $response->get_status() );
    264264        $headers = $response->get_headers();
    265265        $this->assertArrayNotHasKey( 'Location', $headers );
  • trunk/tests/phpunit/includes/testcase-xml.php

    r48072 r50283  
    7070     */
    7171    public function assertXMLEquals( $expectedXml, $actualXml, $message = '' ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
    72         $this->assertEquals( $this->normalizeXML( $expectedXml ), $this->normalizeXML( $actualXml ), $message ); //phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
     72        $this->assertSame( $this->normalizeXML( $expectedXml ), $this->normalizeXML( $actualXml ), $message ); //phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
    7373    }
    7474
Note: See TracChangeset for help on using the changeset viewer.