Tests: Use more appropriate assertions in various tests.

This replaces instances of `assertTrue( ... > 0 )` with `assertGreaterThan()` to use native PHPUnit functionality.

Follow-up to [51335], [51337], [51367], [51397], [51403], [51404], [51436], [51438], [51448], [51449], [51451], [51453].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51454 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2021-07-18 14:10:24 +00:00
parent ba94d9b67b
commit 4a533f4879
10 changed files with 36 additions and 33 deletions

View File

@@ -55,7 +55,7 @@ class Tests_Bookmark_GetBookmarks extends WP_UnitTestCase {
);
$this->assertEqualSets( $bookmarks, wp_list_pluck( $found2, 'link_id' ) );
$this->assertTrue( $num_queries < $wpdb->num_queries );
$this->assertGreaterThan( $num_queries, $wpdb->num_queries );
}
/**
@@ -82,7 +82,7 @@ class Tests_Bookmark_GetBookmarks extends WP_UnitTestCase {
// Equal sets != same order.
$this->assertEqualSets( $found1, $found2 );
$this->assertTrue( $num_queries < $wpdb->num_queries );
$this->assertGreaterThan( $num_queries, $wpdb->num_queries );
}
public function test_exclude_param_gets_properly_parsed_as_list() {

View File

@@ -126,15 +126,15 @@ class Tests_Cron extends WP_UnitTestCase {
wp_schedule_single_event( strtotime( '+4 hour' ), $hook, $args );
// Make sure they're returned by wp_next_scheduled().
$this->assertTrue( wp_next_scheduled( $hook ) > 0 );
$this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
$this->assertGreaterThan( 0, wp_next_scheduled( $hook ) );
$this->assertGreaterThan( 0, wp_next_scheduled( $hook, $args ) );
// Clear the schedule for the no args events and make sure it's gone.
$hook_unscheduled = wp_clear_scheduled_hook( $hook );
$this->assertSame( 2, $hook_unscheduled );
$this->assertFalse( wp_next_scheduled( $hook ) );
// The args events should still be there.
$this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
$this->assertGreaterThan( 0, wp_next_scheduled( $hook, $args ) );
// Clear the schedule for the args events and make sure they're gone too.
// Note: wp_clear_scheduled_hook() expects args passed directly, rather than as an array.
@@ -165,14 +165,14 @@ class Tests_Cron extends WP_UnitTestCase {
wp_schedule_single_event( strtotime( '+4 hour' ), $hook, $args );
// Make sure they're returned by wp_next_scheduled().
$this->assertTrue( wp_next_scheduled( $hook ) > 0 );
$this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
$this->assertGreaterThan( 0, wp_next_scheduled( $hook ) );
$this->assertGreaterThan( 0, wp_next_scheduled( $hook, $args ) );
// Clear the schedule for the no args events and make sure it's gone.
wp_clear_scheduled_hook( $hook );
$this->assertFalse( wp_next_scheduled( $hook ) );
// The args events should still be there.
$this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
$this->assertGreaterThan( 0, wp_next_scheduled( $hook, $args ) );
// Clear the schedule for the args events and make sure they're gone too.
// Note: wp_clear_scheduled_hook() used to expect args passed directly, rather than as an array pre WP 3.0.
@@ -198,14 +198,14 @@ class Tests_Cron extends WP_UnitTestCase {
wp_schedule_single_event( strtotime( '+6 hour' ), $multi_hook, $multi_args );
// Make sure they're returned by wp_next_scheduled().
$this->assertTrue( wp_next_scheduled( $hook ) > 0 );
$this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
$this->assertGreaterThan( 0, wp_next_scheduled( $hook ) );
$this->assertGreaterThan( 0, wp_next_scheduled( $hook, $args ) );
// Clear the schedule for the no args events and make sure it's gone.
wp_clear_scheduled_hook( $hook );
$this->assertFalse( wp_next_scheduled( $hook ) );
// The args events should still be there.
$this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
$this->assertGreaterThan( 0, wp_next_scheduled( $hook, $args ) );
// Clear the schedule for the args events and make sure they're gone too.
// wp_clear_scheduled_hook() should take args as an array like the other functions.
@@ -232,8 +232,8 @@ class Tests_Cron extends WP_UnitTestCase {
wp_schedule_single_event( strtotime( '+4 hour' ), $hook, $args );
// Make sure they're returned by wp_next_scheduled().
$this->assertTrue( wp_next_scheduled( $hook ) > 0 );
$this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
$this->assertGreaterThan( 0, wp_next_scheduled( $hook ) );
$this->assertGreaterThan( 0, wp_next_scheduled( $hook, $args ) );
// Clear the schedule and make sure it's gone.
$unschedule_hook = wp_unschedule_hook( $hook );

View File

@@ -344,7 +344,7 @@ class Tests_Meta extends WP_UnitTestCase {
function test_negative_meta_id() {
$negative_mid = $this->meta_id * -1;
$this->assertTrue( $negative_mid < 0 );
$this->assertLessThan( 0, $negative_mid );
$this->assertFalse( get_metadata_by_mid( 'user', $negative_mid ) );
$this->assertFalse( update_metadata_by_mid( 'user', $negative_mid, 'meta_new_value' ) );
$this->assertFalse( delete_metadata_by_mid( 'user', $negative_mid ) );

View File

@@ -451,7 +451,8 @@ if ( is_multisite() ) :
$site_count = (int) get_blog_count();
$user_count = (int) get_user_count();
$this->assertTrue( $site_count > 0 && $user_count > 0 );
$this->assertGreaterThan( 0, $site_count );
$this->assertGreaterThan( 0, $user_count );
}
/**
@@ -466,7 +467,8 @@ if ( is_multisite() ) :
$site_count = (int) get_blog_count( self::$different_network_id );
$user_count = (int) get_user_count( self::$different_network_id );
$this->assertTrue( $site_count > 0 && $user_count > 0 );
$this->assertGreaterThan( 0, $site_count );
$this->assertGreaterThan( 0, $user_count );
}
/**

View File

@@ -80,7 +80,7 @@ class Tests_Post extends WP_UnitTestCase {
// Insert a post and make sure the ID is OK.
$id = wp_insert_post( $post );
$this->assertIsNumeric( $id );
$this->assertTrue( $id > 0 );
$this->assertGreaterThan( 0, $id );
// Fetch the post and make sure it matches.
$out = get_post( $id );
@@ -136,7 +136,7 @@ class Tests_Post extends WP_UnitTestCase {
$this->post_ids[] = $id;
// dmp( _get_cron_array() );
$this->assertIsNumeric( $id );
$this->assertTrue( $id > 0 );
$this->assertGreaterThan( 0, $id );
// Fetch the post and make sure it matches.
$out = get_post( $id );
@@ -259,7 +259,7 @@ class Tests_Post extends WP_UnitTestCase {
$this->post_ids[] = $id;
// dmp( _get_cron_array() );
$this->assertIsNumeric( $id );
$this->assertTrue( $id > 0 );
$this->assertGreaterThan( 0, $id );
// Fetch the post and make sure it matches.
$out = get_post( $id );
@@ -380,7 +380,7 @@ class Tests_Post extends WP_UnitTestCase {
$this->post_ids[] = $id;
// dmp( _get_cron_array() );
$this->assertIsNumeric( $id );
$this->assertTrue( $id > 0 );
$this->assertGreaterThan( 0, $id );
// Fetch the post and make sure it matches.
$out = get_post( $id );
@@ -793,7 +793,8 @@ class Tests_Post extends WP_UnitTestCase {
),
);
$insert_post_id = wp_insert_post( $post_data, true, true );
$this->assertTrue( ( is_int( $insert_post_id ) && $insert_post_id > 0 ) );
$this->assertIsInt( $insert_post_id );
$this->assertGreaterThan( 0, $insert_post_id );
$post = get_post( $insert_post_id );
$this->assertEquals( $post->post_author, self::$editor_id );

View File

@@ -513,7 +513,7 @@ class WP_Test_REST_Controller extends WP_Test_REST_TestCase {
$first_call_count = $listener->get_call_count( $method );
$this->assertTrue( $first_call_count > 0 );
$this->assertGreaterThan( 0, $first_call_count );
$request->set_param( '_fields', 'somestring' );
@@ -525,7 +525,7 @@ class WP_Test_REST_Controller extends WP_Test_REST_TestCase {
$controller->prepare_item_for_response( $item, $request );
$this->assertTrue( $listener->get_call_count( $method ) > $first_call_count );
$this->assertGreaterThan( $first_call_count, $listener->get_call_count( $method ) );
}
/**

View File

@@ -155,12 +155,12 @@ class Tests_Term extends WP_UnitTestCase {
$t = wp_insert_category( array( 'cat_name' => $term ) );
$this->assertIsNumeric( $t );
$this->assertNotWPError( $t );
$this->assertTrue( $t > 0 );
$this->assertGreaterThan( 0, $t );
$this->assertEquals( $initial_count + 1, wp_count_terms( array( 'taxonomy' => 'category' ) ) );
// Make sure the term exists.
$this->assertTrue( term_exists( $term ) > 0 );
$this->assertTrue( term_exists( $t ) > 0 );
$this->assertGreaterThan( 0, term_exists( $term ) );
$this->assertGreaterThan( 0, term_exists( $t ) );
// Now delete it.
$this->assertTrue( wp_delete_category( $t ) );

View File

@@ -29,13 +29,13 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase {
$t = wp_insert_term( $term, $taxonomy );
$this->assertIsArray( $t );
$this->assertNotWPError( $t );
$this->assertTrue( $t['term_id'] > 0 );
$this->assertTrue( $t['term_taxonomy_id'] > 0 );
$this->assertGreaterThan( 0, $t['term_id'] );
$this->assertGreaterThan( 0, $t['term_taxonomy_id'] );
$this->assertEquals( $initial_count + 1, wp_count_terms( array( 'taxonomy' => $taxonomy ) ) );
// Make sure the term exists.
$this->assertTrue( term_exists( $term ) > 0 );
$this->assertTrue( term_exists( $t['term_id'] ) > 0 );
$this->assertGreaterThan( 0, term_exists( $term ) );
$this->assertGreaterThan( 0, term_exists( $t['term_id'] ) );
// Now delete it.
add_filter( 'delete_term', array( $this, 'deleted_term_cb' ), 10, 5 );

View File

@@ -140,7 +140,7 @@ class Tests_Theme extends WP_UnitTestCase {
// Important attributes should all not be empty as well.
$this->assertNotEmpty( $theme['Description'] );
$this->assertNotEmpty( $theme['Author'] );
$this->assertTrue( version_compare( $theme['Version'], 0 ) > 0 );
$this->assertGreaterThan( 0, version_compare( $theme['Version'], 0 ) );
$this->assertNotEmpty( $theme['Template'] );
$this->assertNotEmpty( $theme['Stylesheet'] );

View File

@@ -68,7 +68,7 @@ class Tests_User_WpDeleteUser extends WP_UnitTestCase {
// Insert a post and make sure the ID is OK.
$post_id = wp_insert_post( $post );
$this->assertIsNumeric( $post_id );
$this->assertTrue( $post_id > 0 );
$this->assertGreaterThan( 0, $post_id );
$post = get_post( $post_id );
$this->assertSame( $post_id, $post->ID );
@@ -84,7 +84,7 @@ class Tests_User_WpDeleteUser extends WP_UnitTestCase {
// Insert a post and make sure the ID is OK.
$nav_id = wp_insert_post( $post );
$this->assertIsNumeric( $nav_id );
$this->assertTrue( $nav_id > 0 );
$this->assertGreaterThan( 0, $nav_id );
$post = get_post( $nav_id );
$this->assertSame( $nav_id, $post->ID );