mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Tests: Use more appropriate assertions in various tests.
This replaces instances of `assertTrue( empty( ... ) )` with `assertEmpty()` to use native PHPUnit functionality. Follow-up to [51335], [51337], [51367], [51397]. See #53363. git-svn-id: https://develop.svn.wordpress.org/trunk@51403 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -279,7 +279,7 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
$this->assertSame( $args[0][0], $obj );
|
||||
// Just in case we don't trust assertSame().
|
||||
$obj->foo = true;
|
||||
$this->assertFalse( empty( $args[0][0]->foo ) );
|
||||
$this->assertNotEmpty( $args[0][0]->foo );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -231,7 +231,7 @@ class Tests_Filters extends WP_UnitTestCase {
|
||||
$this->assertSame( $args[0][0], $obj );
|
||||
// Just in case we don't trust assertSame().
|
||||
$obj->foo = true;
|
||||
$this->assertFalse( empty( $args[0][0]->foo ) );
|
||||
$this->assertNotEmpty( $args[0][0]->foo );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,13 +254,13 @@ class Tests_Filters extends WP_UnitTestCase {
|
||||
$this->assertSame( $args[0][1], $obj );
|
||||
// Just in case we don't trust assertSame().
|
||||
$obj->foo = true;
|
||||
$this->assertFalse( empty( $args[0][1]->foo ) );
|
||||
$this->assertNotEmpty( $args[0][1]->foo );
|
||||
|
||||
$args = $b->get_args();
|
||||
$this->assertSame( $args[0][1], $obj );
|
||||
// Just in case we don't trust assertSame().
|
||||
$obj->foo = true;
|
||||
$this->assertFalse( empty( $args[0][1]->foo ) );
|
||||
$this->assertNotEmpty( $args[0][1]->foo );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -225,7 +225,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
|
||||
|
||||
$this->skipTestOnTimeout( $res );
|
||||
$this->assertSame( 'PASS', wp_remote_retrieve_body( $res ) );
|
||||
$this->assertTrue( ! empty( $res['headers']['location'] ) );
|
||||
$this->assertNotEmpty( $res['headers']['location'] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,7 @@ abstract class WP_Import_UnitTestCase extends WP_UnitTestCase {
|
||||
$importer = new WP_Import();
|
||||
$file = realpath( $filename );
|
||||
|
||||
$this->assertTrue( ! empty( $file ), 'Path to import file is empty.' );
|
||||
$this->assertNotEmpty( $file, 'Path to import file is empty.' );
|
||||
$this->assertTrue( is_file( $file ), 'Import file is not a file.' );
|
||||
|
||||
$authors = array();
|
||||
|
||||
@@ -18,7 +18,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$contents = rand_str();
|
||||
|
||||
$upload = wp_upload_bits( $filename, null, $contents );
|
||||
$this->assertTrue( empty( $upload['error'] ) );
|
||||
$this->assertEmpty( $upload['error'] );
|
||||
}
|
||||
|
||||
function test_insert_image_no_thumb() {
|
||||
@@ -28,7 +28,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$contents = file_get_contents( $filename );
|
||||
|
||||
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
|
||||
$this->assertTrue( empty( $upload['error'] ) );
|
||||
$this->assertEmpty( $upload['error'] );
|
||||
|
||||
$id = $this->_make_attachment( $upload );
|
||||
|
||||
@@ -65,7 +65,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$contents = file_get_contents( $filename );
|
||||
|
||||
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
|
||||
$this->assertTrue( empty( $upload['error'] ) );
|
||||
$this->assertEmpty( $upload['error'] );
|
||||
|
||||
$id = $this->_make_attachment( $upload );
|
||||
|
||||
@@ -119,7 +119,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$contents = file_get_contents( $filename );
|
||||
|
||||
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
|
||||
$this->assertTrue( empty( $upload['error'] ) );
|
||||
$this->assertEmpty( $upload['error'] );
|
||||
|
||||
$id = $this->_make_attachment( $upload );
|
||||
$uploads = wp_upload_dir();
|
||||
@@ -176,7 +176,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$contents = file_get_contents( $filename );
|
||||
|
||||
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
|
||||
$this->assertTrue( empty( $upload['error'] ) );
|
||||
$this->assertEmpty( $upload['error'] );
|
||||
|
||||
$id = $this->_make_attachment( $upload );
|
||||
$uploads = wp_upload_dir();
|
||||
@@ -219,13 +219,13 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$contents = file_get_contents( $filename );
|
||||
|
||||
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
|
||||
$this->assertTrue( empty( $upload['error'] ) );
|
||||
$this->assertEmpty( $upload['error'] );
|
||||
|
||||
$upload['url'] = '';
|
||||
$id = $this->_make_attachment( $upload );
|
||||
|
||||
$guid = get_the_guid( $id );
|
||||
$this->assertFalse( empty( $guid ) );
|
||||
$this->assertNotEmpty( $guid );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,7 +236,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$contents = file_get_contents( $filename );
|
||||
|
||||
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
|
||||
$this->assertTrue( empty( $upload['error'] ) );
|
||||
$this->assertEmpty( $upload['error'] );
|
||||
|
||||
$id = $this->_make_attachment( $upload );
|
||||
|
||||
@@ -262,7 +262,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$contents = file_get_contents( $filename );
|
||||
|
||||
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
|
||||
$this->assertTrue( empty( $upload['error'] ) );
|
||||
$this->assertEmpty( $upload['error'] );
|
||||
|
||||
$attachment_id = $this->_make_attachment( $upload );
|
||||
|
||||
@@ -294,7 +294,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$contents = file_get_contents( $filename );
|
||||
|
||||
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
|
||||
$this->assertTrue( empty( $upload['error'] ) );
|
||||
$this->assertEmpty( $upload['error'] );
|
||||
|
||||
// Set attachment ID.
|
||||
$attachment_id = $this->_make_attachment( $upload );
|
||||
@@ -319,7 +319,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$contents = file_get_contents( $filename );
|
||||
|
||||
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
|
||||
$this->assertTrue( empty( $upload['error'] ) );
|
||||
$this->assertEmpty( $upload['error'] );
|
||||
|
||||
// Set attachment ID.
|
||||
$attachment_id = $this->_make_attachment( $upload );
|
||||
@@ -344,7 +344,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$contents = file_get_contents( $filename );
|
||||
|
||||
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
|
||||
$this->assertTrue( empty( $upload['error'] ) );
|
||||
$this->assertEmpty( $upload['error'] );
|
||||
|
||||
// Set attachment ID.
|
||||
$attachment_id = $this->_make_attachment( $upload );
|
||||
@@ -372,7 +372,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$contents = file_get_contents( $filename );
|
||||
|
||||
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
|
||||
$this->assertTrue( empty( $upload['error'] ) );
|
||||
$this->assertEmpty( $upload['error'] );
|
||||
|
||||
// Set attachment ID.
|
||||
$attachment_id = $this->_make_attachment( $upload );
|
||||
@@ -400,7 +400,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$contents = file_get_contents( $filename );
|
||||
|
||||
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
|
||||
$this->assertTrue( empty( $upload['error'] ) );
|
||||
$this->assertEmpty( $upload['error'] );
|
||||
|
||||
// Set attachment ID.
|
||||
$attachment_id = $this->_make_attachment( $upload );
|
||||
@@ -427,7 +427,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$contents = file_get_contents( $filename );
|
||||
|
||||
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
|
||||
$this->assertTrue( empty( $upload['error'] ) );
|
||||
$this->assertEmpty( $upload['error'] );
|
||||
|
||||
// Set attachment ID.
|
||||
$attachment_id = $this->_make_attachment( $upload );
|
||||
|
||||
@@ -317,7 +317,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
$this->go_to( get_permalink( $post1 ) );
|
||||
setup_postdata( $post2 );
|
||||
|
||||
$this->assertTrue( empty( $GLOBALS['more'] ) );
|
||||
$this->assertEmpty( $GLOBALS['more'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -335,7 +335,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
$this->go_to( get_permalink( $page ) );
|
||||
setup_postdata( $post );
|
||||
|
||||
$this->assertTrue( empty( $GLOBALS['more'] ) );
|
||||
$this->assertEmpty( $GLOBALS['more'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -372,7 +372,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
$q->the_post();
|
||||
|
||||
// $more should refer to the current loop.
|
||||
$this->assertTrue( empty( $GLOBALS['more'] ) );
|
||||
$this->assertEmpty( $GLOBALS['more'] );
|
||||
}
|
||||
}
|
||||
wp_reset_postdata();
|
||||
|
||||
@@ -478,7 +478,7 @@ class REST_Block_Renderer_Controller_Test extends WP_Test_REST_Controller_Testca
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertTrue( empty( $data['rendered'] ) );
|
||||
$this->assertEmpty( $data['rendered'] );
|
||||
|
||||
// Now test with post ID.
|
||||
$request->set_param( 'post_id', self::$post_id );
|
||||
|
||||
@@ -73,7 +73,7 @@ class WP_Test_REST_Schema_Initialization extends WP_Test_REST_TestCase {
|
||||
$routes = rest_get_server()->get_routes();
|
||||
|
||||
$this->assertIsArray( $routes, '`get_routes` should return an array.' );
|
||||
$this->assertTrue( ! empty( $routes ), 'Routes should not be empty.' );
|
||||
$this->assertNotEmpty( $routes, 'Routes should not be empty.' );
|
||||
|
||||
$routes = array_filter( array_keys( $routes ), array( $this, 'is_builtin_route' ) );
|
||||
|
||||
@@ -472,7 +472,7 @@ class WP_Test_REST_Schema_Initialization extends WP_Test_REST_TestCase {
|
||||
$response->get_status(),
|
||||
"HTTP $status from $route[route]: " . json_encode( $data )
|
||||
);
|
||||
$this->assertTrue( ! empty( $data ), $route['name'] . ' route should return data.' );
|
||||
$this->assertNotEmpty( $data, $route['name'] . ' route should return data.' );
|
||||
|
||||
$fixture = $this->normalize_fixture( $data, $route['name'] );
|
||||
$mocked_responses .= "\nmockedApiResponse." . $route['name'] . ' = '
|
||||
|
||||
@@ -260,7 +260,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$rest_post_types = array_values( get_post_types( array( 'show_in_rest' => true ), 'names' ) );
|
||||
|
||||
foreach ( $users as $user ) {
|
||||
$this->assertTrue( count_user_posts( $user['id'], $rest_post_types ) > 0 );
|
||||
$this->assertNotEmpty( count_user_posts( $user['id'], $rest_post_types ) );
|
||||
|
||||
// Ensure we don't expose non-public data.
|
||||
$this->assertArrayNotHasKey( 'capabilities', $user );
|
||||
|
||||
@@ -187,7 +187,7 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase {
|
||||
public function test_wp_insert_term_duplicate_name() {
|
||||
$term = self::factory()->tag->create_and_get( array( 'name' => 'Bozo' ) );
|
||||
$this->assertNotWPError( $term );
|
||||
$this->assertTrue( empty( $term->errors ) );
|
||||
$this->assertEmpty( $term->errors );
|
||||
|
||||
// Test existing term name with unique slug.
|
||||
$term1 = self::factory()->tag->create(
|
||||
|
||||
@@ -288,7 +288,7 @@ class Tests_Theme extends WP_UnitTestCase {
|
||||
$this->assertTrue( is_dir( $root_fs ) );
|
||||
|
||||
$root_uri = get_theme_root_uri();
|
||||
$this->assertTrue( ! empty( $root_uri ) );
|
||||
$this->assertNotEmpty( $root_uri );
|
||||
|
||||
$this->assertSame( $root_fs . '/' . get_stylesheet(), get_stylesheet_directory() );
|
||||
$this->assertSame( $root_uri . '/' . get_stylesheet(), get_stylesheet_directory_uri() );
|
||||
|
||||
@@ -45,7 +45,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase {
|
||||
$theme = get_theme( 'WordPress Default' );
|
||||
$this->assertSame( $themes['WordPress Default'], $theme );
|
||||
|
||||
$this->assertFalse( empty( $theme ) );
|
||||
$this->assertNotEmpty( $theme );
|
||||
|
||||
// echo gen_tests_array( 'theme', $theme );
|
||||
|
||||
@@ -74,7 +74,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase {
|
||||
function test_theme_sandbox() {
|
||||
$theme = get_theme( 'Sandbox' );
|
||||
|
||||
$this->assertFalse( empty( $theme ) );
|
||||
$this->assertNotEmpty( $theme );
|
||||
|
||||
// echo gen_tests_array( 'theme', $theme );
|
||||
|
||||
@@ -111,7 +111,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase {
|
||||
$themes = get_themes();
|
||||
|
||||
$theme = $themes['Stylesheet Only'];
|
||||
$this->assertFalse( empty( $theme ) );
|
||||
$this->assertNotEmpty( $theme );
|
||||
|
||||
// echo gen_tests_array( 'theme', $theme );
|
||||
|
||||
@@ -205,7 +205,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase {
|
||||
$themes = get_themes();
|
||||
|
||||
$theme = $themes['Page Template Theme'];
|
||||
$this->assertFalse( empty( $theme ) );
|
||||
$this->assertNotEmpty( $theme );
|
||||
|
||||
$templates = $theme['Template Files'];
|
||||
$this->assertTrue( in_array( $this->theme_root . '/page-templates/template-top-level.php', $templates, true ) );
|
||||
|
||||
Reference in New Issue
Block a user