diff --git a/tests/phpunit/tests/xmlrpc/mw/editPost.php b/tests/phpunit/tests/xmlrpc/mw/editPost.php index eb996787acc09..23515233325ff 100644 --- a/tests/phpunit/tests/xmlrpc/mw/editPost.php +++ b/tests/phpunit/tests/xmlrpc/mw/editPost.php @@ -88,7 +88,7 @@ public function test_capable_reassign_author() { $this->assertTrue( $result ); $out = get_post( $post_id ); - $this->assertEquals( $author_id, $out->post_author ); + $this->assertSame( (string) $author_id, $out->post_author ); } public function test_incapable_reassign_author() { @@ -107,7 +107,7 @@ public function test_incapable_reassign_author() { $this->assertSame( 401, $result->code ); $out = get_post( $post_id ); - $this->assertEquals( $contributor_id, $out->post_author ); + $this->assertSame( (string) $contributor_id, $out->post_author ); } /** @@ -129,7 +129,7 @@ public function test_capable_reassign_author_to_self() { $this->assertTrue( $result ); $out = get_post( $post_id ); - $this->assertEquals( $editor_id, $out->post_author ); + $this->assertSame( (string) $editor_id, $out->post_author ); } /** @@ -156,13 +156,13 @@ public function test_post_thumbnail() { $post2 = array( 'wp_post_thumbnail' => $attachment_id ); $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'author', 'author', $post2 ) ); $this->assertNotIXRError( $result ); - $this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); + $this->assertSame( (string) $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); // Edit the post without supplying a post_thumbnail and check that it didn't change. $post3 = array( 'post_content' => 'Updated post' ); $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'author', 'author', $post3 ) ); $this->assertNotIXRError( $result ); - $this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); + $this->assertSame( (string) $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); // Create another attachment. $attachment2_id = self::factory()->attachment->create_upload_object( $filename, $post_id ); @@ -171,7 +171,7 @@ public function test_post_thumbnail() { $post4 = array( 'wp_post_thumbnail' => $attachment2_id ); $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'author', 'author', $post4 ) ); $this->assertNotIXRError( $result ); - $this->assertEquals( $attachment2_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); + $this->assertSame( (string) $attachment2_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); // Unset the post's post_thumbnail. $post5 = array( 'wp_post_thumbnail' => '' ); diff --git a/tests/phpunit/tests/xmlrpc/mw/newPost.php b/tests/phpunit/tests/xmlrpc/mw/newPost.php index 3637d28536475..e7c4af0cee01f 100644 --- a/tests/phpunit/tests/xmlrpc/mw/newPost.php +++ b/tests/phpunit/tests/xmlrpc/mw/newPost.php @@ -49,7 +49,8 @@ public function test_ignore_id() { ); $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'author', 'author', $post ) ); $this->assertNotIXRError( $result ); - $this->assertNotEquals( '103948', $result ); + $this->assertIsString( $result ); + $this->assertNotSame( '103948', $result ); } public function test_capable_publish() { @@ -124,7 +125,7 @@ public function test_empty_author() { $this->assertStringMatchesFormat( '%d', $result ); $out = get_post( $result ); - $this->assertEquals( $my_author_id, $out->post_author ); + $this->assertSame( (string) $my_author_id, $out->post_author ); $this->assertSame( 'Test', $out->post_title ); } @@ -146,7 +147,7 @@ public function test_post_thumbnail() { ); $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'author', 'author', $post ) ); $this->assertNotIXRError( $result ); - $this->assertEquals( $attachment_id, get_post_meta( $result, '_thumbnail_id', true ) ); + $this->assertSame( (string) $attachment_id, get_post_meta( $result, '_thumbnail_id', true ) ); remove_theme_support( 'post-thumbnails' ); } diff --git a/tests/phpunit/tests/xmlrpc/wp/editPost.php b/tests/phpunit/tests/xmlrpc/wp/editPost.php index b5f27b85488d8..dacd64573a6d5 100644 --- a/tests/phpunit/tests/xmlrpc/wp/editPost.php +++ b/tests/phpunit/tests/xmlrpc/wp/editPost.php @@ -88,7 +88,7 @@ public function test_capable_reassign_author() { $this->assertTrue( $result ); $out = get_post( $post_id ); - $this->assertEquals( $author_id, $out->post_author ); + $this->assertSame( (string) $author_id, $out->post_author ); } public function test_incapable_reassign_author() { @@ -107,7 +107,7 @@ public function test_incapable_reassign_author() { $this->assertSame( 401, $result->code ); $out = get_post( $post_id ); - $this->assertEquals( $contributor_id, $out->post_author ); + $this->assertSame( (string) $contributor_id, $out->post_author ); } /** @@ -129,7 +129,7 @@ public function test_capable_reassign_author_to_self() { $this->assertTrue( $result ); $out = get_post( $post_id ); - $this->assertEquals( $editor_id, $out->post_author ); + $this->assertSame( (string) $editor_id, $out->post_author ); } /** @@ -156,20 +156,20 @@ public function test_post_thumbnail() { $post2 = array( 'post_thumbnail' => $attachment_id ); $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post2 ) ); $this->assertNotIXRError( $result ); - $this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); + $this->assertSame( (string) $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); // Fetch the post to verify that it appears. $result = $this->myxmlrpcserver->wp_getPost( array( 1, 'author', 'author', $post_id ) ); $this->assertNotIXRError( $result ); $this->assertArrayHasKey( 'post_thumbnail', $result ); $this->assertIsArray( $result['post_thumbnail'] ); - $this->assertEquals( $attachment_id, $result['post_thumbnail']['attachment_id'] ); + $this->assertSame( (string) $attachment_id, $result['post_thumbnail']['attachment_id'] ); // Edit the post without supplying a post_thumbnail and check that it didn't change. $post3 = array( 'post_content' => 'Updated post' ); $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post3 ) ); $this->assertNotIXRError( $result ); - $this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); + $this->assertSame( (string) $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); // Create another attachment. $attachment2_id = self::factory()->attachment->create_upload_object( $filename, $post_id ); @@ -178,7 +178,7 @@ public function test_post_thumbnail() { $post4 = array( 'post_thumbnail' => $attachment2_id ); $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post4 ) ); $this->assertNotIXRError( $result ); - $this->assertEquals( $attachment2_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); + $this->assertSame( (string) $attachment2_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); // Unset the post's post_thumbnail. $post5 = array( 'post_thumbnail' => '' ); diff --git a/tests/phpunit/tests/xmlrpc/wp/editProfile.php b/tests/phpunit/tests/xmlrpc/wp/editProfile.php index 2789dbe460095..579f82c33fceb 100644 --- a/tests/phpunit/tests/xmlrpc/wp/editProfile.php +++ b/tests/phpunit/tests/xmlrpc/wp/editProfile.php @@ -64,6 +64,6 @@ public function test_ignore_email_change() { $this->assertTrue( $result ); $user_data = get_userdata( $editor_id ); - $this->assertNotEquals( $new_email, $user_data->email ); + $this->assertNotSame( $new_email, $user_data->user_email ); } } diff --git a/tests/phpunit/tests/xmlrpc/wp/editTerm.php b/tests/phpunit/tests/xmlrpc/wp/editTerm.php index fbc310ac7ea4f..0f6d9cf891e2e 100644 --- a/tests/phpunit/tests/xmlrpc/wp/editTerm.php +++ b/tests/phpunit/tests/xmlrpc/wp/editTerm.php @@ -190,7 +190,7 @@ public function test_parent_null() { $this->assertIsBool( $result ); $term = get_term( self::$child_term, 'category' ); - $this->assertEquals( '0', $term->parent ); + $this->assertSame( 0, $term->parent ); } public function test_parent_invalid() { diff --git a/tests/phpunit/tests/xmlrpc/wp/getComment.php b/tests/phpunit/tests/xmlrpc/wp/getComment.php index 08cd4a5b00174..1eb64c23ec8c6 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getComment.php +++ b/tests/phpunit/tests/xmlrpc/wp/getComment.php @@ -74,10 +74,10 @@ public function test_valid_comment() { $this->assertStringMatchesFormat( '%d', $result['comment_id'] ); $this->assertStringMatchesFormat( '%d', $result['parent'] ); $this->assertStringMatchesFormat( '%d', $result['post_id'] ); - $this->assertEquals( self::$parent_comment_id, $result['comment_id'] ); - $this->assertEquals( 0, $result['parent'] ); + $this->assertSame( (string) self::$parent_comment_id, $result['comment_id'] ); + $this->assertSame( '0', $result['parent'] ); $this->assertSame( self::$parent_comment_data['comment_content'], $result['content'] ); - $this->assertEquals( self::$post_id, $result['post_id'] ); + $this->assertSame( (string) self::$post_id, $result['post_id'] ); $this->assertSame( self::$parent_comment_data['comment_author'], $result['author'] ); $this->assertSame( self::$parent_comment_data['comment_author_url'], $result['author_url'] ); $this->assertSame( self::$parent_comment_data['comment_author_email'], $result['author_email'] ); @@ -89,8 +89,8 @@ public function test_valid_child_comment() { $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'editor', 'editor', self::$child_comment_id ) ); $this->assertNotIXRError( $result ); - $this->assertEquals( self::$child_comment_id, $result['comment_id'] ); - $this->assertEquals( self::$parent_comment_id, $result['parent'] ); + $this->assertSame( (string) self::$child_comment_id, $result['comment_id'] ); + $this->assertSame( (string) self::$parent_comment_id, $result['parent'] ); } public function test_invalid_id() { diff --git a/tests/phpunit/tests/xmlrpc/wp/getComments.php b/tests/phpunit/tests/xmlrpc/wp/getComments.php index 606f9e0e855cf..acd131a1eef10 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getComments.php +++ b/tests/phpunit/tests/xmlrpc/wp/getComments.php @@ -56,7 +56,7 @@ public function test_post_filter() { $this->assertNotEmpty( $results ); foreach ( $results as $result ) { - $this->assertEquals( $this->post_id, $result['post_id'] ); + $this->assertSame( (string) $this->post_id, $result['post_id'] ); } } diff --git a/tests/phpunit/tests/xmlrpc/wp/getPost.php b/tests/phpunit/tests/xmlrpc/wp/getPost.php index 72a0685a8a11a..8f2e28b5fd6ae 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getPost.php +++ b/tests/phpunit/tests/xmlrpc/wp/getPost.php @@ -72,9 +72,9 @@ public function test_valid_post() { $this->assertSame( $this->post_data['post_excerpt'], $result['post_excerpt'] ); $this->assertSame( $this->post_data['post_content'], $result['post_content'] ); $this->assertSame( url_to_postid( $result['link'] ), $this->post_id ); - $this->assertEquals( $this->post_custom_field['id'], $result['custom_fields'][0]['id'] ); + $this->assertSame( (string) $this->post_custom_field['id'], $result['custom_fields'][0]['id'] ); $this->assertSame( $this->post_custom_field['key'], $result['custom_fields'][0]['key'] ); - $this->assertEquals( $this->post_custom_field['value'], $result['custom_fields'][0]['value'] ); + $this->assertSame( (string) $this->post_custom_field['value'], $result['custom_fields'][0]['value'] ); remove_theme_support( 'post-thumbnails' ); } @@ -144,7 +144,7 @@ public function test_valid_page() { $this->assertIsString( $result['post_mime_type'] ); $this->assertSame( 'page', $result['post_type'] ); - $this->assertEquals( $parent_page_id, $result['post_parent'] ); + $this->assertSame( (string) $parent_page_id, $result['post_parent'] ); $this->assertSame( 2, $result['menu_order'] ); } diff --git a/tests/phpunit/tests/xmlrpc/wp/getPosts.php b/tests/phpunit/tests/xmlrpc/wp/getPosts.php index b1ab560886eb9..4ac3c46ab6069 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getPosts.php +++ b/tests/phpunit/tests/xmlrpc/wp/getPosts.php @@ -120,7 +120,7 @@ public function test_filters() { $results3 = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter3 ) ); $this->assertNotIXRError( $results3 ); $this->assertCount( 1, $results3 ); - $this->assertEquals( $post->ID, $results3[0]['post_id'] ); + $this->assertSame( (string) $post->ID, $results3[0]['post_id'] ); _unregister_post_type( $cpt_name ); } diff --git a/tests/phpunit/tests/xmlrpc/wp/getProfile.php b/tests/phpunit/tests/xmlrpc/wp/getProfile.php index c9325ade3d670..60122d84769db 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getProfile.php +++ b/tests/phpunit/tests/xmlrpc/wp/getProfile.php @@ -17,7 +17,7 @@ public function test_subscriber() { $result = $this->myxmlrpcserver->wp_getProfile( array( 1, 'subscriber', 'subscriber' ) ); $this->assertNotIXRError( $result ); - $this->assertEquals( $subscriber_id, $result['user_id'] ); + $this->assertSame( (string) $subscriber_id, $result['user_id'] ); $this->assertContains( 'subscriber', $result['roles'] ); } @@ -26,7 +26,7 @@ public function test_administrator() { $result = $this->myxmlrpcserver->wp_getProfile( array( 1, 'administrator', 'administrator' ) ); $this->assertNotIXRError( $result ); - $this->assertEquals( $administrator_id, $result['user_id'] ); + $this->assertSame( (string) $administrator_id, $result['user_id'] ); $this->assertContains( 'administrator', $result['roles'] ); } @@ -37,7 +37,7 @@ public function test_arbitrary_fields() { $result = $this->myxmlrpcserver->wp_getProfile( array( 1, 'editor', 'editor', $fields ) ); $this->assertNotIXRError( $result ); - $this->assertEquals( $editor_id, $result['user_id'] ); + $this->assertSame( (string) $editor_id, $result['user_id'] ); $expected_fields = array( 'user_id', 'email', 'bio' ); $keys = array_keys( $result ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getTerm.php b/tests/phpunit/tests/xmlrpc/wp/getTerm.php index 7eb1d3e2e4aff..c6ebe2645e449 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getTerm.php +++ b/tests/phpunit/tests/xmlrpc/wp/getTerm.php @@ -76,7 +76,12 @@ public function test_valid_term() { $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'editor', 'editor', 'category', self::$term_id ) ); $this->assertNotIXRError( $result ); - $this->assertEquals( $result, $term ); + /* + * This comparison stays loose: wp.getTerm returns the IDs as strings so that they + * cannot exceed what an XML-RPC integer can describe, while get_term() returns them + * as integers. The individual types are asserted below. + */ + $this->assertEquals( $term, $result ); // Check data types. $this->assertIsString( $result['name'] ); @@ -86,6 +91,10 @@ public function test_valid_term() { $this->assertIsInt( $result['count'] ); // We expect all ID's to be strings not integers so we don't return something larger than an XMLRPC integer can describe. + $this->assertIsString( $result['term_id'] ); + $this->assertIsString( $result['term_group'] ); + $this->assertIsString( $result['term_taxonomy_id'] ); + $this->assertIsString( $result['parent'] ); $this->assertStringMatchesFormat( '%d', $result['term_id'] ); $this->assertStringMatchesFormat( '%d', $result['term_group'] ); $this->assertStringMatchesFormat( '%d', $result['term_taxonomy_id'] ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getTerms.php b/tests/phpunit/tests/xmlrpc/wp/getTerms.php index d538a4efd2b8e..729a1e6b4ad2f 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getTerms.php +++ b/tests/phpunit/tests/xmlrpc/wp/getTerms.php @@ -143,7 +143,7 @@ public function test_terms_search() { $this->assertNotIXRError( $results ); $this->assertCount( 1, $results ); $this->assertSame( $name, $results[0]['name'] ); - $this->assertEquals( $name_id, $results[0]['term_id'] ); + $this->assertSame( (string) $name_id, $results[0]['term_id'] ); // Search by partial name. $filter = array( 'search' => substr( $name, 0, 10 ) ); @@ -151,6 +151,6 @@ public function test_terms_search() { $this->assertNotIXRError( $results2 ); $this->assertCount( 1, $results2 ); $this->assertSame( $name, $results2[0]['name'] ); - $this->assertEquals( $name_id, $results2[0]['term_id'] ); + $this->assertSame( (string) $name_id, $results2[0]['term_id'] ); } } diff --git a/tests/phpunit/tests/xmlrpc/wp/getUser.php b/tests/phpunit/tests/xmlrpc/wp/getUser.php index 8cfb34ae3e7eb..ca7a6bb6b1ba9 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getUser.php +++ b/tests/phpunit/tests/xmlrpc/wp/getUser.php @@ -43,7 +43,7 @@ public function test_subscriber_self() { $result = $this->myxmlrpcserver->wp_getUser( array( 1, 'subscriber', 'subscriber', $subscriber_id ) ); $this->assertNotIXRError( $result ); - $this->assertEquals( $subscriber_id, $result['user_id'] ); + $this->assertSame( (string) $subscriber_id, $result['user_id'] ); } public function test_valid_user() { @@ -83,7 +83,7 @@ public function test_valid_user() { $this->assertIsArray( $result['roles'] ); // Check expected values. - $this->assertEquals( $user_id, $result['user_id'] ); + $this->assertSame( (string) $user_id, $result['user_id'] ); $this->assertSame( $user_data['user_login'], $result['username'] ); $this->assertSame( $user_data['first_name'], $result['first_name'] ); $this->assertSame( $user_data['last_name'], $result['last_name'] ); @@ -105,7 +105,7 @@ public function test_no_fields() { $result = $this->myxmlrpcserver->wp_getUser( array( 1, 'administrator', 'administrator', $editor_id, array() ) ); $this->assertNotIXRError( $result ); - $this->assertEquals( $editor_id, $result['user_id'] ); + $this->assertSame( (string) $editor_id, $result['user_id'] ); $expected_fields = array( 'user_id' ); $this->assertSame( $expected_fields, array_keys( $result ) ); @@ -116,7 +116,7 @@ public function test_basic_fields() { $result = $this->myxmlrpcserver->wp_getUser( array( 1, 'administrator', 'administrator', $editor_id, array( 'basic' ) ) ); $this->assertNotIXRError( $result ); - $this->assertEquals( $editor_id, $result['user_id'] ); + $this->assertSame( (string) $editor_id, $result['user_id'] ); $expected_fields = array( 'user_id', 'username', 'email', 'registered', 'display_name', 'nicename' ); $keys = array_keys( $result ); @@ -132,7 +132,7 @@ public function test_arbitrary_fields() { $result = $this->myxmlrpcserver->wp_getUser( array( 1, 'administrator', 'administrator', $editor_id, $fields ) ); $this->assertNotIXRError( $result ); - $this->assertEquals( $editor_id, $result['user_id'] ); + $this->assertSame( (string) $editor_id, $result['user_id'] ); $expected_fields = array( 'user_id', 'email', 'bio' ); $keys = array_keys( $result ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getUsers.php b/tests/phpunit/tests/xmlrpc/wp/getUsers.php index a0eeee4026645..a442ad4969d92 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getUsers.php +++ b/tests/phpunit/tests/xmlrpc/wp/getUsers.php @@ -70,7 +70,7 @@ public function test_role_filter() { $results = $this->myxmlrpcserver->wp_getUsers( array( 1, 'administrator', 'administrator', $filter ) ); $this->assertNotIXRError( $results ); $this->assertCount( 1, $results ); - $this->assertEquals( $editor_id, $results[0]['user_id'] ); + $this->assertSame( (string) $editor_id, $results[0]['user_id'] ); // Test 'authors', which should return all non-subscribers. $filter2 = array( 'who' => 'authors' ); diff --git a/tests/phpunit/tests/xmlrpc/wp/newPost.php b/tests/phpunit/tests/xmlrpc/wp/newPost.php index b98b06c01d55b..c6386a1f23d5b 100644 --- a/tests/phpunit/tests/xmlrpc/wp/newPost.php +++ b/tests/phpunit/tests/xmlrpc/wp/newPost.php @@ -46,7 +46,8 @@ public function test_ignore_id() { ); $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); $this->assertNotIXRError( $result ); - $this->assertNotEquals( '103948', $result ); + $this->assertIsString( $result ); + $this->assertNotSame( '103948', $result ); } public function test_capable_publish() { @@ -141,7 +142,7 @@ public function test_empty_author() { $this->assertStringMatchesFormat( '%d', $result ); $out = get_post( $result ); - $this->assertEquals( $my_author_id, $out->post_author ); + $this->assertSame( (string) $my_author_id, $out->post_author ); $this->assertSame( 'Test', $out->post_title ); } @@ -163,7 +164,7 @@ public function test_post_thumbnail() { ); $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); $this->assertNotIXRError( $result ); - $this->assertEquals( $attachment_id, get_post_meta( $result, '_thumbnail_id', true ) ); + $this->assertSame( (string) $attachment_id, get_post_meta( $result, '_thumbnail_id', true ) ); remove_theme_support( 'post-thumbnails' ); }