ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
PCFileListTest.php
Go to the documentation of this file.
1<?php
2
19use PHPUnit\Framework\TestCase;
20
25{
26 public function testConstruction(): void
27 {
28 $page = $this->getEmptyPageWithDom();
29 $pc = new ilPCFileList($page);
30 $this->assertEquals(
31 ilPCFileList::class,
32 get_class($pc)
33 );
34 }
35
36 public function testCreate(): void
37 {
38 $page = $this->getEmptyPageWithDom();
39 $pc = new ilPCFileList($page);
40 $pc->create($page, "pg");
41 $this->assertXmlEquals(
42 '<PageObject HierId="pg"><PageContent><FileList></FileList></PageContent></PageObject>',
43 $page->getXMLFromDom()
44 );
45 }
46
47 public function testAppendItem(): void
48 {
49 $page = $this->getEmptyPageWithDom();
50 $pc = new ilPCFileList($page);
51 $pc->create($page, "pg");
52 $pc->appendItem("10", "file_loc", "image/jpeg");
53 $expected = <<<EOT
54<PageObject HierId="pg"><PageContent><FileList><FileItem><Identifier Catalog="ILIAS" Entry="il__file_10"></Identifier><Location Type="LocalFile">file_loc</Location><Format>image/jpeg</Format></FileItem></FileList></PageContent></PageObject>
55EOT;
56
57 $this->assertXmlEquals(
58 $expected,
59 $page->getXMLFromDom()
60 );
61 }
62
63 public function testListTitle(): void
64 {
65 $page = $this->getEmptyPageWithDom();
66 $pc = new ilPCFileList($page);
67 $pc->create($page, "pg");
68 $pc->setListTitle("MyTitle", "en");
69 $expected = <<<EOT
70<PageObject HierId="pg"><PageContent><FileList><Title Language="en">MyTitle</Title></FileList></PageContent></PageObject>
71EOT;
72
73 $this->assertXmlEquals(
74 $expected,
75 $page->getXMLFromDom()
76 );
77
78 $this->assertEquals(
79 "MyTitle",
80 $pc->getListTitle()
81 );
82
83 $this->assertEquals(
84 "en",
85 $pc->getLanguage()
86 );
87 }
88
89 public function testFileList(): void
90 {
91 $page = $this->getEmptyPageWithDom();
92 $pc = new ilPCFileList($page);
93 $pc->create($page, "pg");
94 $pc->appendItem("10", "file_loc", "image/jpeg");
95 $page->addHierIDs();
96 $pc->setHierId("1");
97 $this->assertEquals(
98 [ 0 =>
99 ["entry" => "il__file_10",
100 "id" => "10",
101 "pc_id" => "",
102 "hier_id" => "1_1",
103 "class" => ""]
104 ],
105 $pc->getFileList()
106 );
107 }
108
109 public function testDeleteFileItem(): void
110 {
111 $page = $this->getEmptyPageWithDom();
112 $pc = new ilPCFileList($page);
113 $pc->create($page, "pg");
114 $pc->appendItem("10", "file_loc", "image/jpeg");
115 $page->addHierIDs();
116 $pc->setHierId("1");
117 $pc->deleteFileItems(["1_1:"]);
118
119 $this->assertXmlEquals(
120 '<PageObject HierId="pg"><PageContent HierId="1"><FileList></FileList></PageContent></PageObject>',
121 $page->getXMLFromDom()
122 );
123 }
124
125 public function testPositions(): void
126 {
127 $page = $this->getEmptyPageWithDom();
128 $pc = new ilPCFileList($page);
129 $pc->create($page, "pg");
130 $pc->appendItem("10", "file_loc", "image/jpeg");
131 $pc->appendItem("20", "file_loc2", "image/png");
132 $page->addHierIDs();
133 $pc->setHierId("1");
134 $pc->savePositions([
135 0 => "1_2:",
136 1 => "1_1:",
137 ]);
138 $page->stripHierIDs();
139 $expected = <<<EOT
140<PageObject><PageContent><FileList><FileItem><Identifier Catalog="ILIAS" Entry="il__file_20"></Identifier><Location Type="LocalFile">file_loc2</Location><Format>image/png</Format></FileItem><FileItem><Identifier Catalog="ILIAS" Entry="il__file_10"></Identifier><Location Type="LocalFile">file_loc</Location><Format>image/jpeg</Format></FileItem></FileList></PageContent></PageObject>
141EOT;
142 $this->assertXmlEquals(
143 $expected,
144 $page->getXMLFromDom()
145 );
146 }
147
148 public function testClasses(): void
149 {
150 $page = $this->getEmptyPageWithDom();
151 $pc = new ilPCFileList($page);
152 $pc->create($page, "pg");
153 $pc->appendItem("10", "file_loc", "image/jpeg");
154 $pc->appendItem("20", "file_loc2", "image/png");
155 $page->addHierIDs();
156 $pc->setHierId("1");
157 $pc->saveStyleClasses([
158 "1_1:" => "Class1",
159 "1_2:" => "Class2",
160 ]);
161 $classes = $pc->getAllClasses();
162
163 $this->assertEquals(
164 [
165 "1_1:" => "Class1",
166 "1_2:" => "Class2",
167 ],
168 $pc->getAllClasses()
169 );
170 }
171
172 //
173 // Test file items
174 //
175
176 protected function getPageWithFileList(): ilPageObject
177 {
178 $page = $this->getEmptyPageWithDom();
179 $pc = new ilPCFileList($page);
180 $pc->create($page, "pg");
181 $pc->appendItem("10", "file_loc", "image/jpeg");
182 $pc->appendItem("20", "file_loc2", "image/png");
183 $page->addHierIDs();
184 $page->insertPCIds();
185 $pc->setHierId("1");
186 return $page;
187 }
188
189 protected function getItemForHierId(ilPageObject $page, string $hier_id): ilPCFileItem
190 {
191 $pc_id = $page->getPCIdForHierId($hier_id);
192 $cont_node = $page->getContentDomNode($hier_id);
193 $pc = new ilPCFileItem($page);
194 $pc->setDomNode($cont_node);
195 $pc->setHierId($hier_id);
196 $pc->setPcId($pc_id);
197 return $pc;
198 }
199
200 public function testNewItemAfter(): void
201 {
202 $page = $this->getPageWithFileList();
203 $item = $this->getItemForHierId($page, "1_1");
204 $item->newItemAfter("30", "file_loc3", "image/gif");
205 $page->stripHierIDs();
206 $page->stripPCIDs();
207
208 $expected = <<<EOT
209<PageObject><PageContent><FileList><FileItem><Identifier Catalog="ILIAS" Entry="il__file_10"/><Location Type="LocalFile">file_loc</Location><Format>image/jpeg</Format></FileItem><FileItem><Identifier Catalog="ILIAS" Entry="il__file_30"/><Location Type="LocalFile">file_loc3</Location><Format>image/gif</Format></FileItem><FileItem><Identifier Catalog="ILIAS" Entry="il__file_20"/><Location Type="LocalFile">file_loc2</Location><Format>image/png</Format></FileItem></FileList></PageContent></PageObject>
210EOT;
211
212 $this->assertXmlEquals(
213 $expected,
214 $page->getXMLFromDom()
215 );
216 }
217
218 public function testNewItemBefore(): void
219 {
220 $page = $this->getPageWithFileList();
221 $item = $this->getItemForHierId($page, "1_2");
222 $item->newItemBefore("30", "file_loc3", "image/gif");
223 $page->stripHierIDs();
224 $page->stripPCIDs();
225
226 $expected = <<<EOT
227<PageObject><PageContent><FileList><FileItem><Identifier Catalog="ILIAS" Entry="il__file_10"/><Location Type="LocalFile">file_loc</Location><Format>image/jpeg</Format></FileItem><FileItem><Identifier Catalog="ILIAS" Entry="il__file_30"/><Location Type="LocalFile">file_loc3</Location><Format>image/gif</Format></FileItem><FileItem><Identifier Catalog="ILIAS" Entry="il__file_20"/><Location Type="LocalFile">file_loc2</Location><Format>image/png</Format></FileItem></FileList></PageContent></PageObject>
228EOT;
229
230 $this->assertXmlEquals(
231 $expected,
232 $page->getXMLFromDom()
233 );
234 }
235
236 public function testDeleteItem(): void
237 {
238 $page = $this->getPageWithFileList();
239 $item = $this->getItemForHierId($page, "1_2");
240 $item->deleteItem();
241 $page->stripHierIDs();
242 $page->stripPCIDs();
243
244 $expected = <<<EOT
245<PageObject><PageContent><FileList><FileItem><Identifier Catalog="ILIAS" Entry="il__file_10"/><Location Type="LocalFile">file_loc</Location><Format>image/jpeg</Format></FileItem></FileList></PageContent></PageObject>
246EOT;
247
248 $this->assertXmlEquals(
249 $expected,
250 $page->getXMLFromDom()
251 );
252 }
253
254 public function testMoveItemDown(): void
255 {
256 $page = $this->getPageWithFileList();
257 $item = $this->getItemForHierId($page, "1_1");
258 $item->moveItemDown();
259 $page->stripHierIDs();
260 $page->stripPCIDs();
261
262 $expected = <<<EOT
263<PageObject><PageContent><FileList><FileItem><Identifier Catalog="ILIAS" Entry="il__file_20"/><Location Type="LocalFile">file_loc2</Location><Format>image/png</Format></FileItem><FileItem><Identifier Catalog="ILIAS" Entry="il__file_10"/><Location Type="LocalFile">file_loc</Location><Format>image/jpeg</Format></FileItem></FileList></PageContent></PageObject>
264EOT;
265
266 $this->assertXmlEquals(
267 $expected,
268 $page->getXMLFromDom()
269 );
270 }
271
272 public function testMoveItemUp(): void
273 {
274 $page = $this->getPageWithFileList();
275 $item = $this->getItemForHierId($page, "1_2");
276 $item->moveItemUp();
277 $page->stripHierIDs();
278 $page->stripPCIDs();
279
280 $expected = <<<EOT
281<PageObject><PageContent><FileList><FileItem><Identifier Catalog="ILIAS" Entry="il__file_20"/><Location Type="LocalFile">file_loc2</Location><Format>image/png</Format></FileItem><FileItem><Identifier Catalog="ILIAS" Entry="il__file_10"/><Location Type="LocalFile">file_loc</Location><Format>image/jpeg</Format></FileItem></FileList></PageContent></PageObject>
282EOT;
283
284 $this->assertXmlEquals(
285 $expected,
286 $page->getXMLFromDom()
287 );
288 }
289}
assertXmlEquals(string $expected_xml_as_string, string $html_xml_string)
getItemForHierId(ilPageObject $page, string $hier_id)
Title class.
Definition: Title.php:42
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
getContentDomNode(string $a_hier_id, string $a_pc_id="")
getPCIdForHierId(string $hier_id)