From 3bb3d7a6c7ecd00136f435c21d126681637e5b18 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 20 Mar 2018 22:34:11 +0000 Subject: [PATCH] Build/Test Tools: Implement `assertNotWPError()` in appropriate places in the test suite. Props birgire Fixes #42065 git-svn-id: https://develop.svn.wordpress.org/trunk@42863 602fd350-edb4-49c9-b593-d223f7449a82 --- .../testcase-rest-post-type-controller.php | 8 ++++---- tests/phpunit/tests/admin/includesPost.php | 12 ++++++------ tests/phpunit/tests/ajax/CustomizeManager.php | 4 ++-- tests/phpunit/tests/customize/manager.php | 2 +- .../phpunit/tests/customize/nav-menu-setting.php | 2 +- tests/phpunit/tests/image/editorGd.php | 6 +++--- tests/phpunit/tests/image/editorImagick.php | 6 +++--- tests/phpunit/tests/image/functions.php | 12 ++++++------ tests/phpunit/tests/post/formats.php | 16 ++++++++-------- 9 files changed, 34 insertions(+), 34 deletions(-) diff --git a/tests/phpunit/includes/testcase-rest-post-type-controller.php b/tests/phpunit/includes/testcase-rest-post-type-controller.php index afba4c92d6..1336074840 100644 --- a/tests/phpunit/includes/testcase-rest-post-type-controller.php +++ b/tests/phpunit/includes/testcase-rest-post-type-controller.php @@ -200,7 +200,7 @@ abstract class WP_Test_REST_Post_Type_Controller_Testcase extends WP_Test_REST_C } protected function check_get_posts_response( $response, $context = 'view' ) { - $this->assertNotInstanceOf( 'WP_Error', $response ); + $this->assertNotWPError( $response ); $response = rest_ensure_response( $response ); $this->assertEquals( 200, $response->get_status() ); @@ -232,7 +232,7 @@ abstract class WP_Test_REST_Post_Type_Controller_Testcase extends WP_Test_REST_C } protected function check_get_post_response( $response, $context = 'view' ) { - $this->assertNotInstanceOf( 'WP_Error', $response ); + $this->assertNotWPError( $response ); $response = rest_ensure_response( $response ); $this->assertEquals( 200, $response->get_status() ); @@ -243,7 +243,7 @@ abstract class WP_Test_REST_Post_Type_Controller_Testcase extends WP_Test_REST_C } protected function check_create_post_response( $response ) { - $this->assertNotInstanceOf( 'WP_Error', $response ); + $this->assertNotWPError( $response ); $response = rest_ensure_response( $response ); $this->assertEquals( 201, $response->get_status() ); @@ -256,7 +256,7 @@ abstract class WP_Test_REST_Post_Type_Controller_Testcase extends WP_Test_REST_C } protected function check_update_post_response( $response ) { - $this->assertNotInstanceOf( 'WP_Error', $response ); + $this->assertNotWPError( $response ); $response = rest_ensure_response( $response ); $this->assertEquals( 200, $response->get_status() ); diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index 5c080f2ed6..a9c5f46856 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -32,7 +32,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase { $_post_data['saveasdraft'] = true; $_results = _wp_translate_postdata( false, $_post_data ); - $this->assertNotInstanceOf( 'WP_Error', $_results ); + $this->assertNotWPError( $_results ); $this->assertEquals( $_post_data['post_author'], $_results['post_author'] ); $this->assertEquals( 'draft', $_results['post_status'] ); @@ -43,7 +43,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase { $_post_data['publish'] = true; $_results = _wp_translate_postdata( false, $_post_data ); - $this->assertNotInstanceOf( 'WP_Error', $_results ); + $this->assertNotWPError( $_results ); $this->assertEquals( $_post_data['post_author'], $_results['post_author'] ); $this->assertEquals( 'pending', $_results['post_status'] ); @@ -82,7 +82,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase { $_post_data['saveasdraft'] = true; $_results = _wp_translate_postdata( false, $_post_data ); - $this->assertNotInstanceOf( 'WP_Error', $_results ); + $this->assertNotWPError( $_results ); $this->assertEquals( $_post_data['post_author'], $_results['post_author'] ); $this->assertEquals( 'draft', $_results['post_status'] ); @@ -93,7 +93,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase { $_post_data['publish'] = true; $_results = _wp_translate_postdata( false, $_post_data ); - $this->assertNotInstanceOf( 'WP_Error', $_results ); + $this->assertNotWPError( $_results ); $this->assertEquals( $_post_data['post_author'], $_results['post_author'] ); $this->assertEquals( 'publish', $_results['post_status'] ); @@ -104,7 +104,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase { $_post_data['saveasdraft'] = true; $_results = _wp_translate_postdata( false, $_post_data ); - $this->assertNotInstanceOf( 'WP_Error', $_results ); + $this->assertNotWPError( $_results ); $this->assertEquals( $_post_data['post_author'], $_results['post_author'] ); $this->assertEquals( 'draft', $_results['post_status'] ); @@ -117,7 +117,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase { $_post_data['saveasdraft'] = true; $_results = _wp_translate_postdata( true, $_post_data ); - $this->assertNotInstanceOf( 'WP_Error', $_results ); + $this->assertNotWPError( $_results ); $this->assertEquals( $_post_data['post_author'], $_results['post_author'] ); $this->assertEquals( 'draft', $_results['post_status'] ); } diff --git a/tests/phpunit/tests/ajax/CustomizeManager.php b/tests/phpunit/tests/ajax/CustomizeManager.php index 933b9920ec..873d017fc1 100644 --- a/tests/phpunit/tests/ajax/CustomizeManager.php +++ b/tests/phpunit/tests/ajax/CustomizeManager.php @@ -645,7 +645,7 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase { $this->assertEquals( 'changeset_lock_dismissed', $this->_last_response_parsed['data'] ); $_POST['dismiss_autosave'] = $_GET['dismiss_autosave'] = $_REQUEST['dismiss_autosave'] = true; - $this->assertNotInstanceOf( 'WP_Error', $r ); + $this->assertNotWPError( $r ); $this->assertFalse( wp_get_post_autosave( $wp_customize->changeset_post_id() ) ); $this->assertContains( 'Foo', get_post( $wp_customize->changeset_post_id() )->post_content ); @@ -665,7 +665,7 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase { 'autosave' => true, ) ); - $this->assertNotInstanceOf( 'WP_Error', $r ); + $this->assertNotWPError( $r ); $autosave_revision = wp_get_post_autosave( $wp_customize->changeset_post_id() ); $this->assertInstanceOf( 'WP_Post', $autosave_revision ); $this->assertContains( 'Foo', get_post( $wp_customize->changeset_post_id() )->post_content ); diff --git a/tests/phpunit/tests/customize/manager.php b/tests/phpunit/tests/customize/manager.php index 80cf0c9b2a..aad5d1f56d 100644 --- a/tests/phpunit/tests/customize/manager.php +++ b/tests/phpunit/tests/customize/manager.php @@ -495,7 +495,7 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase { 'autosave' => true, ) ); - $this->assertNotInstanceOf( 'WP_Error', $r ); + $this->assertNotWPError( $r ); // No change to data if not requesting autosave. $wp_customize = new WP_Customize_Manager( diff --git a/tests/phpunit/tests/customize/nav-menu-setting.php b/tests/phpunit/tests/customize/nav-menu-setting.php index b33b17c404..cf56900309 100644 --- a/tests/phpunit/tests/customize/nav-menu-setting.php +++ b/tests/phpunit/tests/customize/nav-menu-setting.php @@ -253,7 +253,7 @@ class Test_WP_Customize_Nav_Menu_Setting extends WP_UnitTestCase { $term = (array) wp_get_nav_menu_object( $menu_id ); $this->assertNotEmpty( $term ); - $this->assertNotInstanceOf( 'WP_Error', $term ); + $this->assertNotWPError( $term ); $this->assertEqualSets( $post_value, wp_array_slice_assoc( $term, array_keys( $value ) ) ); $this->assertEquals( $menu_id, $term['term_id'] ); $this->assertEquals( $menu_id, $term['term_taxonomy_id'] ); diff --git a/tests/phpunit/tests/image/editorGd.php b/tests/phpunit/tests/image/editorGd.php index 5be8fc9385..fdd0e9c96a 100644 --- a/tests/phpunit/tests/image/editorGd.php +++ b/tests/phpunit/tests/image/editorGd.php @@ -476,7 +476,7 @@ class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { $editor = wp_get_image_editor( $file ); - $this->assertNotInstanceOf( 'WP_Error', $editor ); + $this->assertNotWPError( $editor ); $editor->load(); $editor->resize( 5, 5 ); @@ -503,7 +503,7 @@ class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { $editor = wp_get_image_editor( $file ); - $this->assertNotInstanceOf( 'WP_Error', $editor ); + $this->assertNotWPError( $editor ); $editor->load(); @@ -531,7 +531,7 @@ class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { $expected = imagecolorsforindex( $image, $rgb ); $editor = new WP_Image_Editor_GD( $file ); - $this->assertNotInstanceOf( 'WP_Error', $editor ); + $this->assertNotWPError( $editor ); $editor->load(); $editor->rotate( 180 ); $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; diff --git a/tests/phpunit/tests/image/editorImagick.php b/tests/phpunit/tests/image/editorImagick.php index fb88f3346d..f62ad39815 100644 --- a/tests/phpunit/tests/image/editorImagick.php +++ b/tests/phpunit/tests/image/editorImagick.php @@ -465,7 +465,7 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { $editor = new WP_Image_Editor_Imagick( $file ); - $this->assertNotInstanceOf( 'WP_Error', $editor ); + $this->assertNotWPError( $editor ); $editor->load(); $editor->resize( 5, 5 ); @@ -492,7 +492,7 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { $editor = new WP_Image_Editor_Imagick( $file ); - $this->assertNotInstanceOf( 'WP_Error', $editor ); + $this->assertNotWPError( $editor ); $editor->load(); @@ -524,7 +524,7 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { $image_editor = new WP_Image_Editor_Imagick( $save_to_file ); $image_editor->load(); - $this->assertNotInstanceOf( 'WP_Error', $image_editor ); + $this->assertNotWPError( $image_editor ); $image_editor->rotate( 180 ); $image_editor->save( $save_to_file ); diff --git a/tests/phpunit/tests/image/functions.php b/tests/phpunit/tests/image/functions.php index 913fefd93d..cff7fc7402 100644 --- a/tests/phpunit/tests/image/functions.php +++ b/tests/phpunit/tests/image/functions.php @@ -163,7 +163,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { $file = wp_tempnam(); $ret = wp_save_image_file( $file, $img, $mime_type, 1 ); $this->assertNotEmpty( $ret ); - $this->assertNotInstanceOf( 'WP_Error', $ret ); + $this->assertNotWPError( $ret ); $this->assertEquals( $mime_type, $this->get_mime_type( $ret['path'] ) ); // Clean up @@ -205,7 +205,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { // Make assertions $this->assertNotEmpty( $ret ); - $this->assertNotInstanceOf( 'WP_Error', $ret ); + $this->assertNotWPError( $ret ); $this->assertEquals( $mime_type, $this->get_mime_type( $ret['path'] ) ); // Clean up @@ -249,7 +249,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { // Save the image as each file extension, check the mime type $img = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); - $this->assertNotInstanceOf( 'WP_Error', $img ); + $this->assertNotWPError( $img ); $temp = get_temp_dir(); foreach ( $mime_types as $ext => $mime_type ) { @@ -260,7 +260,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { $file = wp_unique_filename( $temp, uniqid() . ".$ext" ); $ret = $img->save( trailingslashit( $temp ) . $file ); $this->assertNotEmpty( $ret ); - $this->assertNotInstanceOf( 'WP_Error', $ret ); + $this->assertNotWPError( $ret ); $this->assertEquals( $mime_type, $this->get_mime_type( $ret['path'] ) ); unlink( $ret['path'] ); } @@ -310,7 +310,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { DIR_TESTDATA . '/images/canola.jpg', 0, 0, 100, 100, 100, 100 ); - $this->assertNotInstanceOf( 'WP_Error', $file ); + $this->assertNotWPError( $file ); $this->assertFileExists( $file ); $image = wp_get_image_editor( $file ); $size = $image->get_size(); @@ -334,7 +334,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { 0, 0, 100, 100, 100, 100, false, DIR_TESTDATA . '/images/' . __FUNCTION__ . '.jpg' ); - $this->assertNotInstanceOf( 'WP_Error', $file ); + $this->assertNotWPError( $file ); $this->assertFileExists( $file ); $image = wp_get_image_editor( $file ); $size = $image->get_size(); diff --git a/tests/phpunit/tests/post/formats.php b/tests/phpunit/tests/post/formats.php index 3b5c527722..961aa988e7 100644 --- a/tests/phpunit/tests/post/formats.php +++ b/tests/phpunit/tests/post/formats.php @@ -15,7 +15,7 @@ class Tests_Post_Formats extends WP_UnitTestCase { $this->assertFalse( $format ); $result = set_post_format( $post_id, 'aside' ); - $this->assertNotInstanceOf( 'WP_Error', $result ); + $this->assertNotWPError( $result ); $this->assertInternalType( 'array', $result ); $this->assertEquals( 1, count( $result ) ); @@ -23,12 +23,12 @@ class Tests_Post_Formats extends WP_UnitTestCase { $this->assertEquals( 'aside', $format ); $result = set_post_format( $post_id, 'standard' ); - $this->assertNotInstanceOf( 'WP_Error', $result ); + $this->assertNotWPError( $result ); $this->assertInternalType( 'array', $result ); $this->assertEquals( 0, count( $result ) ); $result = set_post_format( $post_id, '' ); - $this->assertNotInstanceOf( 'WP_Error', $result ); + $this->assertNotWPError( $result ); $this->assertInternalType( 'array', $result ); $this->assertEquals( 0, count( $result ) ); } @@ -43,7 +43,7 @@ class Tests_Post_Formats extends WP_UnitTestCase { $this->assertFalse( $format ); $result = set_post_format( $post_id, 'aside' ); - $this->assertNotInstanceOf( 'WP_Error', $result ); + $this->assertNotWPError( $result ); $this->assertInternalType( 'array', $result ); $this->assertEquals( 1, count( $result ) ); // The format can be set but not retrieved until it is registered. @@ -56,12 +56,12 @@ class Tests_Post_Formats extends WP_UnitTestCase { $this->assertEquals( 'aside', $format ); $result = set_post_format( $post_id, 'standard' ); - $this->assertNotInstanceOf( 'WP_Error', $result ); + $this->assertNotWPError( $result ); $this->assertInternalType( 'array', $result ); $this->assertEquals( 0, count( $result ) ); $result = set_post_format( $post_id, '' ); - $this->assertNotInstanceOf( 'WP_Error', $result ); + $this->assertNotWPError( $result ); $this->assertInternalType( 'array', $result ); $this->assertEquals( 0, count( $result ) ); @@ -75,13 +75,13 @@ class Tests_Post_Formats extends WP_UnitTestCase { $this->assertFalse( has_post_format( '', $post_id ) ); $result = set_post_format( $post_id, 'aside' ); - $this->assertNotInstanceOf( 'WP_Error', $result ); + $this->assertNotWPError( $result ); $this->assertInternalType( 'array', $result ); $this->assertEquals( 1, count( $result ) ); $this->assertTrue( has_post_format( 'aside', $post_id ) ); $result = set_post_format( $post_id, 'standard' ); - $this->assertNotInstanceOf( 'WP_Error', $result ); + $this->assertNotWPError( $result ); $this->assertInternalType( 'array', $result ); $this->assertEquals( 0, count( $result ) ); // Standard is a special case. It shows as false when set.