1<?php
2/**
3 * @group plugin_latexport
4 * @group plugins
5 */
6
7require_once DOKU_PLUGIN . 'latexport/_test/decorator_mock.php';
8require_once DOKU_PLUGIN . 'latexport/implementation/decorator_tables.php';
9
10class DecoratorTablesTest extends DokuWikiTest {
11
12
13    protected $pluginsEnabled = array('latexport', 'mathjax');
14	private $decoratorMock;
15	private $decoratorTables;
16
17    public static function setUpBeforeClass(){
18        parent::setUpBeforeClass();
19	}
20
21	public function setUp() {
22		$this->decoratorMock = new DecoratorMock();
23		$this->decoratorTables = new DecoratorTables($this->decoratorMock);
24    }
25
26	public function testInTablesNewLinesAreReplacedByWordWrap() {
27		$this->decoratorTables->p_close();
28		$this->decoratorTables->table_open(3, 0, 0);
29		$this->decoratorTables->p_close();
30		$this->decoratorTables->table_close();
31		$this->decoratorTables->p_close();
32
33		$this->assertEquals(new CommandPClose(),            $this->decoratorMock->nextCommand());
34		$this->assertEquals(new CommandTableOpen(3, 0, 0),  $this->decoratorMock->nextCommand());
35		$this->assertEquals(new CommandLinebreak(),         $this->decoratorMock->nextCommand());
36		$this->assertEquals(new CommandTableClose(),        $this->decoratorMock->nextCommand());
37		$this->assertEquals(new CommandPClose(),            $this->decoratorMock->nextCommand());
38	}
39
40    public function testDoesNotChangeAnythingOnTablesWithoutSpanning() {
41		$this->decoratorTables->table_open(3, 0, 0);
42
43		$this->decoratorTables->tablerow_open();
44		$this->decoratorTables->tableheader_open(1, 1, 1);
45		$this->decoratorTables->tableheader_close();
46		$this->decoratorTables->tableheader_open(1, 1, 1);
47		$this->decoratorTables->tableheader_close();
48		$this->decoratorTables->tableheader_open(1, 1, 1);
49		$this->decoratorTables->tableheader_close();
50
51		$this->decoratorTables->tablerow_close();
52		$this->decoratorTables->tablerow_open();
53
54		$this->decoratorTables->tablecell_open(1, 1, 1);
55		$this->decoratorTables->tablecell_close();
56		$this->decoratorTables->tablecell_open(1, 1, 1);
57		$this->decoratorTables->tablecell_close();
58		$this->decoratorTables->tablecell_open(1, 1, 1);
59		$this->decoratorTables->tablecell_close();
60
61		$this->decoratorTables->tablerow_close();
62
63		$this->decoratorTables->table_close();
64
65		$this->assertEquals(new CommandTableOpen(3, 0, 0),       $this->decoratorMock->nextCommand());
66
67		$this->assertEquals(new CommandTableRowOpen(),           $this->decoratorMock->nextCommand());
68
69		$this->assertEquals(new CommandTableHeaderOpen(1, 1, 1), $this->decoratorMock->nextCommand());
70		$this->assertEquals(new CommandTableHeaderClose(),       $this->decoratorMock->nextCommand());
71		$this->assertEquals(new CommandTableHeaderOpen(1, 1, 1), $this->decoratorMock->nextCommand());
72		$this->assertEquals(new CommandTableHeaderClose(),       $this->decoratorMock->nextCommand());
73		$this->assertEquals(new CommandTableHeaderOpen(1, 1, 1), $this->decoratorMock->nextCommand());
74		$this->assertEquals(new CommandTableHeaderClose(),       $this->decoratorMock->nextCommand());
75
76		$this->assertEquals(new CommandTableRowClose(),          $this->decoratorMock->nextCommand());
77		$this->assertEquals(new CommandTableCline(1, 3),         $this->decoratorMock->nextCommand());
78		$this->assertEquals(new CommandTableRowOpen(),           $this->decoratorMock->nextCommand());
79
80		$this->assertEquals(new CommandTableCellOpen(1, 1, 1),   $this->decoratorMock->nextCommand());
81		$this->assertEquals(new CommandTableCellClose(),         $this->decoratorMock->nextCommand());
82		$this->assertEquals(new CommandTableCellOpen(1, 1, 1),   $this->decoratorMock->nextCommand());
83		$this->assertEquals(new CommandTableCellClose(),         $this->decoratorMock->nextCommand());
84		$this->assertEquals(new CommandTableCellOpen(1, 1, 1),   $this->decoratorMock->nextCommand());
85	 	$this->assertEquals(new CommandTableCellClose(),         $this->decoratorMock->nextCommand());
86
87		$this->assertEquals(new CommandTableRowClose(),          $this->decoratorMock->nextCommand());
88		$this->assertEquals(new CommandTableCline(1, 3),         $this->decoratorMock->nextCommand());
89
90		$this->assertEquals(new CommandTableClose(),             $this->decoratorMock->nextCommand());
91
92		$this->assertTrue($this->decoratorMock->noCommands(), "Should not have more commands");
93    }
94
95    public function testCanHandleMulticolumn() {
96		$this->decoratorTables->table_open(3, 0, 0);
97
98		$this->decoratorTables->tablerow_open();
99		$this->decoratorTables->tableheader_open(1, 1, 1);
100		$this->decoratorTables->tableheader_close();
101		$this->decoratorTables->tableheader_open(2, 1, 1);
102		$this->decoratorTables->tableheader_close();
103
104		$this->decoratorTables->tablerow_close();
105		$this->decoratorTables->tablerow_open();
106
107		$this->decoratorTables->tablecell_open(1, 1, 1);
108		$this->decoratorTables->tablecell_close();
109		$this->decoratorTables->tablecell_open(1, 1, 1);
110		$this->decoratorTables->tablecell_close();
111		$this->decoratorTables->tablecell_open(1, 1, 1);
112		$this->decoratorTables->tablecell_close();
113
114		$this->decoratorTables->tablerow_close();
115
116		$this->decoratorTables->table_close();
117
118		$this->assertEquals(new CommandTableOpen(3, 0, 0),       $this->decoratorMock->nextCommand());
119
120		$this->assertEquals(new CommandTableRowOpen(),           $this->decoratorMock->nextCommand());
121
122		$this->assertEquals(new CommandTableHeaderOpen(1, 1, 1), $this->decoratorMock->nextCommand());
123		$this->assertEquals(new CommandTableHeaderClose(),       $this->decoratorMock->nextCommand());
124		$this->assertEquals(new CommandTableHeaderOpen(2, 1, 1), $this->decoratorMock->nextCommand());
125		$this->assertEquals(new CommandTableHeaderClose(),       $this->decoratorMock->nextCommand());
126
127		$this->assertEquals(new CommandTableRowClose(),          $this->decoratorMock->nextCommand());
128		$this->assertEquals(new CommandTableCline(1, 3),         $this->decoratorMock->nextCommand());
129		$this->assertEquals(new CommandTableRowOpen(),           $this->decoratorMock->nextCommand());
130
131		$this->assertEquals(new CommandTableCellOpen(1, 1, 1),   $this->decoratorMock->nextCommand());
132		$this->assertEquals(new CommandTableCellClose(),         $this->decoratorMock->nextCommand());
133		$this->assertEquals(new CommandTableCellOpen(1, 1, 1),   $this->decoratorMock->nextCommand());
134		$this->assertEquals(new CommandTableCellClose(),         $this->decoratorMock->nextCommand());
135		$this->assertEquals(new CommandTableCellOpen(1, 1, 1),   $this->decoratorMock->nextCommand());
136	 	$this->assertEquals(new CommandTableCellClose(),         $this->decoratorMock->nextCommand());
137
138		$this->assertEquals(new CommandTableRowClose(),          $this->decoratorMock->nextCommand());
139		$this->assertEquals(new CommandTableCline(1, 3),         $this->decoratorMock->nextCommand());
140
141		$this->assertEquals(new CommandTableClose(),             $this->decoratorMock->nextCommand());
142
143		$this->assertTrue($this->decoratorMock->noCommands(), "Should not have more commands");
144    }
145
146    public function testCanHandleMultirow() {
147
148		$this->decoratorTables->table_open(3, 0, 0);
149
150		$this->decoratorTables->tablerow_open();
151		$this->decoratorTables->tableheader_open(1, 1, 2);
152		$this->decoratorTables->tableheader_close();
153		$this->decoratorTables->tableheader_open(1, 1, 2);
154		$this->decoratorTables->tableheader_close();
155		$this->decoratorTables->tableheader_open(1, 1, 1);
156		$this->decoratorTables->tableheader_close();
157
158		$this->decoratorTables->tablerow_close();
159		$this->decoratorTables->tablerow_open();
160
161		$this->decoratorTables->tablecell_open(1, 1, 1);
162		$this->decoratorTables->tablecell_close();
163
164		$this->decoratorTables->tablerow_close();
165		$this->decoratorTables->tablerow_open();
166
167		$this->decoratorTables->tablecell_open(1, 1, 1);
168		$this->decoratorTables->tablecell_close();
169		$this->decoratorTables->tablecell_open(1, 1, 1);
170		$this->decoratorTables->tablecell_close();
171		$this->decoratorTables->tablecell_open(1, 1, 1);
172		$this->decoratorTables->tablecell_close();
173
174		$this->decoratorTables->tablerow_close();
175
176		$this->decoratorTables->table_close();
177
178
179		$this->assertEquals(new CommandTableOpen(3, 0, 0),        $this->decoratorMock->nextCommand());
180
181		$this->assertEquals(new CommandTableRowOpen(),            $this->decoratorMock->nextCommand());
182
183		$this->assertEquals(new CommandTableHeaderOpen(1, 1, 2),  $this->decoratorMock->nextCommand());
184		$this->assertEquals(new CommandTableHeaderClose(),        $this->decoratorMock->nextCommand());
185		$this->assertEquals(new CommandTableHeaderOpen(1, 1, 2),  $this->decoratorMock->nextCommand());
186		$this->assertEquals(new CommandTableHeaderClose(),        $this->decoratorMock->nextCommand());
187		$this->assertEquals(new CommandTableHeaderOpen(1, 1, 1),  $this->decoratorMock->nextCommand());
188		$this->assertEquals(new CommandTableHeaderClose(),        $this->decoratorMock->nextCommand());
189
190		$this->assertEquals(new CommandTableRowClose(),           $this->decoratorMock->nextCommand());
191		$this->assertEquals(new CommandTableCline(3, 3),         $this->decoratorMock->nextCommand());
192		$this->assertEquals(new CommandTableRowOpen(),            $this->decoratorMock->nextCommand());
193
194		$this->assertEquals(new CommandTableCellOpen(1, null, 1), $this->decoratorMock->nextCommand());
195		$this->assertEquals(new CommandTableCellClose(),          $this->decoratorMock->nextCommand());
196		$this->assertEquals(new CommandTableCellOpen(1, null, 1), $this->decoratorMock->nextCommand());
197		$this->assertEquals(new CommandTableCellClose(),          $this->decoratorMock->nextCommand());
198		$this->assertEquals(new CommandTableCellOpen(1, 1, 1),    $this->decoratorMock->nextCommand());
199	 	$this->assertEquals(new CommandTableCellClose(),          $this->decoratorMock->nextCommand());
200
201		$this->assertEquals(new CommandTableRowClose(),           $this->decoratorMock->nextCommand());
202		$this->assertEquals(new CommandTableCline(1, 3),         $this->decoratorMock->nextCommand());
203		$this->assertEquals(new CommandTableRowOpen(),            $this->decoratorMock->nextCommand());
204
205		$this->assertEquals(new CommandTableCellOpen(1, 1, 1),    $this->decoratorMock->nextCommand());
206		$this->assertEquals(new CommandTableCellClose(),          $this->decoratorMock->nextCommand());
207		$this->assertEquals(new CommandTableCellOpen(1, 1, 1),    $this->decoratorMock->nextCommand());
208		$this->assertEquals(new CommandTableCellClose(),          $this->decoratorMock->nextCommand());
209		$this->assertEquals(new CommandTableCellOpen(1, 1, 1),    $this->decoratorMock->nextCommand());
210	 	$this->assertEquals(new CommandTableCellClose(),          $this->decoratorMock->nextCommand());
211
212		$this->assertEquals(new CommandTableRowClose(),           $this->decoratorMock->nextCommand());
213		$this->assertEquals(new CommandTableCline(1, 3),         $this->decoratorMock->nextCommand());
214
215		$this->assertEquals(new CommandTableClose(),              $this->decoratorMock->nextCommand());
216
217		$this->assertTrue($this->decoratorMock->noCommands(), "Should not have more commands");
218    }
219
220}
221?>
222