Skip to content

Commit 4512c03

Browse files
committed
Add PhpUnit test for html merged renderer
1 parent d70eaf6 commit 4512c03

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

tests/Diff/Renderer/Html/HtmlRenderersTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use jblond\Diff;
88
use jblond\Diff\Renderer\Html\Inline;
9+
use jblond\Diff\Renderer\Html\Merged;
910
use jblond\Diff\Renderer\Html\SideBySide;
1011
use jblond\Diff\Renderer\Html\Unified;
1112
use PHPUnit\Framework\TestCase;
@@ -89,6 +90,26 @@ public function testInline()
8990
$this->assertStringEqualsFile('tests/resources/htmlInline.txt', $result);
9091
}
9192

93+
/**
94+
* Test the output of the HTML Unified renderer.
95+
* @covers \jblond\Diff\Renderer\Html\Merged
96+
*/
97+
public function testMerged()
98+
{
99+
$diff = new Diff(
100+
file_get_contents('tests/resources/a.txt'),
101+
file_get_contents('tests/resources/b.txt')
102+
);
103+
104+
$renderer = new Merged();
105+
$result = $diff->render($renderer);
106+
if ($this->genOutputFiles) {
107+
file_put_contents('htmlMerged.txt', $result);
108+
}
109+
110+
$this->assertStringEqualsFile('tests/resources/htmlMerged.txt', $result);
111+
}
112+
92113
/**
93114
* Test the output of the HTML Unified renderer.
94115
* @covers \jblond\Diff\Renderer\Html\Unified

tests/resources/htmlMerged.txt

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<table class="Differences DifferencesMerged">
2+
<thead>
3+
<tr>
4+
<th colspan="2">Merge of Version1 &amp; Version2</th>
5+
</tr>
6+
</thead><tbody class="ChangeEqual"><tr>
7+
<th title="">1</th>
8+
<td>&lt;html&gt;</td>
9+
</tr><tr>
10+
<th title="">2</th>
11+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&lt;head&gt;</td>
12+
</tr><tr>
13+
<th title="">3</th>
14+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta http-equiv="Content-type" content="text/html; charset=utf-8"/&gt;</td>
15+
</tr></tbody><tbody class="ChangeReplace"><tr>
16+
<th title="">4</th>
17+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Hello <del>World</del><ins>You</ins>!&lt;/title&gt;</td>
18+
</tr></tbody><tbody class="ChangeEqual"><tr>
19+
<th title="">5</th>
20+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/head&gt;</td>
21+
</tr><tr>
22+
<th title="">6</th>
23+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&lt;body&gt;</td>
24+
</tr><tr>
25+
<th title="">7</th>
26+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;This is demo content to show features of the php-diff package.&lt;/h1&gt;</td>
27+
</tr></tbody><tbody class="ChangeDelete"></tbody><tbody class="ChangeEqual"><tr>
28+
<th title="Lines deleted at Version2:
29+
8: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line is removed from version2.&lt;/h2&gt;
30+
">*8</th>
31+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line is the same for both versions.&lt;/h2&gt;</td>
32+
</tr></tbody><tbody class="ChangeReplace"><tr>
33+
<th title="">9</th>
34+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line has <del>inline </del><ins></ins>differences between both versions.&lt;/h2&gt;</td>
35+
</tr></tbody><tbody class="ChangeEqual"><tr>
36+
<th title="">10</th>
37+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line is the same for both versions.&lt;/h2&gt;</td>
38+
</tr></tbody><tbody class="ChangeReplace"><tr>
39+
<th title="">11</th>
40+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line also has <del>inl</del><ins>InL</ins>ine differences between both versions.&lt;/h2&gt;</td>
41+
</tr></tbody><tbody class="ChangeEqual"><tr>
42+
<th title="">12</th>
43+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line is the same for both versions.&lt;/h2&gt;</td>
44+
</tr></tbody><tbody class="ChangeInsert"><tr>
45+
<th title="">13</th>
46+
<td><ins>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line is added to version2.&lt;/h2&gt;</ins></td>
47+
</tr></tbody><tbody class="ChangeEqual"><tr>
48+
<th title="">14</th>
49+
<td></td>
50+
</tr><tr>
51+
<th title="">15</th>
52+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;</td>
53+
</tr><tr>
54+
<th title="">16</th>
55+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;It's also compatible with multibyte characters (like Chinese and emoji) as shown below:</td>
56+
</tr></tbody><tbody class="ChangeReplace"><tr>
57+
<th title="">17</th>
58+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;另外我覺得那個評<del>價</del><ins>鑑</ins>的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革”</td>
59+
</tr><tr>
60+
<th title="">18</th>
61+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Do you know what "<del>金槍魚罐頭</del><ins>魚の缶詰</ins>" means in Chinese?</td>
62+
</tr><tr>
63+
<th title="">19</th>
64+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<del>🍏🍎</del><ins>🍎🍏</ins>🙂</td>
65+
</tr></tbody><tbody class="ChangeEqual"><tr>
66+
<th title="">20</th>
67+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/p&gt;</td>
68+
</tr><tr>
69+
<th title="">21</th>
70+
<td></td>
71+
</tr><tr>
72+
<th title="">22</th>
73+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.&lt;/p&gt;</td>
74+
</tr></tbody><tr>
75+
<th title="">&hellip;</th>
76+
<td class="Skipped">&hellip;</td>
77+
</tr><tbody class="ChangeEqual"><tr>
78+
<th title="">25</th>
79+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.&lt;/p&gt;</td>
80+
</tr><tr>
81+
<th title="">26</th>
82+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.&lt;/p&gt;</td>
83+
</tr><tr>
84+
<th title="">27</th>
85+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.&lt;/p&gt;</td>
86+
</tr></tbody><tbody class="ChangeReplace"><tr>
87+
<th title="">28</th>
88+
<td><del>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</del><ins>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</ins>&lt;h2&gt;This line also has inline differences between both versions. It's the whitespace in front.&lt;/h2&gt;</td>
89+
</tr></tbody><tbody class="ChangeEqual"><tr>
90+
<th title="">29</th>
91+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line is the same for both versions.&lt;/h2&gt;</td>
92+
</tr></tbody><tbody class="ChangeReplace"><tr>
93+
<th title="">30</th>
94+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line also has inline differences between both versions<del>.</del><ins>!</ins>&lt;/h2&gt;</td>
95+
</tr></tbody><tbody class="ChangeEqual"><tr>
96+
<th title="">31</th>
97+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/body&gt;</td>
98+
</tr><tr>
99+
<th title="">32</th>
100+
<td>&lt;/html&gt;</td>
101+
</tr><tr>
102+
<th title="">33</th>
103+
<td></td>
104+
</tr></tbody></table>

0 commit comments

Comments
 (0)