diff --git a/src/wp-includes/Text/Diff.php b/src/wp-includes/Text/Diff.php index b3c63afc5f859..0f13b0fe5a650 100644 --- a/src/wp-includes/Text/Diff.php +++ b/src/wp-includes/Text/Diff.php @@ -260,24 +260,24 @@ static function _getTempDir() function _check($from_lines, $to_lines) { if (serialize($from_lines) != serialize($this->getOriginal())) { - trigger_error("Reconstructed original does not match", E_USER_ERROR); + throw new Text_Exception("Reconstructed original does not match"); } if (serialize($to_lines) != serialize($this->getFinal())) { - trigger_error("Reconstructed final does not match", E_USER_ERROR); + throw new Text_Exception("Reconstructed final does not match"); } $rev = $this->reverse(); if (serialize($to_lines) != serialize($rev->getOriginal())) { - trigger_error("Reversed original does not match", E_USER_ERROR); + throw new Text_Exception("Reversed original does not match"); } if (serialize($from_lines) != serialize($rev->getFinal())) { - trigger_error("Reversed final does not match", E_USER_ERROR); + throw new Text_Exception("Reversed final does not match"); } $prevtype = null; foreach ($this->_edits as $edit) { if ($prevtype !== null && $edit instanceof $prevtype) { - trigger_error("Edit sequence is non-optimal", E_USER_ERROR); + throw new Text_Exception("Edit sequence is non-optimal"); } $prevtype = get_class($edit); } diff --git a/src/wp-includes/Text/Exception.php b/src/wp-includes/Text/Exception.php new file mode 100644 index 0000000000000..4bbe25dcb6744 --- /dev/null +++ b/src/wp-includes/Text/Exception.php @@ -0,0 +1,11 @@ +assertTrue( $diff->_check( self::FILE_A, self::FILE_B ) ); } + + public function test_check_throws_exception_when_from_is_not_same_as_original() { + $this->expectException( Text_Exception::class ); + $this->expectExceptionMessage( 'Reconstructed original does not match' ); + + $diff = new Text_Diff( 'auto', array( self::FILE_A, self::FILE_B ) ); + $diff->_check( self::FILE_B, self::FILE_B ); + } + + public function test_check_throws_exception_when_to_is_not_same_as_final() { + $this->expectException( Text_Exception::class ); + $this->expectExceptionMessage( 'Reconstructed final does not match' ); + + $diff = new Text_Diff( 'auto', array( self::FILE_A, self::FILE_B ) ); + $diff->_check( self::FILE_A, self::FILE_A ); + } }