Skip to content

Commit 122a72c

Browse files
committed
PHPUnit test added for diff-view renderers.
The tests verify if the ouput of the diff-view renderers remains as defined by the files in the resources folder. TestCase ArrayTest is renamed to HtmlArrayTest in moved to the Html subFolder.
1 parent 0d8c872 commit 122a72c

File tree

9 files changed

+237
-3
lines changed

9 files changed

+237
-3
lines changed

tests/Diff/Renderer/ArrayTest.php renamed to tests/Diff/Renderer/Html/HtmlArrayTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
use PHPUnit\Framework\TestCase;
99

1010
/**
11-
* Class ArrayTest
11+
* Class HtmlArrayTest
1212
* @package Tests\Diff\Renderer\Html
1313
*/
14-
class ArrayTest extends TestCase
14+
class HtmlArrayTest extends TestCase
1515
{
1616

1717
/**
18-
* ArrayTest constructor.
18+
* HtmlArrayTest constructor.
1919
* @param null $name
2020
* @param array $data
2121
* @param string $dataName
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Diff\Renderer\Html;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use jblond\Diff;
9+
use jblond\Diff\Renderer\Html\Inline;
10+
use jblond\Diff\Renderer\Html\SideBySide;
11+
12+
/**
13+
* Class HtmlRendererTest
14+
*
15+
* PHPunit tests to verify the output of the HTML renderers hasn't change by code changes.
16+
*
17+
* @package Tests\Diff\Renderer\Html
18+
*/
19+
class HtmlRendererTest extends TestCase
20+
{
21+
22+
/**
23+
* Constructor.
24+
*
25+
* @param null $name
26+
* @param array $data
27+
* @param string $dataName
28+
*/
29+
public function __construct($name = null, array $data = [], $dataName = '')
30+
{
31+
parent::__construct($name, $data, $dataName);
32+
}
33+
34+
public function testSideBySide()
35+
{
36+
$diff = new Diff(
37+
file_get_contents('./resources/a.txt'),
38+
file_get_contents('./resources/b.txt')
39+
);
40+
41+
$renderer = new SideBySide();
42+
$result = $diff->render($renderer);
43+
//file_put_contents('out.txt', $result);
44+
45+
$this->assertStringEqualsFile('./resources/htmlSideBySide.txt', $result);
46+
}
47+
48+
public function testInline()
49+
{
50+
$diff = new Diff(
51+
file_get_contents('./resources/a.txt'),
52+
file_get_contents('./resources/b.txt')
53+
);
54+
55+
$renderer = new Inline();
56+
$result = $diff->render($renderer);
57+
//file_put_contents('out.txt', $result);
58+
59+
$this->assertStringEqualsFile('./resources/htmlInline.txt', $result);
60+
}
61+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Diff\Renderer\Text;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use jblond\Diff;
9+
use jblond\Diff\Renderer\Text\Context;
10+
use jblond\Diff\Renderer\Text\Unified;
11+
12+
/**
13+
* Class TextRendererTest
14+
*
15+
* PHPunit tests to verify the output of the text renderers hasn't change by code changes.
16+
*
17+
* @package Tests\Diff\Renderer\Text
18+
*/
19+
class TextRendererTest extends TestCase
20+
{
21+
22+
/**
23+
* Constructor.
24+
*
25+
* @param null $name
26+
* @param array $data
27+
* @param string $dataName
28+
*/
29+
public function __construct($name = null, array $data = [], $dataName = '')
30+
{
31+
parent::__construct($name, $data, $dataName);
32+
}
33+
34+
public function testContext()
35+
{
36+
$diff = new Diff(
37+
file_get_contents('./resources/a.txt'),
38+
file_get_contents('./resources/b.txt')
39+
);
40+
41+
$renderer = new Context();
42+
$result = $diff->render($renderer);
43+
//file_put_contents('out.txt', $result);
44+
45+
$this->assertStringEqualsFile('./resources/textContext.txt', $result);
46+
}
47+
48+
public function testUnified()
49+
{
50+
$diff = new Diff(
51+
file_get_contents('./resources/a.txt'),
52+
file_get_contents('./resources/b.txt')
53+
);
54+
55+
$renderer = new Unified();
56+
$result = $diff->render($renderer);
57+
//file_put_contents('out.txt', $result);
58+
59+
$this->assertStringEqualsFile('./resources/textUnified.txt', $result);
60+
}
61+
}

tests/resources/a.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<html>
2+
<head>
3+
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
4+
<title>Hello World!</title>
5+
</head>
6+
<body>
7+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
8+
9+
<h2>A heading we'll be removing</h2>
10+
<pre>
11+
构建具有中国特色的医学人才培养体系
12+
</pre>
13+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
14+
<pre>
15+
另外我覺得那個評價的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅
16+
</pre>
17+
<p>Do you know in Chinese, "金槍魚罐頭" means tuna can.</p>
18+
</body>
19+
</html>

tests/resources/b.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
5+
<title>Goodbye Cruel World!</title>
6+
</head>
7+
<body>
8+
<p>Just a small amount of new text...</p>
9+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
10+
11+
<pre>
12+
构建具有中国國的医学人才培养体系
13+
</pre>
14+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
15+
<pre>
16+
另外我覺得那個評鑑的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅
17+
</pre>
18+
<p>Do you know in Japanese, "魚の缶詰" means fish can.</p>
19+
</body>
20+
</html>

tests/resources/htmlInline.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<table class="Differences DifferencesInline"><thead><tr><th>Old</th><th>New</th><th>Differences</th></tr></thead><tbody class="ChangeInsert"><tr><th>&#xA0;</th><th>1</th><td class="Right"><ins></ins>&#xA0;</td></tr></tbody><tbody class="ChangeEqual"><tr><th>1</th><th>2</th><td class="Left">&lt;html&gt;</td></tr><tr><th>2</th><th>3</th><td class="Left">&#xA0; &#xA0;&lt;head&gt;</td></tr><tr><th>3</th><th>4</th><td class="Left">&#xA0; &#xA0; &#xA0; &#xA0;&lt;meta http-equiv="Content-type" content="text/html; charset=utf-8"/&gt;</td></tr></tbody><tbody class="ChangeReplace"><tr><th>4</th><th>&#xA0;</th><td class="Left"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;title&gt;<del>Hello</del> World!&lt;/title&gt;</span></td></tr><tr><th>&#xA0;</th><th>5</th><td class="Right"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;title&gt;<ins>Goodbye Cruel</ins> World!&lt;/title&gt;</span></td></tr></tbody><tbody class="ChangeEqual"><tr><th>5</th><th>6</th><td class="Left">&#xA0; &#xA0;&lt;/head&gt;</td></tr><tr><th>6</th><th>7</th><td class="Left">&#xA0; &#xA0;&lt;body&gt;</td></tr></tbody><tbody class="ChangeInsert"><tr><th>&#xA0;</th><th>8</th><td class="Right"><ins>&#xA0; &#xA0; &#xA0; &#xA0;&lt;p&gt;Just a small amount of new text...&lt;/p&gt;</ins>&#xA0;</td></tr></tbody><tbody class="ChangeEqual"><tr><th>7</th><th>9</th><td class="Left">&#xA0; &#xA0; &#xA0; &#xA0;&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&lt;/p&gt;</td></tr><tr><th>8</th><th>10</th><td class="Left"></td></tr></tbody><tbody class="ChangeDelete"><tr><th>9</th><th>&#xA0;</th><td class="Left"><del>&#xA0; &#xA0; &#xA0; &#xA0;&lt;h2&gt;A heading we'll be removing&lt;/h2&gt;</del>&#xA0;</td></tr></tbody><tbody class="ChangeEqual"><tr><th>10</th><th>11</th><td class="Left">&lt;pre&gt;</td></tr></tbody><tbody class="ChangeReplace"><tr><th>11</th><th>&#xA0;</th><td class="Left"><span>构建具有中国<del>特色</del>的医学人才培养体系</span></td></tr><tr><th>&#xA0;</th><th>12</th><td class="Right"><span>构建具有中国<ins>國</ins>的医学人才培养体系</span></td></tr></tbody><tbody class="ChangeEqual"><tr><th>12</th><th>13</th><td class="Left">&lt;/pre&gt;</td></tr><tr><th>13</th><th>14</th><td class="Left">&#xA0; &#xA0; &#xA0; &#xA0;&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&lt;/p&gt;</td></tr><tr><th>14</th><th>15</th><td class="Left">&#xA0; &#xA0; &#xA0; &#xA0;&lt;pre&gt;</td></tr></tbody><tbody class="ChangeReplace"><tr><th>15</th><th>&#xA0;</th><td class="Left"><span>&#xA0; &#xA0; &#xA0; &#xA0;另外我覺得那個評<del>價</del>的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅</span></td></tr><tr><th>&#xA0;</th><th>16</th><td class="Right"><span>&#xA0; &#xA0; &#xA0; &#xA0;另外我覺得那個評<ins>鑑</ins>的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅</span></td></tr></tbody><tbody class="ChangeEqual"><tr><th>16</th><th>17</th><td class="Left">&#xA0; &#xA0; &#xA0; &#xA0;&lt;/pre&gt;</td></tr></tbody><tbody class="ChangeReplace"><tr><th>17</th><th>&#xA0;</th><td class="Left"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;p&gt;Do you know in <del>Chinese, "金槍魚罐頭" means tuna</del> can.&lt;/p&gt;</span></td></tr><tr><th>&#xA0;</th><th>18</th><td class="Right"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;p&gt;Do you know in <ins>Japanese, "魚の缶詰" means fish</ins> can.&lt;/p&gt;</span></td></tr></tbody><tbody class="ChangeEqual"><tr><th>18</th><th>19</th><td class="Left">&#xA0; &#xA0;&lt;/body&gt;</td></tr><tr><th>19</th><th>20</th><td class="Left">&lt;/html&gt;</td></tr><tr><th>20</th><th>21</th><td class="Left"></td></tr></tbody></table>

tests/resources/htmlSideBySide.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<table class="Differences DifferencesSideBySide"><thead><tr><th colspan="2">Old Version</th><th colspan="2">New Version</th></tr></thead><tbody class="ChangeInsert"><tr><th>&#xA0;</th><td class="Left">&#xA0;</td><th>1</th><td class="Right"><ins></ins>&#xA0;</td></tr></tbody><tbody class="ChangeEqual"><tr><th>1</th><td class="Left"><span>&lt;html&gt;</span>&#xA0;</td><th>2</th><td class="Right"><span>&lt;html&gt;</span>&#xA0;</td></tr><tr><th>2</th><td class="Left"><span>&#xA0; &#xA0;&lt;head&gt;</span>&#xA0;</td><th>3</th><td class="Right"><span>&#xA0; &#xA0;&lt;head&gt;</span>&#xA0;</td></tr><tr><th>3</th><td class="Left"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;meta http-equiv="Content-type" content="text/html; charset=utf-8"/&gt;</span>&#xA0;</td><th>4</th><td class="Right"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;meta http-equiv="Content-type" content="text/html; charset=utf-8"/&gt;</span>&#xA0;</td></tr></tbody><tbody class="ChangeReplace"><tr><th>4</th><td class="Left"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;title&gt;<del>Hello</del> World!&lt;/title&gt;</span>&#xA0;</td><th>5</th><td class="Right"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;title&gt;<ins>Goodbye Cruel</ins> World!&lt;/title&gt;</span></td></tr></tbody><tbody class="ChangeEqual"><tr><th>5</th><td class="Left"><span>&#xA0; &#xA0;&lt;/head&gt;</span>&#xA0;</td><th>6</th><td class="Right"><span>&#xA0; &#xA0;&lt;/head&gt;</span>&#xA0;</td></tr><tr><th>6</th><td class="Left"><span>&#xA0; &#xA0;&lt;body&gt;</span>&#xA0;</td><th>7</th><td class="Right"><span>&#xA0; &#xA0;&lt;body&gt;</span>&#xA0;</td></tr></tbody><tbody class="ChangeInsert"><tr><th>&#xA0;</th><td class="Left">&#xA0;</td><th>8</th><td class="Right"><ins>&#xA0; &#xA0; &#xA0; &#xA0;&lt;p&gt;Just a small amount of new text...&lt;/p&gt;</ins>&#xA0;</td></tr></tbody><tbody class="ChangeEqual"><tr><th>7</th><td class="Left"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&lt;/p&gt;</span>&#xA0;</td><th>9</th><td class="Right"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&lt;/p&gt;</span>&#xA0;</td></tr><tr><th>8</th><td class="Left"><span></span>&#xA0;</td><th>10</th><td class="Right"><span></span>&#xA0;</td></tr></tbody><tbody class="ChangeDelete"><tr><th>9</th><td class="Left"><del>&#xA0; &#xA0; &#xA0; &#xA0;&lt;h2&gt;A heading we'll be removing&lt;/h2&gt;</del>&#xA0;</td><th>&#xA0;</th><td class="Right">&#xA0;</td></tr></tbody><tbody class="ChangeEqual"><tr><th>10</th><td class="Left"><span>&lt;pre&gt;</span>&#xA0;</td><th>11</th><td class="Right"><span>&lt;pre&gt;</span>&#xA0;</td></tr></tbody><tbody class="ChangeReplace"><tr><th>11</th><td class="Left"><span>构建具有中国<del>特色</del>的医学人才培养体系</span>&#xA0;</td><th>12</th><td class="Right"><span>构建具有中国<ins>國</ins>的医学人才培养体系</span></td></tr></tbody><tbody class="ChangeEqual"><tr><th>12</th><td class="Left"><span>&lt;/pre&gt;</span>&#xA0;</td><th>13</th><td class="Right"><span>&lt;/pre&gt;</span>&#xA0;</td></tr><tr><th>13</th><td class="Left"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&lt;/p&gt;</span>&#xA0;</td><th>14</th><td class="Right"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&lt;/p&gt;</span>&#xA0;</td></tr><tr><th>14</th><td class="Left"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;pre&gt;</span>&#xA0;</td><th>15</th><td class="Right"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;pre&gt;</span>&#xA0;</td></tr></tbody><tbody class="ChangeReplace"><tr><th>15</th><td class="Left"><span>&#xA0; &#xA0; &#xA0; &#xA0;另外我覺得那個評<del>價</del>的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅</span>&#xA0;</td><th>16</th><td class="Right"><span>&#xA0; &#xA0; &#xA0; &#xA0;另外我覺得那個評<ins>鑑</ins>的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅</span></td></tr></tbody><tbody class="ChangeEqual"><tr><th>16</th><td class="Left"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;/pre&gt;</span>&#xA0;</td><th>17</th><td class="Right"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;/pre&gt;</span>&#xA0;</td></tr></tbody><tbody class="ChangeReplace"><tr><th>17</th><td class="Left"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;p&gt;Do you know in <del>Chinese, "金槍魚罐頭" means tuna</del> can.&lt;/p&gt;</span>&#xA0;</td><th>18</th><td class="Right"><span>&#xA0; &#xA0; &#xA0; &#xA0;&lt;p&gt;Do you know in <ins>Japanese, "魚の缶詰" means fish</ins> can.&lt;/p&gt;</span></td></tr></tbody><tbody class="ChangeEqual"><tr><th>18</th><td class="Left"><span>&#xA0; &#xA0;&lt;/body&gt;</span>&#xA0;</td><th>19</th><td class="Right"><span>&#xA0; &#xA0;&lt;/body&gt;</span>&#xA0;</td></tr><tr><th>19</th><td class="Left"><span>&lt;/html&gt;</span>&#xA0;</td><th>20</th><td class="Right"><span>&lt;/html&gt;</span>&#xA0;</td></tr><tr><th>20</th><td class="Left"><span></span>&#xA0;</td><th>21</th><td class="Right"><span></span>&#xA0;</td></tr></tbody></table>

0 commit comments

Comments
 (0)