ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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
135 $pc->savePositions([
136 "1_1:" => 20,
137 "1_2:" => 10,
138 ]);
139 $page->stripHierIDs();
140 $expected = <<<EOT
141<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>
142EOT;
143 $this->assertXmlEquals(
144 $expected,
145 $page->getXMLFromDom()
146 );
147 }
148
149 public function testClasses(): void
150 {
151 $page = $this->getEmptyPageWithDom();
152 $pc = new ilPCFileList($page);
153 $pc->create($page, "pg");
154 $pc->appendItem("10", "file_loc", "image/jpeg");
155 $pc->appendItem("20", "file_loc2", "image/png");
156 $page->addHierIDs();
157 $pc->setHierId("1");
158 $pc->saveStyleClasses([
159 "1_1:" => "Class1",
160 "1_2:" => "Class2",
161 ]);
162 $classes = $pc->getAllClasses();
163
164 $this->assertEquals(
165 [
166 "1_1:" => "Class1",
167 "1_2:" => "Class2",
168 ],
169 $pc->getAllClasses()
170 );
171 }
172
173 //
174 // Test file items
175 //
176
177 protected function getPageWithFileList(): ilPageObject
178 {
179 $page = $this->getEmptyPageWithDom();
180 $pc = new ilPCFileList($page);
181 $pc->create($page, "pg");
182 $pc->appendItem("10", "file_loc", "image/jpeg");
183 $pc->appendItem("20", "file_loc2", "image/png");
184 $page->addHierIDs();
185 $page->insertPCIds();
186 $pc->setHierId("1");
187 return $page;
188 }
189
190 protected function getItemForHierId(ilPageObject $page, string $hier_id): ilPCFileItem
191 {
192 $pc_id = $page->getPCIdForHierId($hier_id);
193 $cont_node = $page->getContentDomNode($hier_id);
194 $pc = new ilPCFileItem($page);
195 $pc->setDomNode($cont_node);
196 $pc->setHierId($hier_id);
197 $pc->setPcId($pc_id);
198 return $pc;
199 }
200
201 public function testNewItemAfter(): void
202 {
203 $page = $this->getPageWithFileList();
204 $item = $this->getItemForHierId($page, "1_1");
205 $item->newItemAfter("30", "file_loc3", "image/gif");
206 $page->stripHierIDs();
207 $page->stripPCIDs();
208
209 $expected = <<<EOT
210<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>
211EOT;
212
213 $this->assertXmlEquals(
214 $expected,
215 $page->getXMLFromDom()
216 );
217 }
218
219 public function testNewItemBefore(): void
220 {
221 $page = $this->getPageWithFileList();
222 $item = $this->getItemForHierId($page, "1_2");
223 $item->newItemBefore("30", "file_loc3", "image/gif");
224 $page->stripHierIDs();
225 $page->stripPCIDs();
226
227 $expected = <<<EOT
228<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>
229EOT;
230
231 $this->assertXmlEquals(
232 $expected,
233 $page->getXMLFromDom()
234 );
235 }
236
237 public function testDeleteItem(): void
238 {
239 $page = $this->getPageWithFileList();
240 $item = $this->getItemForHierId($page, "1_2");
241 $item->deleteItem();
242 $page->stripHierIDs();
243 $page->stripPCIDs();
244
245 $expected = <<<EOT
246<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>
247EOT;
248
249 $this->assertXmlEquals(
250 $expected,
251 $page->getXMLFromDom()
252 );
253 }
254
255 public function testMoveItemDown(): void
256 {
257 $page = $this->getPageWithFileList();
258 $item = $this->getItemForHierId($page, "1_1");
259 $item->moveItemDown();
260 $page->stripHierIDs();
261 $page->stripPCIDs();
262
263 $expected = <<<EOT
264<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>
265EOT;
266
267 $this->assertXmlEquals(
268 $expected,
269 $page->getXMLFromDom()
270 );
271 }
272
273 public function testMoveItemUp(): void
274 {
275 $page = $this->getPageWithFileList();
276 $item = $this->getItemForHierId($page, "1_2");
277 $item->moveItemUp();
278 $page->stripHierIDs();
279 $page->stripPCIDs();
280
281 $expected = <<<EOT
282<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>
283EOT;
284
285 $this->assertXmlEquals(
286 $expected,
287 $page->getXMLFromDom()
288 );
289 }
290}
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)