1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
<?php
namespace SMW\Tests\Utils;
use SMW\Tests\TestEnvironment;
use SMW\Utils\HtmlTable;
/**
* @covers \SMW\Utils\HtmlTable
* @group semantic-mediawiki
*
* @license GNU GPL v2+
* @since 3.0
*
* @author mwjames
*/
class HtmlTableTest extends \PHPUnit_Framework_TestCase {
private $stringValidator;
protected function setUp() {
parent::setUp();
$this->stringValidator = TestEnvironment::newValidatorFactory()->newStringValidator();
}
public function testStandardTable_Cell_Row() {
$instance = new HtmlTable();
$instance->cell( 'Foo', [ 'rel' => 'some' ] );
$instance->row( [ 'class' => 'bar' ] );
$this->stringValidator->assertThatStringContains(
'<table><tr class="bar row-odd"><td rel="some">Foo</td></tr></table>',
$instance->table()
);
}
public function testStandardTable_Header_Cell_Row() {
$instance = new HtmlTable();
$instance->header( 'Foo ');
$instance->cell( 'Bar' );
$instance->row();
$this->stringValidator->assertThatStringContains(
'<table><th>Foo </th><tr class="row-odd"><td>Bar</td></tr></table>',
$instance->table()
);
}
public function testStandardTable_Header_Cell_Row_IsHtml() {
$instance = new HtmlTable();
$instance->header( 'Foo' );
$instance->cell( 'Bar' );
$instance->row();
$this->stringValidator->assertThatStringContains(
'<table><thead><th>Foo</th></thead><tbody><tr class="row-odd"><td>Bar</td></tr></tbody></table>',
$instance->table( [], false, true )
);
}
public function testTransposedTable_Cell_Row() {
$instance = new HtmlTable();
// We need a dedicated header definition to support a table transpose
$instance->header( 'Foo' );
$instance->header( 'Bar' );
$instance->cell( 'lala', [ 'class' => 'foo' ] );
$instance->row();
$instance->cell( 'lula', [ 'rel' => 'tuuu' ] );
$instance->cell( 'lila' );
$instance->row();
$this->stringValidator->assertThatStringContains(
[
'<table data-transpose="1"><tr class="row-odd"><th>Foo</th>',
'<td class="foo">lala</td><td rel="tuuu">lula</td></tr><tr class="row-even"><th>Bar</th>',
'<td></td><td>lila</td></tr></table>'
],
$instance->table( [], true )
);
}
public function testTransposedTable_Cell_Row_IsHtml() {
$instance = new HtmlTable();
// We need a dedicated header definition to support a table transpose
$instance->header( 'Foo' );
$instance->header( 'Bar' );
$instance->cell( 'lala', [ 'class' => 'foo' ] );
$instance->row();
$instance->cell( 'lula', [ 'rel' => 'tuuu' ] );
$instance->cell( 'lila' );
$instance->row();
$this->stringValidator->assertThatStringContains(
[
'<table data-transpose="1"><tbody><tr class="row-odd"><th>Foo</th><td class="foo">lala</td>',
'<td rel="tuuu">lula</td></tr><tr class="row-even"><th>Bar</th><td></td><td>lila</td></tr>',
'</tbody></table>'
],
$instance->table( [], true, true )
);
}
}
|