ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
PCSectionTest.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_sec = new ilPCSection($page);
30 $this->assertEquals(
31 ilPCSection::class,
32 get_class($pc_sec)
33 );
34 }
35
36 public function testCreate(): void
37 {
38 $page = $this->getEmptyPageWithDom();
39 $pc_sec = new ilPCSection($page);
40 $pc_sec->create($page, "pg");
41 $this->assertXmlEquals(
42 '<PageObject HierId="pg"><PageContent><Section Characteristic="Block"></Section></PageContent></PageObject>',
43 $page->getXMLFromDom()
44 );
45 }
46
47 public function testCharacteristic(): void
48 {
49 $page = $this->getEmptyPageWithDom();
50 $pc_sec = new ilPCSection($page);
51 $pc_sec->create($page, "pg");
52 $pc_sec->setCharacteristic("MyChar");
53
54 $this->assertEquals(
55 "MyChar",
56 $pc_sec->getCharacteristic()
57 );
58
59 $expected = <<<EOT
60<PageObject HierId="pg"><PageContent><Section Characteristic="MyChar"></Section></PageContent></PageObject>
61EOT;
62
63 $this->assertXmlEquals(
64 $expected,
65 $page->getXMLFromDom()
66 );
67 }
68
69 public function testProtected(): void
70 {
71 $page = $this->getEmptyPageWithDom();
72 $pc_sec = new ilPCSection($page);
73 $pc_sec->create($page, "pg");
74 $pc_sec->setProtected(true);
75
76 $this->assertEquals(
77 true,
78 $pc_sec->getProtected()
79 );
80
81 $expected = <<<EOT
82<PageObject HierId="pg"><PageContent><Section Characteristic="Block" Protected="1"></Section></PageContent></PageObject>
83EOT;
84
85 $this->assertXmlEquals(
86 $expected,
87 $page->getXMLFromDom()
88 );
89 }
90
91 public function testActiveFrom(): void
92 {
93 $page = $this->getEmptyPageWithDom();
94 $pc_sec = new ilPCSection($page);
95 $pc_sec->create($page, "pg");
96 $pc_sec->setActiveFrom(1234);
97
98 $this->assertEquals(
99 1234,
100 $pc_sec->getActiveFrom()
101 );
102
103 $expected = <<<EOT
104<PageObject HierId="pg"><PageContent><Section Characteristic="Block" ActiveFrom="1234"></Section></PageContent></PageObject>
105EOT;
106
107 $this->assertXmlEquals(
108 $expected,
109 $page->getXMLFromDom()
110 );
111 }
112
113 public function testActiveTo(): void
114 {
115 $page = $this->getEmptyPageWithDom();
116 $pc_sec = new ilPCSection($page);
117 $pc_sec->create($page, "pg");
118 $pc_sec->setActiveTo(5678);
119
120 $this->assertEquals(
121 5678,
122 $pc_sec->getActiveTo()
123 );
124
125 $expected = <<<EOT
126<PageObject HierId="pg"><PageContent><Section Characteristic="Block" ActiveTo="5678"></Section></PageContent></PageObject>
127EOT;
128
129 $this->assertXmlEquals(
130 $expected,
131 $page->getXMLFromDom()
132 );
133 }
134
135 public function testPermission(): void
136 {
137 $page = $this->getEmptyPageWithDom();
138 $pc_sec = new ilPCSection($page);
139 $pc_sec->create($page, "pg");
140 $pc_sec->setPermission("write");
141
142 $this->assertEquals(
143 "write",
144 $pc_sec->getPermission()
145 );
146
147 $expected = <<<EOT
148<PageObject HierId="pg"><PageContent><Section Characteristic="Block" Permission="write"></Section></PageContent></PageObject>
149EOT;
150
151 $this->assertXmlEquals(
152 $expected,
153 $page->getXMLFromDom()
154 );
155 }
156
157 public function testPermissionRefId(): void
158 {
159 $page = $this->getEmptyPageWithDom();
160 $pc_sec = new ilPCSection($page);
161 $pc_sec->create($page, "pg");
162 $pc_sec->setPermissionRefId(10);
163
164 $this->assertEquals(
165 10,
166 $pc_sec->getPermissionRefId()
167 );
168
169 $expected = <<<EOT
170<PageObject HierId="pg"><PageContent><Section Characteristic="Block" PermissionRefId="il__ref_10"></Section></PageContent></PageObject>
171EOT;
172
173 $this->assertXmlEquals(
174 $expected,
175 $page->getXMLFromDom()
176 );
177 }
178
180 {
181 $page = $this->getEmptyPageWithDom();
182 $pc_sec = new ilPCSection($page);
183 $pc_sec->create($page, "pg");
184 $pc_sec->setPermissionRefId(10);
185
187
188 $this->assertSame(20, $pc_sec->getPermissionRefId());
189
191
192 $this->assertSame(20, $pc_sec->getPermissionRefId());
193 }
194
195 public function testExtLink(): void
196 {
197 $page = $this->getEmptyPageWithDom();
198 $pc_sec = new ilPCSection($page);
199 $pc_sec->create($page, "pg");
200 $pc_sec->setExtLink("https://www.ilias.de");
201
202 $ext_link = $pc_sec->getLink();
203
204 $this->assertEquals(
205 "ExtLink",
206 $ext_link["LinkType"]
207 );
208
209 $this->assertEquals(
210 "https://www.ilias.de",
211 $ext_link["Href"]
212 );
213
214 $expected = <<<EOT
215<PageObject HierId="pg"><PageContent><Section Characteristic="Block"><ExtLink Href="https://www.ilias.de"></ExtLink></Section></PageContent></PageObject>
216EOT;
217
218 $this->assertXmlEquals(
219 $expected,
220 $page->getXMLFromDom()
221 );
222 }
223
224 public function testIntLink(): void
225 {
226 $page = $this->getEmptyPageWithDom();
227 $pc_sec = new ilPCSection($page);
228 $pc_sec->create($page, "pg");
229 $pc_sec->setIntLink("mytype", "mytarget", "myframe");
230
231 $link = $pc_sec->getLink();
232
233 $this->assertEquals(
234 "IntLink",
235 $link["LinkType"]
236 );
237
238 $this->assertEquals(
239 "mytype",
240 $link["Type"]
241 );
242
243 $this->assertEquals(
244 "mytarget",
245 $link["Target"]
246 );
247
248 $this->assertEquals(
249 "myframe",
250 $link["TargetFrame"]
251 );
252
253 $expected = <<<EOT
254<PageObject HierId="pg"><PageContent><Section Characteristic="Block"><IntLink Type="mytype" Target="mytarget" TargetFrame="myframe"></IntLink></Section></PageContent></PageObject>
255EOT;
256
257 $this->assertXmlEquals(
258 $expected,
259 $page->getXMLFromDom()
260 );
261 }
262
263 public function testNoLink(): void
264 {
265 $page = $this->getEmptyPageWithDom();
266 $pc_sec = new ilPCSection($page);
267 $pc_sec->create($page, "pg");
268
269 $link = $pc_sec->getLink();
270
271 $this->assertEquals(
272 "NoLink",
273 $link["LinkType"]
274 );
275
276 $pc_sec->setIntLink("mytype", "mytarget", "myframe");
277 $pc_sec->setNoLink();
278
279 $link = $pc_sec->getLink();
280
281 $this->assertEquals(
282 "NoLink",
283 $link["LinkType"]
284 );
285
286 $expected = <<<EOT
287<PageObject HierId="pg"><PageContent><Section Characteristic="Block"></Section></PageContent></PageObject>
288EOT;
289
290 $this->assertXmlEquals(
291 $expected,
292 $page->getXMLFromDom()
293 );
294 }
295
296 public function testModel(): void
297 {
298 $page = $this->getEmptyPageWithDom();
299 $pc_sec = new ilPCSection($page);
300 $pc_sec->create($page, "pg");
301
302 $pc_sec->setProtected(true);
303
304 $model = new stdClass();
305 $model->protected = true;
306
307
308 $this->assertEquals(
309 $model,
310 $pc_sec->getModel()
311 );
312 }
313}
assertXmlEquals(string $expected_xml_as_string, string $html_xml_string)
testPermissionRefIdIsAdaptedOnRepositoryCopy()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static afterRepositoryCopy(ilPageObject $page, array $mapping, int $source_ref_id)
After repository (container) copy action.