Make WordPress Core

Ticket #28092: 28092.diff

File 28092.diff, 1.5 KB (added by stephenharris, 12 years ago)
  • src/wp-includes/class-wp-error.php

    diff --git src/wp-includes/class-wp-error.php src/wp-includes/class-wp-error.php
    index 971a4c7..73b6cdf 100644
    class WP_Error {  
    242242
    243243                $this->error_data[$code] = $data;
    244244        }
     245       
     246        /**
     247         * Removes the specified error.
     248         *
     249         * This function removes all error messages associated with the specified
     250         * error code, along with any error data for that code.
     251         *
     252         * @since 4.1.0
     253         *
     254         * @param string|int $code Error code.
     255         */
     256        public function remove( $code ) {
     257               
     258                unset( $this->errors[$code] );
     259                unset( $this->error_data[$code] );
     260               
     261        }
    245262}
    246263
    247264/**
  • new file tests/phpunit/tests/wp-error.php

    diff --git tests/phpunit/tests/wp-error.php tests/phpunit/tests/wp-error.php
    new file mode 100644
    index 0000000..9566991
    - +  
     1<?php
     2/**
     3 * @group wp-error
     4 */
     5class Tests_WP_Error extends WP_UnitTestCase {
     6       
     7        function test_remove_error() {
     8
     9                $error = new WP_Error();
     10                $error->add( 'foo', "This is the first error message", "some error data" );
     11                $error->add( 'foo', "This is the second error message" );
     12                $error->add( 'bar', "This is another error" );
     13               
     14                $error->remove( 'foo' );
     15               
     16                //Check the error has been removed
     17                $this->assertNull( $error->get_error_data( 'foo' ) );
     18                $this->assertEquals( array(), $error->get_error_messages( 'foo' ) );
     19               
     20                //The 'bar' error should now be the 'first' error retrieved
     21                $this->assertEquals( 'bar', $error->get_error_code() );
     22               
     23        }
     24
     25}