|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Trefoil\Test\Helpers; |
|
4
|
|
|
|
|
5
|
|
|
use Trefoil\Helpers\TabularList; |
|
6
|
|
|
|
|
7
|
|
|
class TabularListTest extends \PHPUnit_Framework_TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
|
|
10
|
|
|
public function setUp() |
|
11
|
|
|
{ |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
public function tearDown() |
|
15
|
|
|
{ |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function testNoList() |
|
19
|
|
|
{ |
|
20
|
|
|
$list = new TabularList(); |
|
21
|
|
|
$list->fromHtml(''); |
|
22
|
|
|
$output = $list->toHtmlTable(); |
|
23
|
|
|
|
|
24
|
|
|
$this->assertEmpty($output); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testSimpleListDefault() |
|
28
|
|
|
{ |
|
29
|
|
|
$input = __DIR__ . '/fixtures/tabularlist-test-simple-list.html'; |
|
30
|
|
|
$expected = __DIR__ . '/fixtures/tabularlist-test-simple-list-expected.html'; |
|
31
|
|
|
|
|
32
|
|
|
$this->executeTestSimpleList($input, $expected); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testSimpleList0Categories() |
|
36
|
|
|
{ |
|
37
|
|
|
$input = __DIR__ . '/fixtures/tabularlist-test-simple-list.html'; |
|
38
|
|
|
$expected = __DIR__ . '/fixtures/tabularlist-test-simple-list-expected-0-categories.html'; |
|
39
|
|
|
|
|
40
|
|
|
$this->executeTestSimpleList($input, $expected, 0); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testSimpleList2Categories() |
|
44
|
|
|
{ |
|
45
|
|
|
$input = __DIR__ . '/fixtures/tabularlist-test-simple-list.html'; |
|
46
|
|
|
$expected = __DIR__ . '/fixtures/tabularlist-test-simple-list-expected-2-categories.html'; |
|
47
|
|
|
|
|
48
|
|
|
$this->executeTestSimpleList($input, $expected, 2); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testRowspanListDefault() |
|
52
|
|
|
{ |
|
53
|
|
|
$input = __DIR__ . '/fixtures/tabularlist-test-rowspan-list.html'; |
|
54
|
|
|
$expected = __DIR__ . '/fixtures/tabularlist-test-rowspan-list-expected.html'; |
|
55
|
|
|
|
|
56
|
|
|
$this->executeTestSimpleList($input, $expected); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testRowspanList0Categories() |
|
60
|
|
|
{ |
|
61
|
|
|
$input = __DIR__ . '/fixtures/tabularlist-test-rowspan-list.html'; |
|
62
|
|
|
$expected = __DIR__ . '/fixtures/tabularlist-test-rowspan-list-expected-0-categories.html'; |
|
63
|
|
|
|
|
64
|
|
|
$this->executeTestSimpleList($input, $expected, 0); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testRowspanList1Category() |
|
68
|
|
|
{ |
|
69
|
|
|
$input = __DIR__ . '/fixtures/tabularlist-test-rowspan-list.html'; |
|
70
|
|
|
$expected = __DIR__ . '/fixtures/tabularlist-test-rowspan-list-expected-1-categories.html'; |
|
71
|
|
|
|
|
72
|
|
|
$this->executeTestSimpleList($input, $expected, 1); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function testRowspanList2Category() |
|
76
|
|
|
{ |
|
77
|
|
|
$input = __DIR__ . '/fixtures/tabularlist-test-rowspan-list.html'; |
|
78
|
|
|
$expected = __DIR__ . '/fixtures/tabularlist-test-rowspan-list-expected-2-categories.html'; |
|
79
|
|
|
|
|
80
|
|
|
$this->executeTestSimpleList($input, $expected, 2); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
protected function executeTestSimpleList($inputFile, $expectedFile, $numCategories = null) |
|
84
|
|
|
{ |
|
85
|
|
|
$input = file_get_contents($inputFile); |
|
86
|
|
|
$expected = file_get_contents($expectedFile); |
|
87
|
|
|
|
|
88
|
|
|
$list = new TabularList(); |
|
89
|
|
|
$list->fromHtml($input, $numCategories); |
|
90
|
|
|
$output = $list->toHtmlTable(); |
|
91
|
|
|
|
|
92
|
|
|
// add style to make it easy to visualization |
|
93
|
|
|
$output2 = $input . $output; |
|
94
|
|
|
$output2 .= "<style>"; |
|
95
|
|
|
$output2 .= "td { border: 1px solid black; }"; |
|
96
|
|
|
$output2 .= "th { background: #bbb; border: 1px solid blue;}"; |
|
97
|
|
|
$output2 .= "</style>"; |
|
98
|
|
|
$output2 = tidy_repair_string($output2, array('indent' => true), 'utf8'); |
|
99
|
|
|
// put expected in a temp file to make it easy to examine |
|
100
|
|
|
file_put_contents('/tmp/' . basename($expectedFile) . '-output.html', $output2); |
|
101
|
|
|
|
|
102
|
|
|
// make them comparable |
|
103
|
|
|
$output = tidy_repair_string($output, array('indent' => true), 'utf8'); |
|
104
|
|
|
$expected = tidy_repair_string($expected, array('indent' => true), 'utf8'); |
|
105
|
|
|
$this->assertEquals($expected, $output); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|