*/ /** Test the domframework xdiff part */ class test_xdiff extends PHPUnit_Framework_TestCase { // Declaration of $string1 and $string2 // Taken from // {{{ private $string1 = "This part of the document has stayed the same from version to version. It shouldn't be shown if it doesn't change. Otherwise, that would not be helping to compress the size of the changes. This paragraph contains text that is outdated. It will be deleted in the near future. It is important to spell check this dokument. On the other hand, a misspelled word isn't the end of the world. Nothing in the rest of this paragraph needs to be changed. Things can be added after it. "; private $string2 = "This is an important notice! It should therefore be located at the beginning of this document! This part of the document has stayed the same from version to version. It shouldn't be shown if it doesn't change. Otherwise, that would not be helping to compress the size of the changes. It is important to spell check this document. On the other hand, a misspelled word isn't the end of the world. Nothing in the rest of this paragraph needs to be changed. Things can be added after it. This paragraph contains important new additions to this document. "; // }}} public function test_diff_normal_1 () { // Mode normal $xdiff = new xdiff (); $res = $xdiff->diff ($this->string1, $this->string2); $this->assertSame ($res, "0a1,6 > This is an important > notice! It should > therefore be located at > the beginning of this > document! > 11,15d16 < This paragraph contains < text that is outdated. < It will be deleted in the < near future. < 17c18 < check this dokument. On --- > check this document. On 24a26,29 > > This paragraph contains > important new additions > to this document. "); } public function test_diff_normal_2 () { // Mode normal $xdiff = new xdiff (); $res = $xdiff->diff ("NEWLINE\n".$this->string1, $this->string2); $this->assertSame ($res, "1c1,6 < NEWLINE --- > This is an important > notice! It should > therefore be located at > the beginning of this > document! > 12,16d16 < This paragraph contains < text that is outdated. < It will be deleted in the < near future. < 18c18 < check this dokument. On --- > check this document. On 25a26,29 > > This paragraph contains > important new additions > to this document. "); } public function test_diff_normal_3 () { // Mode normal $xdiff = new xdiff (); $res = $xdiff->diff ("NEWLINE\n", "\n"); $this->assertSame ($res, "1c1 < NEWLINE --- > "); } public function test_diff_normal_4 () { // Mode normal $xdiff = new xdiff (); $res = $xdiff->diff ("\n", "NEWLINE\n"); $this->assertSame ($res, "1c1 < --- > NEWLINE "); } public function test_diff_normal_5 () { $xdiff = new xdiff (); $res = $xdiff->diff ("\n", "\n"); $this->assertSame ($res, ""); } public function test_diff_normal_6 () { $xdiff = new xdiff (); $res = $xdiff->diff ("\n", ""); $this->assertSame ($res, "1d0 < \n"); } public function test_diff_normal_7 () { $xdiff = new xdiff (); $res = $xdiff->diff ("", "\n"); $this->assertSame ($res, "0a1 > \n"); } public function test_diff_unified_1 () { // Mode unified $xdiff = new xdiff ("unified"); $res = $xdiff->diff ($this->string1, $this->string2); $this->assertSame ($res, "--- Original ".date ("Y-m-d H:i:s.u000 O")." +++ New ".date ("Y-m-d H:i:s.u001 O")." @@ -0,0 +1,6 @@ +This is an important +notice! It should +therefore be located at +the beginning of this +document! + @@ -11,5 +16,0 @@ -This paragraph contains -text that is outdated. -It will be deleted in the -near future. - @@ -17 +18 @@ -check this dokument. On +check this document. On @@ -24,0 +26,4 @@ + +This paragraph contains +important new additions +to this document. "); } public function test_diff_unified_2 () { // Mode unified $xdiff = new xdiff ("unified"); $res = $xdiff->diff ("NEWLINE\n".$this->string1, $this->string2); $this->assertSame ($res, "--- Original ".date ("Y-m-d H:i:s.u000 O")." +++ New ".date ("Y-m-d H:i:s.u001 O")." @@ -1 +1,6 @@ -NEWLINE +This is an important +notice! It should +therefore be located at +the beginning of this +document! + @@ -12,5 +16,0 @@ -This paragraph contains -text that is outdated. -It will be deleted in the -near future. - @@ -18 +18 @@ -check this dokument. On +check this document. On @@ -25,0 +26,4 @@ + +This paragraph contains +important new additions +to this document. "); } public function test_diff_unified_3 () { $xdiff = new xdiff ("unified"); $res = $xdiff->diff ("NEWLINE\n", "\n"); $this->assertSame ($res, "--- Original ".date ("Y-m-d H:i:s.u000 O")." +++ New ".date ("Y-m-d H:i:s.u001 O")." @@ -1 +1 @@ -NEWLINE + "); } public function test_diff_unified_4 () { $xdiff = new xdiff ("unified"); $res = $xdiff->diff ("\n", "NEWLINE\n"); $this->assertSame ($res, "--- Original ".date ("Y-m-d H:i:s.u000 O")." +++ New ".date ("Y-m-d H:i:s.u001 O")." @@ -1 +1 @@ - +NEWLINE "); } public function test_diff_unified_5 () { $xdiff = new xdiff ("unified"); $res = $xdiff->diff ("\n", "\n"); $this->assertSame ($res, ""); } public function test_diff_unified_6 () { $xdiff = new xdiff ("unified"); $res = $xdiff->diff ("\n", ""); $this->assertSame ($res, "--- Original ".date ("Y-m-d H:i:s.u000 O")." +++ New ".date ("Y-m-d H:i:s.u001 O")." @@ -1 +0,0 @@ -\n"); } public function test_diff_unified_7 () { $xdiff = new xdiff ("unified"); $res = $xdiff->diff ("", "\n"); $this->assertSame ($res, "--- Original ".date ("Y-m-d H:i:s.u000 O")." +++ New ".date ("Y-m-d H:i:s.u001 O")." @@ -0,0 +1 @@ +\n"); } public function test_diffFile_unified_1 () { file_put_contents ("/tmp/test_xdiff1", $this->string1); file_put_contents ("/tmp/test_xdiff2", $this->string2); $xdiff = new xdiff ("unified"); $res = $xdiff->diffFile ("/tmp/test_xdiff1", "/tmp/test_xdiff2"); $this->assertSame ($res, "--- /tmp/test_xdiff1 ".date ("Y-m-d H:i:s.u000 O")." +++ /tmp/test_xdiff2 ".date ("Y-m-d H:i:s.u001 O")." @@ -0,0 +1,6 @@ +This is an important +notice! It should +therefore be located at +the beginning of this +document! + @@ -11,5 +16,0 @@ -This paragraph contains -text that is outdated. -It will be deleted in the -near future. - @@ -17 +18 @@ -check this dokument. On +check this document. On @@ -24,0 +26,4 @@ + +This paragraph contains +important new additions +to this document. "); } public function test_diffFile_unified_2 () { $xdiff = new xdiff ("unified"); $this->setExpectedException (); $res = $xdiff->diffFile ("/tmp/test_xdiffNOTEXISTS", "/tmp/test_xdiff2"); } public function test_diffFile_unified_3 () { $xdiff = new xdiff ("unified"); $this->setExpectedException (); $res = $xdiff->diffFile ("/tmp/test_xdiff1", "/tmp/test_xdiffNOTEXISTS"); } }