| | 721 | /** |
| | 722 | * @covers ::merge() |
| | 723 | */ |
| | 724 | public function test_merge_should_copy_other_error_into_instance() { |
| | 725 | $this->wp_error->add( 'code1', 'message1', 'data1' ); |
| | 726 | |
| | 727 | $other = new \WP_Error( 'code1', 'message2', 'data2' ); |
| | 728 | $other->add( 'code2', 'message3' ); |
| | 729 | $this->wp_error->merge( $other ); |
| | 730 | |
| | 731 | $this->assertSame( array( 'message1', 'message2' ), $this->wp_error->get_error_messages( 'code1' ) ); |
| | 732 | $this->assertSame( 'data2', $this->wp_error->get_error_data( 'code1' ) ); |
| | 733 | $this->assertSame( 'message3', $this->wp_error->get_error_message( 'code2' ) ); |
| | 734 | } |
| | 735 | |
| | 736 | /** |
| | 737 | * @covers ::merge() |
| | 738 | */ |
| | 739 | public function test_merge_with_no_errors_should_not_add_to_instance() { |
| | 740 | $other = new \WP_Error(); |
| | 741 | |
| | 742 | $this->wp_error->merge( $other ); |
| | 743 | |
| | 744 | $this->assertFalse( $this->wp_error->has_errors() ); |
| | 745 | } |
| | 746 | |
| | 747 | /** |
| | 748 | * @covers ::export() |
| | 749 | */ |
| | 750 | public function test_export_should_copy_instance_into_other_error() { |
| | 751 | $other = new \WP_Error(); |
| | 752 | $other->add( 'code1', 'message1', 'data1' ); |
| | 753 | |
| | 754 | $this->wp_error->add( 'code1', 'message2', 'data2' ); |
| | 755 | $this->wp_error->add( 'code2', 'message3' ); |
| | 756 | |
| | 757 | $this->wp_error->export( $other ); |
| | 758 | |
| | 759 | $this->assertSame( array( 'message1', 'message2' ), $other->get_error_messages( 'code1' ) ); |
| | 760 | $this->assertSame( 'data2', $other->get_error_data( 'code1' ) ); |
| | 761 | $this->assertSame( 'message3', $other->get_error_message( 'code2' ) ); |
| | 762 | } |
| | 763 | |
| | 764 | /** |
| | 765 | * @covers ::export() |
| | 766 | */ |
| | 767 | public function test_export_with_no_errors_should_not_add_to_other_error() { |
| | 768 | $other = new \WP_Error(); |
| | 769 | |
| | 770 | $this->wp_error->export( $other ); |
| | 771 | |
| | 772 | $this->assertFalse( $other->has_errors() ); |
| | 773 | } |