Tests: Use more appropriate assertions in various tests.

This replaces instances of `assertSame( [number], count( ... ) )` with `assertCount()` to use native PHPUnit functionality.

Follow-up to [51335], [51337].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51367 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2021-07-07 10:32:56 +00:00
parent b1f0971ee3
commit e77691036d
63 changed files with 291 additions and 291 deletions

View File

@@ -101,19 +101,19 @@ class Tests_Term extends WP_UnitTestCase {
$tags = self::factory()->tag->create_many( 5 );
$tt = wp_add_object_terms( $posts[0], $tags[1], 'post_tag' );
$this->assertSame( 1, count( $tt ) );
$this->assertCount( 1, $tt );
$this->assertSame( array( $tags[1] ), wp_get_object_terms( $posts[0], 'post_tag', array( 'fields' => 'ids' ) ) );
$three_tags = array( $tags[0], $tags[1], $tags[2] );
$tt = wp_add_object_terms( $posts[1], $three_tags, 'post_tag' );
$this->assertSame( 3, count( $tt ) );
$this->assertCount( 3, $tt );
$this->assertSame( $three_tags, wp_get_object_terms( $posts[1], 'post_tag', array( 'fields' => 'ids' ) ) );
$this->assertTrue( wp_remove_object_terms( $posts[0], $tags[1], 'post_tag' ) );
$this->assertFalse( wp_remove_object_terms( $posts[0], $tags[0], 'post_tag' ) );
$this->assertInstanceOf( 'WP_Error', wp_remove_object_terms( $posts[0], $tags[1], 'non_existing_taxonomy' ) );
$this->assertTrue( wp_remove_object_terms( $posts[1], $three_tags, 'post_tag' ) );
$this->assertSame( 0, count( wp_get_object_terms( $posts[1], 'post_tag' ) ) );
$this->assertCount( 0, wp_get_object_terms( $posts[1], 'post_tag' ) );
foreach ( $tags as $term_id ) {
$this->assertTrue( wp_delete_term( $term_id, 'post_tag' ) );
@@ -177,7 +177,7 @@ class Tests_Term extends WP_UnitTestCase {
$post = get_post( $post_id );
$this->assertIsArray( $post->post_category );
$this->assertSame( 1, count( $post->post_category ) );
$this->assertCount( 1, $post->post_category );
$this->assertEquals( get_option( 'default_category' ), $post->post_category[0] );
$term1 = wp_insert_term( 'Foo', 'category' );
@@ -185,7 +185,7 @@ class Tests_Term extends WP_UnitTestCase {
$term3 = wp_insert_term( 'Baz', 'category' );
wp_set_post_categories( $post_id, array( $term1['term_id'], $term2['term_id'] ) );
$this->assertSame( 2, count( $post->post_category ) );
$this->assertCount( 2, $post->post_category );
$this->assertSame( array( $term2['term_id'], $term1['term_id'] ), $post->post_category );
wp_set_post_categories( $post_id, $term3['term_id'], true );
@@ -200,11 +200,11 @@ class Tests_Term extends WP_UnitTestCase {
$this->assertSame( array( $term2['term_id'], $term4['term_id'], $term1['term_id'] ), $post->post_category );
wp_set_post_categories( $post_id, array(), true );
$this->assertSame( 1, count( $post->post_category ) );
$this->assertCount( 1, $post->post_category );
$this->assertEquals( get_option( 'default_category' ), $post->post_category[0] );
wp_set_post_categories( $post_id, array() );
$this->assertSame( 1, count( $post->post_category ) );
$this->assertCount( 1, $post->post_category );
$this->assertEquals( get_option( 'default_category' ), $post->post_category[0] );
}