393 lines
9.1 KiB
PHP
393 lines
9.1 KiB
PHP
<?php
|
|
|
|
/** DomFramework - Tests
|
|
* @package domframework
|
|
* @author Dominique Fournier <dominique@fournier38.fr>
|
|
* @license BSD
|
|
*/
|
|
|
|
namespace Domframework\Tests;
|
|
|
|
use Domframework\Xdiff;
|
|
|
|
/** Test the domframework xdiff part */
|
|
class xdiffTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
// Declaration of $string1 and $string2
|
|
// {{{
|
|
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);
|
|
$date = date("Y-m-d H:i:s.u00");
|
|
// DST must answer +0200 in winter and +0100 in summer
|
|
$dst = date("O");
|
|
$this->assertSame($res, "--- Original ${date}0 $dst
|
|
+++ New ${date}1 $dst
|
|
@@ -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");
|
|
}
|
|
|
|
public function test_diffFile_sideBySide_1()
|
|
{
|
|
file_put_contents("/tmp/test_xdiff1", $this->string1);
|
|
file_put_contents("/tmp/test_xdiff2", $this->string2);
|
|
$xdiff = new Xdiff("sideBySide");
|
|
$res = $xdiff->diffFile("/tmp/test_xdiff1", "/tmp/test_xdiff2");
|
|
$this->assertSame(
|
|
$res,
|
|
" > This is an important
|
|
> notice! It should
|
|
> therefore be located at
|
|
> the beginning of this
|
|
> document!
|
|
>
|
|
This part of the This part of the
|
|
document has stayed the document has stayed the
|
|
same from version to same from version to
|
|
version. It shouldn't version. It shouldn't
|
|
be shown if it doesn't be shown if it doesn't
|
|
change. Otherwise, that change. Otherwise, that
|
|
would not be helping to would not be helping to
|
|
compress the size of the compress the size of the
|
|
changes. changes.
|
|
|
|
This paragraph contains <
|
|
text that is outdated. <
|
|
It will be deleted in the <
|
|
near future. <
|
|
<
|
|
It is important to spell It is important to spell
|
|
check this dokument. On | check this document. On
|
|
the other hand, a the other hand, a
|
|
misspelled word isn't misspelled word isn't
|
|
the end of the world. the end of the world.
|
|
Nothing in the rest of Nothing in the rest of
|
|
this paragraph needs to this paragraph needs to
|
|
be changed. Things can be changed. Things can
|
|
be added after it. be added after it.
|
|
>
|
|
> This paragraph contains
|
|
> important new additions
|
|
> to this document.
|
|
"
|
|
);
|
|
}
|
|
}
|