mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-01 11:14:36 +00:00
New remove() method and some unit tests for the WP_Error class.
props stephenharris. fixes #28092. git-svn-id: https://develop.svn.wordpress.org/trunk@29854 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
63
tests/phpunit/tests/general/errors.php
Normal file
63
tests/phpunit/tests/general/errors.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for error handling and the WP_Error class.
|
||||
*
|
||||
* @group general
|
||||
*/
|
||||
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->assertEquals( 'foo', $error->get_error_code() );
|
||||
$this->assertEquals( 'message', $error->get_error_message() );
|
||||
$this->assertEquals( 'data', $error->get_error_data() );
|
||||
}
|
||||
|
||||
function test_add_error() {
|
||||
$error = new WP_Error();
|
||||
$error->add( 'foo', 'message', 'data' );
|
||||
|
||||
$this->assertTrue( is_wp_error( $error ) );
|
||||
$this->assertEquals( 'foo', $error->get_error_code() );
|
||||
$this->assertEquals( 'message', $error->get_error_message() );
|
||||
$this->assertEquals( 'data', $error->get_error_data() );
|
||||
}
|
||||
|
||||
function test_multiple_errors() {
|
||||
$error = new WP_Error();
|
||||
$error->add( 'foo', 'foo message', 'foo data' );
|
||||
$error->add( 'bar', 'bar message', 'bar data' );
|
||||
|
||||
$this->assertTrue( is_wp_error( $error ) );
|
||||
$this->assertEquals( 'foo', $error->get_error_code() );
|
||||
$this->assertEquals( 'foo message', $error->get_error_message() );
|
||||
$this->assertEquals( 'foo data', $error->get_error_data() );
|
||||
|
||||
$this->assertEquals( array( 'foo', 'bar' ), $error->get_error_codes() );
|
||||
$this->assertEquals( array( 'foo message', 'bar message' ), $error->get_error_messages() );
|
||||
$this->assertEquals( 'foo data', $error->get_error_data( 'foo' ) );
|
||||
$this->assertEquals( 'bar data', $error->get_error_data( 'bar' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28092
|
||||
*/
|
||||
function test_remove_error() {
|
||||
$error = new WP_Error();
|
||||
$error->add( 'foo', 'This is the first error message', 'some error data' );
|
||||
$error->add( 'foo', 'This is the second error message' );
|
||||
$error->add( 'bar', 'This is another error' );
|
||||
|
||||
$error->remove( 'foo' );
|
||||
|
||||
// Check the error has been removed.
|
||||
$this->assertEmpty( $error->get_error_data( 'foo' ) );
|
||||
$this->assertEmpty( $error->get_error_messages( 'foo' ) );
|
||||
|
||||
// The 'bar' error should now be the 'first' error retrieved.
|
||||
$this->assertEquals( 'bar', $error->get_error_code() );
|
||||
$this->assertEmpty( $error->get_error_data() );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user