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/rest-api/rest-comments-controller.php

    r48231 r48937  
    173173        $response = rest_get_server()->dispatch( $request );
    174174        $data     = $response->get_data();
    175         $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
    176         $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
     175        $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] );
     176        $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
    177177        // Single.
    178178        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments/' . self::$approved_id );
    179179        $response = rest_get_server()->dispatch( $request );
    180180        $data     = $response->get_data();
    181         $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
    182         $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
     181        $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] );
     182        $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
    183183    }
    184184
     
    189189        $keys     = array_keys( $data['endpoints'][0]['args'] );
    190190        sort( $keys );
    191         $this->assertEquals(
     191        $this->assertSame(
    192192            array(
    193193                'after',
     
    221221
    222222        $response = rest_get_server()->dispatch( $request );
    223         $this->assertEquals( 200, $response->get_status() );
     223        $this->assertSame( 200, $response->get_status() );
    224224
    225225        $comments = $response->get_data();
     
    245245
    246246        $response = rest_get_server()->dispatch( $request );
    247         $this->assertEquals( 200, $response->get_status() );
     247        $this->assertSame( 200, $response->get_status() );
    248248
    249249        $collection_data = $response->get_data();
     
    268268
    269269        $response = rest_get_server()->dispatch( $request );
    270         $this->assertEquals( 200, $response->get_status() );
     270        $this->assertSame( 200, $response->get_status() );
    271271
    272272        $collection_data = $response->get_data();
     
    308308
    309309        $response = rest_get_server()->dispatch( $request );
    310         $this->assertEquals( 200, $response->get_status() );
     310        $this->assertSame( 200, $response->get_status() );
    311311
    312312        $collection_data = $response->get_data();
     
    327327
    328328        $response = rest_get_server()->dispatch( $request );
    329         $this->assertEquals( 200, $response->get_status() );
     329        $this->assertSame( 200, $response->get_status() );
    330330
    331331        $collection_data = $response->get_data();
     
    346346
    347347        $response = rest_get_server()->dispatch( $request );
    348         $this->assertEquals( 200, $response->get_status() );
     348        $this->assertSame( 200, $response->get_status() );
    349349
    350350        $collection_data = $response->get_data();
     
    365365
    366366        $response = rest_get_server()->dispatch( $request );
    367         $this->assertEquals( 200, $response->get_status() );
     367        $this->assertSame( 200, $response->get_status() );
    368368
    369369        $collection_data = $response->get_data();
     
    384384
    385385        $response = rest_get_server()->dispatch( $request );
    386         $this->assertEquals( 200, $response->get_status() );
     386        $this->assertSame( 200, $response->get_status() );
    387387
    388388        $collection_data = $response->get_data();
     
    405405
    406406        $response = rest_get_server()->dispatch( $request );
    407         $this->assertEquals( 200, $response->get_status() );
     407        $this->assertSame( 200, $response->get_status() );
    408408
    409409        $collection_data = $response->get_data();
     
    430430        $request->set_param( 'post', 0 );
    431431        $response = rest_get_server()->dispatch( $request );
    432         $this->assertEquals( 200, $response->get_status() );
     432        $this->assertSame( 200, $response->get_status() );
    433433        $comments = $response->get_data();
    434434        $this->assertCount( 2, $comments );
     
    450450        $request->set_param( 'context', 'edit' );
    451451        $response = rest_get_server()->dispatch( $request );
    452         $this->assertEquals( 200, $response->get_status() );
     452        $this->assertSame( 200, $response->get_status() );
    453453    }
    454454
     
    465465
    466466        $response = rest_get_server()->dispatch( $request );
    467         $this->assertEquals( 200, $response->get_status() );
     467        $this->assertSame( 200, $response->get_status() );
    468468
    469469        $comments = $response->get_data();
     
    489489        $response = rest_get_server()->dispatch( $request );
    490490        $data     = $response->get_data();
    491         $this->assertEquals( 2, count( $data ) );
    492         $this->assertEquals( $id1, $data[0]['id'] );
     491        $this->assertSame( 2, count( $data ) );
     492        $this->assertSame( $id1, $data[0]['id'] );
    493493
    494494        // 'orderby' => 'include'.
     
    496496        $response = rest_get_server()->dispatch( $request );
    497497        $data     = $response->get_data();
    498         $this->assertEquals( 2, count( $data ) );
    499         $this->assertEquals( $id2, $data[0]['id'] );
     498        $this->assertSame( 2, count( $data ) );
     499        $this->assertSame( $id2, $data[0]['id'] );
    500500
    501501        // Invalid 'orderby' should error.
     
    582582        $response = rest_get_server()->dispatch( $request );
    583583        $data     = $response->get_data();
    584         $this->assertEquals( $id, $data[0]['id'] );
     584        $this->assertSame( $id, $data[0]['id'] );
    585585
    586586        // 'order' => 'asc'.
     
    588588        $response = rest_get_server()->dispatch( $request );
    589589        $data     = $response->get_data();
    590         $this->assertEquals( self::$approved_id, $data[0]['id'] );
     590        $this->assertSame( self::$approved_id, $data[0]['id'] );
    591591
    592592        // 'order' => 'asc,id' should error.
     
    627627        $request->set_param( 'author', self::$author_id );
    628628        $response = rest_get_server()->dispatch( $request );
    629         $this->assertEquals( 200, $response->get_status() );
     629        $this->assertSame( 200, $response->get_status() );
    630630        $comments = $response->get_data();
    631631        $this->assertCount( 1, $comments );
     
    634634        $request->set_param( 'author', array( self::$author_id, self::$subscriber_id ) );
    635635        $response = rest_get_server()->dispatch( $request );
    636         $this->assertEquals( 200, $response->get_status() );
     636        $this->assertSame( 200, $response->get_status() );
    637637        $comments = $response->get_data();
    638638        $this->assertCount( 2, $comments );
     
    679679        $request->set_param( 'author_exclude', self::$author_id );
    680680        $response = rest_get_server()->dispatch( $request );
    681         $this->assertEquals( 200, $response->get_status() );
     681        $this->assertSame( 200, $response->get_status() );
    682682        $comments = $response->get_data();
    683683        $this->assertCount( $total_comments - 1, $comments );
     
    688688        $request->set_param( 'author_exclude', array( self::$author_id, self::$subscriber_id ) );
    689689        $response = rest_get_server()->dispatch( $request );
    690         $this->assertEquals( 200, $response->get_status() );
     690        $this->assertSame( 200, $response->get_status() );
    691691        $comments = $response->get_data();
    692692        $this->assertCount( $total_comments - 2, $comments );
     
    801801        $data     = $response->get_data();
    802802        $this->assertCount( 1, $data );
    803         $this->assertEquals( $id, $data[0]['id'] );
     803        $this->assertSame( $id, $data[0]['id'] );
    804804    }
    805805
     
    814814        $response = rest_get_server()->dispatch( $request );
    815815        $headers  = $response->get_headers();
    816         $this->assertEquals( $total_comments, $headers['X-WP-Total'] );
    817         $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] );
     816        $this->assertSame( $total_comments, $headers['X-WP-Total'] );
     817        $this->assertSame( $total_pages, $headers['X-WP-TotalPages'] );
    818818        $next_link = add_query_arg(
    819819            array(
     
    837837        $response = rest_get_server()->dispatch( $request );
    838838        $headers  = $response->get_headers();
    839         $this->assertEquals( $total_comments, $headers['X-WP-Total'] );
    840         $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] );
     839        $this->assertSame( $total_comments, $headers['X-WP-Total'] );
     840        $this->assertSame( $total_pages, $headers['X-WP-TotalPages'] );
    841841        $prev_link = add_query_arg(
    842842            array(
     
    859859        $response = rest_get_server()->dispatch( $request );
    860860        $headers  = $response->get_headers();
    861         $this->assertEquals( $total_comments, $headers['X-WP-Total'] );
    862         $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] );
     861        $this->assertSame( $total_comments, $headers['X-WP-Total'] );
     862        $this->assertSame( $total_pages, $headers['X-WP-TotalPages'] );
    863863        $prev_link = add_query_arg(
    864864            array(
     
    875875        $response = rest_get_server()->dispatch( $request );
    876876        $headers  = $response->get_headers();
    877         $this->assertEquals( $total_comments, $headers['X-WP-Total'] );
     877        $this->assertSame( $total_comments, $headers['X-WP-Total'] );
    878878        $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] );
    879879        $prev_link = add_query_arg(
     
    921921        $data     = $response->get_data();
    922922        $this->assertCount( 1, $data );
    923         $this->assertEquals( $comment2, $data[0]['id'] );
     923        $this->assertSame( $comment2, $data[0]['id'] );
    924924    }
    925925
     
    928928
    929929        $response = rest_get_server()->dispatch( $request );
    930         $this->assertEquals( 200, $response->get_status() );
     930        $this->assertSame( 200, $response->get_status() );
    931931
    932932        $data = $response->get_data();
     
    945945
    946946        $response = rest_get_server()->dispatch( $request );
    947         $this->assertEquals( 200, $response->get_status() );
     947        $this->assertSame( 200, $response->get_status() );
    948948
    949949        $data = $response->get_data();
     
    960960        $obj      = get_comment( self::$approved_id );
    961961        $response = $endpoint->prepare_item_for_response( $obj, $request );
    962         $this->assertEquals(
     962        $this->assertSame(
    963963            array(
    964964                'id',
     
    982982        // Ignore the subdomain, since get_avatar_url() randomly sets
    983983        // the Gravatar server when building the URL string.
    984         $this->assertEquals( substr( get_avatar_url( $comment->comment_author_email ), 9 ), substr( $data['author_avatar_urls'][96], 9 ) );
     984        $this->assertSame( substr( get_avatar_url( $comment->comment_author_email ), 9 ), substr( $data['author_avatar_urls'][96], 9 ) );
    985985    }
    986986
     
    10441044        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$hold_id ) );
    10451045        $response = rest_get_server()->dispatch( $request );
    1046         $this->assertEquals( 200, $response->get_status() );
     1046        $this->assertSame( 200, $response->get_status() );
    10471047    }
    10481048
     
    10671067        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $comment_id_1 ) );
    10681068        $response = rest_get_server()->dispatch( $request );
    1069         $this->assertEquals( 200, $response->get_status() );
     1069        $this->assertSame( 200, $response->get_status() );
    10701070        $this->assertArrayHasKey( 'children', $response->get_links() );
    10711071    }
     
    10821082        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $comment_id_1 ) );
    10831083        $response = rest_get_server()->dispatch( $request );
    1084         $this->assertEquals( 200, $response->get_status() );
     1084        $this->assertSame( 200, $response->get_status() );
    10851085        $this->assertArrayNotHasKey( 'children', $response->get_links() );
    10861086    }
     
    11181118
    11191119        $response = rest_get_server()->dispatch( $request );
    1120         $this->assertEquals( 200, $response->get_status() );
     1120        $this->assertSame( 200, $response->get_status() );
    11211121    }
    11221122
     
    11381138
    11391139        $response = rest_get_server()->dispatch( $request );
    1140         $this->assertEquals( 201, $response->get_status() );
     1140        $this->assertSame( 201, $response->get_status() );
    11411141
    11421142        $data = $response->get_data();
    11431143        $this->check_comment_data( $data, 'edit', $response->get_links() );
    1144         $this->assertEquals( 'hold', $data['status'] );
    1145         $this->assertEquals( '2014-11-07T10:14:25', $data['date'] );
    1146         $this->assertEquals( self::$post_id, $data['post'] );
     1144        $this->assertSame( 'hold', $data['status'] );
     1145        $this->assertSame( '2014-11-07T10:14:25', $data['date'] );
     1146        $this->assertSame( self::$post_id, $data['post'] );
    11471147    }
    11481148
     
    12131213        update_option( 'timezone_string', '' );
    12141214
    1215         $this->assertEquals( 201, $response->get_status() );
     1215        $this->assertSame( 201, $response->get_status() );
    12161216        $data    = $response->get_data();
    12171217        $comment = get_comment( $data['id'] );
    12181218
    1219         $this->assertEquals( $results['date'], $data['date'] );
     1219        $this->assertSame( $results['date'], $data['date'] );
    12201220        $comment_date = str_replace( 'T', ' ', $results['date'] );
    1221         $this->assertEquals( $comment_date, $comment->comment_date );
    1222 
    1223         $this->assertEquals( $results['date_gmt'], $data['date_gmt'] );
     1221        $this->assertSame( $comment_date, $comment->comment_date );
     1222
     1223        $this->assertSame( $results['date_gmt'], $data['date_gmt'] );
    12241224        $comment_date_gmt = str_replace( 'T', ' ', $results['date_gmt'] );
    1225         $this->assertEquals( $comment_date_gmt, $comment->comment_date_gmt );
     1225        $this->assertSame( $comment_date_gmt, $comment->comment_date_gmt );
    12261226    }
    12271227
     
    12441244
    12451245        $response = rest_get_server()->dispatch( $request );
    1246         $this->assertEquals( 201, $response->get_status() );
     1246        $this->assertSame( 201, $response->get_status() );
    12471247
    12481248        $data        = $response->get_data();
    12491249        $new_comment = get_comment( $data['id'] );
    1250         $this->assertEquals( $params['content']['raw'], $new_comment->comment_content );
     1250        $this->assertSame( $params['content']['raw'], $new_comment->comment_content );
    12511251    }
    12521252
     
    14441444        $request->set_body( wp_json_encode( $params ) );
    14451445        $response = rest_get_server()->dispatch( $request );
    1446         $this->assertEquals( 201, $response->get_status() );
     1446        $this->assertSame( 201, $response->get_status() );
    14471447
    14481448        $data = $response->get_data();
    1449         $this->assertEquals( $subscriber_id, $data['author'] );
    1450         $this->assertEquals( '127.0.0.1', $data['author_ip'] );
     1449        $this->assertSame( $subscriber_id, $data['author'] );
     1450        $this->assertSame( '127.0.0.1', $data['author_ip'] );
    14511451    }
    14521452
     
    14711471
    14721472        $response = rest_get_server()->dispatch( $request );
    1473         $this->assertEquals( 201, $response->get_status() );
     1473        $this->assertSame( 201, $response->get_status() );
    14741474
    14751475        $data = $response->get_data();
    1476         $this->assertEquals( 'comment', $data['type'] );
     1476        $this->assertSame( 'comment', $data['type'] );
    14771477
    14781478        $comment_id = $data['id'];
     
    14831483        $collection_response = rest_get_server()->dispatch( $collection );
    14841484        $collection_data     = $collection_response->get_data();
    1485         $this->assertEquals( $comment_id, $collection_data[0]['id'] );
     1485        $this->assertSame( $comment_id, $collection_data[0]['id'] );
    14861486    }
    14871487
     
    15601560        $response = rest_get_server()->dispatch( $request );
    15611561
    1562         $this->assertEquals( 201, $response->get_status() );
     1562        $this->assertSame( 201, $response->get_status() );
    15631563        $data = $response->get_data();
    1564         $this->assertEquals( $user_id, $data['author'] );
     1564        $this->assertSame( $user_id, $data['author'] );
    15651565
    15661566        // Check author data matches.
    15671567        $author  = get_user_by( 'id', $user_id );
    15681568        $comment = get_comment( $data['id'] );
    1569         $this->assertEquals( $author->display_name, $comment->comment_author );
    1570         $this->assertEquals( $author->user_email, $comment->comment_author_email );
    1571         $this->assertEquals( $author->user_url, $comment->comment_author_url );
     1569        $this->assertSame( $author->display_name, $comment->comment_author );
     1570        $this->assertSame( $author->user_email, $comment->comment_author_email );
     1571        $this->assertSame( $author->user_url, $comment->comment_author_url );
    15721572    }
    15731573
     
    15891589        $response = rest_get_server()->dispatch( $request );
    15901590
    1591         $this->assertEquals( 201, $response->get_status() );
     1591        $this->assertSame( 201, $response->get_status() );
    15921592        $data = $response->get_data();
    1593         $this->assertEquals( self::$subscriber_id, $data['author'] );
    1594         $this->assertEquals( 'Homer Jay Simpson', $data['author_name'] );
    1595         $this->assertEquals( 'chunkylover53@aol.com', $data['author_email'] );
    1596         $this->assertEquals( 'http://compuglobalhypermeganet.com', $data['author_url'] );
     1593        $this->assertSame( self::$subscriber_id, $data['author'] );
     1594        $this->assertSame( 'Homer Jay Simpson', $data['author_name'] );
     1595        $this->assertSame( 'chunkylover53@aol.com', $data['author_email'] );
     1596        $this->assertSame( 'http://compuglobalhypermeganet.com', $data['author_url'] );
    15971597    }
    15981598
     
    16791679
    16801680        $response = rest_get_server()->dispatch( $request );
    1681         $this->assertEquals( 201, $response->get_status() );
     1681        $this->assertSame( 201, $response->get_status() );
    16821682
    16831683        $data = $response->get_data();
    1684         $this->assertEquals( 'approved', $data['status'] );
    1685         $this->assertEquals( '139.130.4.5', $data['author_ip'] );
    1686         $this->assertEquals( 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36', $data['author_user_agent'] );
     1684        $this->assertSame( 'approved', $data['status'] );
     1685        $this->assertSame( '139.130.4.5', $data['author_ip'] );
     1686        $this->assertSame( 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36', $data['author_user_agent'] );
    16871687    }
    16881688
     
    17041704
    17051705        $response = rest_get_server()->dispatch( $request );
    1706         $this->assertEquals( 201, $response->get_status() );
     1706        $this->assertSame( 201, $response->get_status() );
    17071707
    17081708        $data = $response->get_data();
    17091709
    17101710        $new_comment = get_comment( $data['id'] );
    1711         $this->assertEquals( 'Mozilla/4.0 (compatible; MSIE 5.5; AOL 4.0; Windows 95)', $new_comment->comment_agent );
     1711        $this->assertSame( 'Mozilla/4.0 (compatible; MSIE 5.5; AOL 4.0; Windows 95)', $new_comment->comment_agent );
    17121712    }
    17131713
     
    17301730        $data        = $response->get_data();
    17311731        $new_comment = get_comment( $data['id'] );
    1732         $this->assertEquals( '127.0.0.3', $new_comment->comment_author_IP );
     1732        $this->assertSame( '127.0.0.3', $new_comment->comment_author_IP );
    17331733    }
    17341734
     
    17911791        $data        = $response->get_data();
    17921792        $new_comment = get_comment( $data['id'] );
    1793         $this->assertEquals( '127.0.0.2', $new_comment->comment_author_IP );
     1793        $this->assertSame( '127.0.0.2', $new_comment->comment_author_IP );
    17941794    }
    17951795
     
    19581958        $response = rest_get_server()->dispatch( $request );
    19591959
    1960         $this->assertEquals( 409, $response->get_status() );
     1960        $this->assertSame( 409, $response->get_status() );
    19611961    }
    19621962
     
    19791979        $response = rest_get_server()->dispatch( $request );
    19801980
    1981         $this->assertEquals( 403, $response->get_status() );
     1981        $this->assertSame( 403, $response->get_status() );
    19821982    }
    19831983
     
    19911991        $request->set_param( 'post', self::$post_id );
    19921992        $response = rest_get_server()->dispatch( $request );
    1993         $this->assertEquals( 401, $response->get_status() );
     1993        $this->assertSame( 401, $response->get_status() );
    19941994        $data = $response->get_data();
    1995         $this->assertEquals( 'rest_comment_login_required', $data['code'] );
     1995        $this->assertSame( 'rest_comment_login_required', $data['code'] );
    19961996    }
    19971997
     
    20522052
    20532053        $response = rest_get_server()->dispatch( $request );
    2054         $this->assertEquals( 201, $response->get_status() );
     2054        $this->assertSame( 201, $response->get_status() );
    20552055
    20562056        $params = array(
     
    20672067
    20682068        $response = rest_get_server()->dispatch( $request );
    2069         $this->assertEquals( 400, $response->get_status() );
     2069        $this->assertSame( 400, $response->get_status() );
    20702070    }
    20712071
     
    22302230        $request->set_body( wp_json_encode( $params ) );
    22312231        $response = rest_get_server()->dispatch( $request );
    2232         $this->assertEquals( 201, $response->get_status() );
     2232        $this->assertSame( 201, $response->get_status() );
    22332233    }
    22342234
     
    22542254
    22552255        $response = rest_get_server()->dispatch( $request );
    2256         $this->assertEquals( 200, $response->get_status() );
     2256        $this->assertSame( 200, $response->get_status() );
    22572257
    22582258        $comment = $response->get_data();
    22592259        $updated = get_comment( self::$approved_id );
    2260         $this->assertEquals( $params['content'], $comment['content']['raw'] );
    2261         $this->assertEquals( $params['author'], $comment['author'] );
    2262         $this->assertEquals( $params['author_name'], $comment['author_name'] );
    2263         $this->assertEquals( $params['author_url'], $comment['author_url'] );
    2264         $this->assertEquals( $params['author_email'], $comment['author_email'] );
    2265         $this->assertEquals( $params['author_ip'], $comment['author_ip'] );
    2266         $this->assertEquals( $params['post'], $comment['post'] );
    2267 
    2268         $this->assertEquals( mysql_to_rfc3339( $updated->comment_date ), $comment['date'] );
    2269         $this->assertEquals( '2014-11-07T10:14:25', $comment['date'] );
     2260        $this->assertSame( $params['content'], $comment['content']['raw'] );
     2261        $this->assertSame( $params['author'], $comment['author'] );
     2262        $this->assertSame( $params['author_name'], $comment['author_name'] );
     2263        $this->assertSame( $params['author_url'], $comment['author_url'] );
     2264        $this->assertSame( $params['author_email'], $comment['author_email'] );
     2265        $this->assertSame( $params['author_ip'], $comment['author_ip'] );
     2266        $this->assertSame( $params['post'], $comment['post'] );
     2267
     2268        $this->assertSame( mysql_to_rfc3339( $updated->comment_date ), $comment['date'] );
     2269        $this->assertSame( '2014-11-07T10:14:25', $comment['date'] );
    22702270    }
    22712271
     
    22912291        update_option( 'timezone_string', '' );
    22922292
    2293         $this->assertEquals( 200, $response->get_status() );
     2293        $this->assertSame( 200, $response->get_status() );
    22942294        $data    = $response->get_data();
    22952295        $comment = get_comment( $data['id'] );
    22962296
    2297         $this->assertEquals( $results['date'], $data['date'] );
     2297        $this->assertSame( $results['date'], $data['date'] );
    22982298        $comment_date = str_replace( 'T', ' ', $results['date'] );
    2299         $this->assertEquals( $comment_date, $comment->comment_date );
    2300 
    2301         $this->assertEquals( $results['date_gmt'], $data['date_gmt'] );
     2299        $this->assertSame( $comment_date, $comment->comment_date );
     2300
     2301        $this->assertSame( $results['date_gmt'], $data['date_gmt'] );
    23022302        $comment_date_gmt = str_replace( 'T', ' ', $results['date_gmt'] );
    2303         $this->assertEquals( $comment_date_gmt, $comment->comment_date_gmt );
     2303        $this->assertSame( $comment_date_gmt, $comment->comment_date_gmt );
    23042304    }
    23052305
     
    23142314        // Sending a request without content is fine.
    23152315        $response = rest_get_server()->dispatch( $request );
    2316         $this->assertEquals( 200, $response->get_status() );
     2316        $this->assertSame( 200, $response->get_status() );
    23172317
    23182318        // Sending a request with empty comment is not fine.
     
    23342334        // even if no DB rows are updated.
    23352335        $response = rest_get_server()->dispatch( $request );
    2336         $this->assertEquals( 200, $response->get_status() );
    2337 
    2338         $response = rest_get_server()->dispatch( $request );
    2339         $this->assertEquals( 200, $response->get_status() );
     2336        $this->assertSame( 200, $response->get_status() );
     2337
     2338        $response = rest_get_server()->dispatch( $request );
     2339        $this->assertSame( 200, $response->get_status() );
    23402340    }
    23412341
     
    23592359
    23602360        $response = rest_get_server()->dispatch( $request );
    2361         $this->assertEquals( 200, $response->get_status() );
     2361        $this->assertSame( 200, $response->get_status() );
    23622362
    23632363        $comment = $response->get_data();
    23642364        $updated = get_comment( $comment_id );
    2365         $this->assertEquals( 'approved', $comment['status'] );
     2365        $this->assertSame( 'approved', $comment['status'] );
    23662366        $this->assertEquals( 1, $updated->comment_approved );
    23672367    }
     
    23872387
    23882388        $response = rest_get_server()->dispatch( $request );
    2389         $this->assertEquals( 200, $response->get_status() );
     2389        $this->assertSame( 200, $response->get_status() );
    23902390
    23912391        $comment = $response->get_data();
    23922392        $updated = get_comment( $comment_id );
    2393         $this->assertEquals( 'approved', $comment['status'] );
     2393        $this->assertSame( 'approved', $comment['status'] );
    23942394        $this->assertEquals( 1, $updated->comment_approved );
    2395         $this->assertEquals( 'some content', $updated->comment_content );
     2395        $this->assertSame( 'some content', $updated->comment_content );
    23962396    }
    23972397
     
    24092409
    24102410        $response = rest_get_server()->dispatch( $request );
    2411         $this->assertEquals( 200, $response->get_status() );
     2411        $this->assertSame( 200, $response->get_status() );
    24122412
    24132413        $comment = $response->get_data();
    24142414        $updated = get_comment( self::$approved_id );
    2415         $this->assertEquals( $params['date_gmt'], $comment['date_gmt'] );
    2416         $this->assertEquals( $params['date_gmt'], mysql_to_rfc3339( $updated->comment_date_gmt ) );
     2415        $this->assertSame( $params['date_gmt'], $comment['date_gmt'] );
     2416        $this->assertSame( $params['date_gmt'], mysql_to_rfc3339( $updated->comment_date_gmt ) );
    24172417    }
    24182418
     
    24332433
    24342434        $response = rest_get_server()->dispatch( $request );
    2435         $this->assertEquals( 200, $response->get_status() );
     2435        $this->assertSame( 200, $response->get_status() );
    24362436    }
    24372437
     
    24532453
    24542454        $response = rest_get_server()->dispatch( $request );
    2455         $this->assertEquals( 200, $response->get_status() );
     2455        $this->assertSame( 200, $response->get_status() );
    24562456    }
    24572457
     
    24722472
    24732473        $response = rest_get_server()->dispatch( $request );
    2474         $this->assertEquals( 200, $response->get_status() );
     2474        $this->assertSame( 200, $response->get_status() );
    24752475    }
    24762476
     
    24922492
    24932493        $response = rest_get_server()->dispatch( $request );
    2494         $this->assertEquals( 200, $response->get_status() );
     2494        $this->assertSame( 200, $response->get_status() );
    24952495    }
    24962496
     
    25452545        $response = rest_get_server()->dispatch( $request );
    25462546
    2547         $this->assertEquals( 200, $response->get_status() );
     2547        $this->assertSame( 200, $response->get_status() );
    25482548
    25492549        $comment = $response->get_data();
    25502550        $updated = get_comment( self::$approved_id );
    2551         $this->assertEquals( $params['content']['raw'], $updated->comment_content );
     2551        $this->assertSame( $params['content']['raw'], $updated->comment_content );
    25522552    }
    25532553
     
    26402640
    26412641        $response = rest_get_server()->dispatch( $request );
    2642         $this->assertEquals( 200, $response->get_status() );
     2642        $this->assertSame( 200, $response->get_status() );
    26432643
    26442644        $comment = $response->get_data();
    26452645        $updated = get_comment( self::$approved_id );
    26462646
    2647         $this->assertEquals( $params['content'], $updated->comment_content );
    2648         $this->assertEquals( self::$post_id, $comment['post'] );
    2649         $this->assertEquals( '2019-10-07T23:14:25', $comment['date'] );
     2647        $this->assertSame( $params['content'], $updated->comment_content );
     2648        $this->assertSame( self::$post_id, $comment['post'] );
     2649        $this->assertSame( '2019-10-07T23:14:25', $comment['date'] );
    26502650    }
    26512651
     
    26952695        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $comment_id_1 ) );
    26962696        $response = rest_get_server()->dispatch( $request );
    2697         $this->assertEquals( 200, $response->get_status() );
     2697        $this->assertSame( 200, $response->get_status() );
    26982698        $this->assertArrayNotHasKey( 'children', $response->get_links() );
    26992699
     
    27032703        $request->set_param( 'content', rand_str() );
    27042704        $response = rest_get_server()->dispatch( $request );
    2705         $this->assertEquals( 200, $response->get_status() );
     2705        $this->assertSame( 200, $response->get_status() );
    27062706
    27072707        // Check if comment 1 now has the child link.
    27082708        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $comment_id_1 ) );
    27092709        $response = rest_get_server()->dispatch( $request );
    2710         $this->assertEquals( 200, $response->get_status() );
     2710        $this->assertSame( 200, $response->get_status() );
    27112711        $this->assertArrayHasKey( 'children', $response->get_links() );
    27122712    }
     
    28302830        }
    28312831        $response = rest_get_server()->dispatch( $request );
    2832         $this->assertEquals( 201, $response->get_status() );
     2832        $this->assertSame( 201, $response->get_status() );
    28332833        $actual_output = $response->get_data();
    28342834
     
    28362836        $this->assertInternalType( 'array', $actual_output['content'] );
    28372837        $this->assertArrayHasKey( 'raw', $actual_output['content'] );
    2838         $this->assertEquals( $expected_output['content']['raw'], $actual_output['content']['raw'] );
    2839         $this->assertEquals( $expected_output['content']['rendered'], trim( $actual_output['content']['rendered'] ) );
    2840         $this->assertEquals( $expected_output['author_name'], $actual_output['author_name'] );
    2841         $this->assertEquals( $expected_output['author_user_agent'], $actual_output['author_user_agent'] );
     2838        $this->assertSame( $expected_output['content']['raw'], $actual_output['content']['raw'] );
     2839        $this->assertSame( $expected_output['content']['rendered'], trim( $actual_output['content']['rendered'] ) );
     2840        $this->assertSame( $expected_output['author_name'], $actual_output['author_name'] );
     2841        $this->assertSame( $expected_output['author_user_agent'], $actual_output['author_user_agent'] );
    28422842
    28432843        // Compare expected API output to WP internal values.
    28442844        $comment = get_comment( $actual_output['id'] );
    2845         $this->assertEquals( $expected_output['content']['raw'], $comment->comment_content );
    2846         $this->assertEquals( $expected_output['author_name'], $comment->comment_author );
    2847         $this->assertEquals( $expected_output['author_user_agent'], $comment->comment_agent );
     2845        $this->assertSame( $expected_output['content']['raw'], $comment->comment_content );
     2846        $this->assertSame( $expected_output['author_name'], $comment->comment_author );
     2847        $this->assertSame( $expected_output['author_user_agent'], $comment->comment_agent );
    28482848
    28492849        // Update the comment.
     
    28562856        $request->set_param( 'author_ip', '127.0.0.2' );
    28572857        $response = rest_get_server()->dispatch( $request );
    2858         $this->assertEquals( 200, $response->get_status() );
     2858        $this->assertSame( 200, $response->get_status() );
    28592859        $actual_output = $response->get_data();
    28602860
    28612861        // Compare expected API output to actual API output.
    2862         $this->assertEquals( $expected_output['content']['raw'], $actual_output['content']['raw'] );
    2863         $this->assertEquals( $expected_output['content']['rendered'], trim( $actual_output['content']['rendered'] ) );
    2864         $this->assertEquals( $expected_output['author_name'], $actual_output['author_name'] );
    2865         $this->assertEquals( $expected_output['author_user_agent'], $actual_output['author_user_agent'] );
     2862        $this->assertSame( $expected_output['content']['raw'], $actual_output['content']['raw'] );
     2863        $this->assertSame( $expected_output['content']['rendered'], trim( $actual_output['content']['rendered'] ) );
     2864        $this->assertSame( $expected_output['author_name'], $actual_output['author_name'] );
     2865        $this->assertSame( $expected_output['author_user_agent'], $actual_output['author_user_agent'] );
    28662866
    28672867        // Compare expected API output to WP internal values.
    28682868        $comment = get_comment( $actual_output['id'] );
    2869         $this->assertEquals( $expected_output['content']['raw'], $comment->comment_content );
    2870         $this->assertEquals( $expected_output['author_name'], $comment->comment_author );
    2871         $this->assertEquals( $expected_output['author_user_agent'], $comment->comment_agent );
     2869        $this->assertSame( $expected_output['content']['raw'], $comment->comment_content );
     2870        $this->assertSame( $expected_output['author_name'], $comment->comment_author );
     2871        $this->assertSame( $expected_output['author_user_agent'], $comment->comment_agent );
    28722872    }
    28732873
     
    28752875        wp_set_current_user( self::$editor_id );
    28762876
    2877         $this->assertEquals( ! is_multisite(), current_user_can( 'unfiltered_html' ) );
     2877        $this->assertSame( ! is_multisite(), current_user_can( 'unfiltered_html' ) );
    28782878        $this->verify_comment_roundtrip(
    28792879            array(
     
    29892989        $request->set_param( 'force', 'false' );
    29902990        $response = rest_get_server()->dispatch( $request );
    2991         $this->assertEquals( 200, $response->get_status() );
     2991        $this->assertSame( 200, $response->get_status() );
    29922992
    29932993        $data = $response->get_data();
    2994         $this->assertEquals( 'trash', $data['status'] );
     2994        $this->assertSame( 'trash', $data['status'] );
    29952995    }
    29962996
     
    30103010
    30113011        $response = rest_get_server()->dispatch( $request );
    3012         $this->assertEquals( 200, $response->get_status() );
     3012        $this->assertSame( 200, $response->get_status() );
    30133013        $data = $response->get_data();
    30143014        $this->assertTrue( $data['deleted'] );
     
    30293029        $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) );
    30303030        $response = rest_get_server()->dispatch( $request );
    3031         $this->assertEquals( 200, $response->get_status() );
     3031        $this->assertSame( 200, $response->get_status() );
    30323032        $data     = $response->get_data();
    30333033        $response = rest_get_server()->dispatch( $request );
     
    30733073        $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%s', $child_comment ) );
    30743074        $response = rest_get_server()->dispatch( $request );
    3075         $this->assertEquals( 200, $response->get_status() );
     3075        $this->assertSame( 200, $response->get_status() );
    30763076
    30773077        // Verify children link is gone.
    30783078        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $comment_id_1 ) );
    30793079        $response = rest_get_server()->dispatch( $request );
    3080         $this->assertEquals( 200, $response->get_status() );
     3080        $this->assertSame( 200, $response->get_status() );
    30813081        $this->assertArrayNotHasKey( 'children', $response->get_links() );
    30823082    }
     
    30873087        $data       = $response->get_data();
    30883088        $properties = $data['schema']['properties'];
    3089         $this->assertEquals( 17, count( $properties ) );
     3089        $this->assertSame( 17, count( $properties ) );
    30903090        $this->assertArrayHasKey( 'id', $properties );
    30913091        $this->assertArrayHasKey( 'author', $properties );
     
    31063106        $this->assertArrayHasKey( 'type', $properties );
    31073107
    3108         $this->assertEquals( 0, $properties['parent']['default'] );
    3109         $this->assertEquals( 0, $properties['post']['default'] );
    3110 
    3111         $this->assertEquals( true, $properties['link']['readonly'] );
    3112         $this->assertEquals( true, $properties['type']['readonly'] );
     3108        $this->assertSame( 0, $properties['parent']['default'] );
     3109        $this->assertSame( 0, $properties['post']['default'] );
     3110
     3111        $this->assertTrue( $properties['link']['readonly'] );
     3112        $this->assertTrue( $properties['type']['readonly'] );
    31133113    }
    31143114
     
    31483148
    31493149        $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] );
    3150         $this->assertEquals( $schema, $data['schema']['properties']['my_custom_int'] );
     3150        $this->assertSame( $schema, $data['schema']['properties']['my_custom_int'] );
    31513151
    31523152        $request  = new WP_REST_Request( 'GET', '/wp/v2/comments/' . self::$approved_id );
     
    32393239        $this->assertEquals( $comment->comment_parent, $data['parent'] );
    32403240        $this->assertEquals( $comment->user_id, $data['author'] );
    3241         $this->assertEquals( $comment->comment_author, $data['author_name'] );
    3242         $this->assertEquals( $comment->comment_author_url, $data['author_url'] );
    3243         $this->assertEquals( wpautop( $comment->comment_content ), $data['content']['rendered'] );
    3244         $this->assertEquals( mysql_to_rfc3339( $comment->comment_date ), $data['date'] );
    3245         $this->assertEquals( mysql_to_rfc3339( $comment->comment_date_gmt ), $data['date_gmt'] );
    3246         $this->assertEquals( get_comment_link( $comment ), $data['link'] );
     3241        $this->assertSame( $comment->comment_author, $data['author_name'] );
     3242        $this->assertSame( $comment->comment_author_url, $data['author_url'] );
     3243        $this->assertSame( wpautop( $comment->comment_content ), $data['content']['rendered'] );
     3244        $this->assertSame( mysql_to_rfc3339( $comment->comment_date ), $data['date'] );
     3245        $this->assertSame( mysql_to_rfc3339( $comment->comment_date_gmt ), $data['date_gmt'] );
     3246        $this->assertSame( get_comment_link( $comment ), $data['link'] );
    32473247        $this->assertContains( 'author_avatar_urls', $data );
    32483248        $this->assertEqualSets(
     
    32563256
    32573257        if ( 'edit' === $context ) {
    3258             $this->assertEquals( $comment->comment_author_email, $data['author_email'] );
    3259             $this->assertEquals( $comment->comment_author_IP, $data['author_ip'] );
    3260             $this->assertEquals( $comment->comment_agent, $data['author_user_agent'] );
    3261             $this->assertEquals( $comment->comment_content, $data['content']['raw'] );
     3258            $this->assertSame( $comment->comment_author_email, $data['author_email'] );
     3259            $this->assertSame( $comment->comment_author_IP, $data['author_ip'] );
     3260            $this->assertSame( $comment->comment_agent, $data['author_user_agent'] );
     3261            $this->assertSame( $comment->comment_content, $data['content']['raw'] );
    32623262        }
    32633263
     
    32943294        $request  = new WP_REST_Request( 'GET', '/wp/v2/comments/' . $comment_id );
    32953295        $response = rest_get_server()->dispatch( $request );
    3296         $this->assertEquals( 403, $response->get_status() );
     3296        $this->assertSame( 403, $response->get_status() );
    32973297    }
    32983298}
Note: See TracChangeset for help on using the changeset viewer.