Build/Test Tools: Utilise `assertWPError()` and `assertNotWPError()` in more places.

See #38716


git-svn-id: https://develop.svn.wordpress.org/trunk@39174 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2016-11-09 00:01:42 +00:00
parent 5ab2a22a38
commit 61fa0a69d6
10 changed files with 27 additions and 27 deletions

View File

@ -9,7 +9,7 @@ class Tests_General_Errors extends WP_UnitTestCase {
function test_create_error() {
$error = new WP_Error( 'foo', 'message', 'data' );
$this->assertTrue( is_wp_error( $error ) );
$this->assertWPError( $error );
$this->assertEquals( 'foo', $error->get_error_code() );
$this->assertEquals( 'message', $error->get_error_message() );
$this->assertEquals( 'data', $error->get_error_data() );
@ -19,7 +19,7 @@ class Tests_General_Errors extends WP_UnitTestCase {
$error = new WP_Error();
$error->add( 'foo', 'message', 'data' );
$this->assertTrue( is_wp_error( $error ) );
$this->assertWPError( $error );
$this->assertEquals( 'foo', $error->get_error_code() );
$this->assertEquals( 'message', $error->get_error_message() );
$this->assertEquals( 'data', $error->get_error_data() );
@ -30,7 +30,7 @@ class Tests_General_Errors extends WP_UnitTestCase {
$error->add( 'foo', 'foo message', 'foo data' );
$error->add( 'bar', 'bar message', 'bar data' );
$this->assertTrue( is_wp_error( $error ) );
$this->assertWPError( $error );
$this->assertEquals( 'foo', $error->get_error_code() );
$this->assertEquals( 'foo message', $error->get_error_message() );
$this->assertEquals( 'foo data', $error->get_error_data() );

View File

@ -131,13 +131,13 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_redirections_greater() {
// 10 > 5
$res = wp_remote_request($this->redirection_script . '?rt=' . 10, array('redirection' => 5) );
$this->assertTrue( is_wp_error($res), print_r($res, true) );
$this->assertWPError( $res );
}
function test_redirections_greater_edgecase() {
// 6 > 5 (close edgecase)
$res = wp_remote_request($this->redirection_script . '?rt=' . 6, array('redirection' => 5) );
$this->assertTrue( is_wp_error($res) );
$this->assertWPError( $res );
}
function test_redirections_less_edgecase() {
@ -387,7 +387,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$this->markTestSkipped( 'This install of PHP does not support SSL' );
$res = wp_remote_get( 'https://wordpress.org/' );
$this->assertTrue( ! is_wp_error( $res ), print_r( $res, true ) );
$this->assertNotWPError( $res );
}
/**

View File

@ -29,7 +29,7 @@ class Tests_Import_Parser extends WP_Import_UnitTestCase {
foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML' ) as $p ) {
$parser = new $p;
$result = $parser->parse($file);
$this->assertTrue( is_wp_error( $result ) );
$this->assertWPError( $result );
$this->assertEquals( 'There was an error when reading this WXR file', $result->get_error_message() );
}
}
@ -42,7 +42,7 @@ class Tests_Import_Parser extends WP_Import_UnitTestCase {
foreach ( array( $f1, $f2 ) as $file ) {
$parser = new $p;
$result = $parser->parse( $file );
$this->assertTrue( is_wp_error( $result ) );
$this->assertWPError( $result );
$this->assertEquals( 'This does not appear to be a WXR file, missing/invalid WXR version number', $result->get_error_message() );
}
}

View File

@ -381,7 +381,7 @@ class Tests_Post extends WP_UnitTestCase {
// Test both return paths with or without WP_Error
$insert_post = wp_insert_post( $post, true );
$this->assertTrue( is_wp_error( $insert_post ), 'Did not get a WP_Error back from wp_insert_post' );
$this->assertWPError( $insert_post );
$this->assertEquals( 'invalid_date', $insert_post->get_error_code() );
$insert_post = wp_insert_post( $post );

View File

@ -143,7 +143,7 @@ class Tests_Term_GetTheTerms extends WP_UnitTestCase {
function test_get_the_terms_should_return_wp_error_when_taxonomy_is_unregistered() {
$p = self::$post_ids[0];
$terms = get_the_terms( $p, 'this-taxonomy-does-not-exist' );
$this->assertTrue( is_wp_error( $terms ) );
$this->assertWPError( $terms );
}
/**

View File

@ -231,7 +231,7 @@ class Tests_Term_Tax_Query extends WP_UnitTestCase {
) );
$tq->transform_query( $tq->queries[0], 'term_taxonomy_id' );
$this->assertTrue( is_wp_error( $tq->queries[0] ) );
$this->assertWPError( $tq->queries[0] );
}
/**

View File

@ -48,7 +48,7 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase {
public function test_wp_insert_term_taxonomy_does_not_exist() {
$found = wp_insert_term( 'foo', 'bar' );
$this->assertTrue( is_wp_error( $found ) );
$this->assertWPError( $found );
$this->assertSame( 'invalid_taxonomy', $found->get_error_code() );
}
@ -57,21 +57,21 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase {
$found = wp_insert_term( 'foo', 'post_tag' );
remove_filter( 'pre_insert_term', array( $this, '_pre_insert_term_callback' ) );
$this->assertTrue( is_wp_error( $found ) );
$this->assertWPError( $found );
$this->assertSame( 'custom_error', $found->get_error_code() );
}
public function test_wp_insert_term_term_0() {
$found = wp_insert_term( 0, 'post_tag' );
$this->assertTrue( is_wp_error( $found ) );
$this->assertWPError( $found );
$this->assertSame( 'invalid_term_id', $found->get_error_code() );
}
public function test_wp_insert_term_term_trims_to_empty_string() {
$found = wp_insert_term( ' ', 'post_tag' );
$this->assertTrue( is_wp_error( $found ) );
$this->assertWPError( $found );
$this->assertSame( 'empty_term_name', $found->get_error_code() );
}
@ -80,7 +80,7 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase {
'parent' => 999999,
) );
$this->assertTrue( is_wp_error( $found ) );
$this->assertWPError( $found );
$this->assertSame( 'missing_parent', $found->get_error_code() );
}
@ -170,7 +170,7 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase {
// Test an existing term name
$term2 = self::factory()->tag->create( array( 'name' => 'Bozo' ) );
$this->assertTrue( is_wp_error( $term2 ) );
$this->assertWPError( $term2 );
$this->assertNotEmpty( $term2->errors );
// Test named terms ending in special characters
@ -179,7 +179,7 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase {
$term5 = self::factory()->tag->create( array( 'name' => 'T$$$' ) );
$term6 = self::factory()->tag->create( array( 'name' => 'T$$$$' ) );
$term7 = self::factory()->tag->create( array( 'name' => 'T$$$$' ) );
$this->assertTrue( is_wp_error( $term7 ) );
$this->assertWPError( $term7 );
$this->assertNotEmpty( $term7->errors );
$this->assertEquals( $term6, $term7->error_data['term_exists'] );
@ -192,7 +192,7 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase {
$term10 = self::factory()->tag->create( array( 'name' => '$$$' ) );
$term11 = self::factory()->tag->create( array( 'name' => '$$$$' ) );
$term12 = self::factory()->tag->create( array( 'name' => '$$$$' ) );
$this->assertTrue( is_wp_error( $term12 ) );
$this->assertWPError( $term12 );
$this->assertNotEmpty( $term12->errors );
$this->assertEquals( $term11, $term12->error_data['term_exists'] );
@ -202,17 +202,17 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase {
$term13 = self::factory()->tag->create( array( 'name' => 'A' ) );
$this->assertNotWPError( $term13 );
$term14 = self::factory()->tag->create( array( 'name' => 'A' ) );
$this->assertTrue( is_wp_error( $term14 ) );
$this->assertWPError( $term14 );
$term15 = self::factory()->tag->create( array( 'name' => 'A+', 'slug' => 'a' ) );
$this->assertNotWPError( $term15 );
$term16 = self::factory()->tag->create( array( 'name' => 'A+' ) );
$this->assertTrue( is_wp_error( $term16 ) );
$this->assertWPError( $term16 );
$term17 = self::factory()->tag->create( array( 'name' => 'A++' ) );
$this->assertNotWPError( $term17 );
$term18 = self::factory()->tag->create( array( 'name' => 'A-', 'slug' => 'a' ) );
$this->assertNotWPError( $term18 );
$term19 = self::factory()->tag->create( array( 'name' => 'A-' ) );
$this->assertTrue( is_wp_error( $term19 ) );
$this->assertWPError( $term19 );
$term20 = self::factory()->tag->create( array( 'name' => 'A--' ) );
$this->assertNotWPError( $term20 );
}

View File

@ -165,7 +165,7 @@ class Tests_Term_WpSetObjectTerms extends WP_UnitTestCase {
function test_set_object_terms_invalid() {
// bogus taxonomy
$result = wp_set_object_terms( self::$post_ids[0], array(rand_str()), rand_str() );
$this->assertTrue( is_wp_error($result) );
$this->assertWPError( $result );
}
public function test_wp_set_object_terms_append_true() {

View File

@ -7,14 +7,14 @@ class Tests_Term_WpUpdateTerm extends WP_UnitTestCase {
public function test_wp_update_term_taxonomy_does_not_exist() {
$found = wp_update_term( 1, 'bar' );
$this->assertTrue( is_wp_error( $found ) );
$this->assertWPError( $found );
$this->assertSame( 'invalid_taxonomy', $found->get_error_code() );
}
public function test_wp_update_term_term_empty_string_should_return_wp_error() {
$found = wp_update_term( '', 'post_tag' );
$this->assertTrue( is_wp_error( $found ) );
$this->assertWPError( $found );
$this->assertSame( 'invalid_term', $found->get_error_code() );
}
@ -60,7 +60,7 @@ class Tests_Term_WpUpdateTerm extends WP_UnitTestCase {
'name' => '',
) );
$this->assertTrue( is_wp_error( $found ) );
$this->assertWPError( $found );
$this->assertSame( 'empty_term_name', $found->get_error_code() );
_unregister_taxonomy( 'wptests_tax' );
}

View File

@ -51,7 +51,7 @@ class Tests_XMLRPC_wp_editProfile extends WP_XMLRPC_UnitTestCase {
$auth_old = wp_authenticate( 'author', 'author' );
$auth_new = wp_authenticate( 'author', $new_pass );
$this->assertInstanceOf( 'WP_User', $auth_old );
$this->assertTrue( is_wp_error( $auth_new ) );
$this->assertWPError( $auth_new );
}
function test_ignore_email_change() {