ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ContentIdManagerTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
26
31{
32 protected int $pc_cnt;
33 protected function setUp(): void
34 {
35 parent::setUp();
36 }
37
38 public function testInsertPCIds(): void
39 {
40 $page = $this->getEmptyPageWithDom();
41 $pc = new \ilPCGrid($page);
42 $pc->create($page, "pg");
43 $pc->applyTemplate(
45 0,
46 0,
47 0,
48 0,
49 0
50 );
51
52 $id_manager = $this->getIDManager($page);
53 $id_manager->insertPCIds();
54
55 $expected = <<<EOT
56<PageObject HierId="pg"><PageContent PCID="00000000000000000000000000000001"><Grid><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="6" WIDTH_L="6" WIDTH_XL="6" PCID="00000000000000000000000000000002"/><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="6" WIDTH_L="6" WIDTH_XL="6" PCID="00000000000000000000000000000003"/></Grid></PageContent></PageObject>
57EOT;
58
59 $this->assertXmlEquals(
60 $expected,
61 $page->getXMLFromDom()
62 );
63 }
64
65
66 public function testDuplicatePCIds(): void
67 {
68 $page = $this->getEmptyPageWithDom();
69 $id_manager = $this->getIDManager($page);
70
71 $this->insertParagraphAt($page, "pg");
72 $id_manager->insertPCIds();
73
74 $this->insertParagraphAt($page, "1");
75 $id_manager->insertPCIds();
76
77 $this->assertEquals(
78 false,
79 $id_manager->hasDuplicatePCIds()
80 );
81
82 $this->insertParagraphAt($page, "2");
83 // force a duplicate
84 $this->pc_cnt--;
85 $id_manager->insertPCIds();
86
87 $this->assertEquals(
88 [0 => "00000000000000000000000000000002"],
89 $id_manager->getDuplicatePCIds()
90 );
91
92 $this->assertEquals(
93 true,
94 $id_manager->hasDuplicatePCIds()
95 );
96 }
97
98 public function testStripPCIds(): void
99 {
100 $page = $this->getEmptyPageWithDom();
101 $id_manager = $this->getIDManager($page);
102
103 $this->insertParagraphAt($page, "pg");
104 $this->insertParagraphAt($page, "1");
105 $id_manager->insertPCIds();
106
107 $id_manager->stripPCIDs();
108
109 $expected = <<<EOT
110<PageObject HierId="pg"><PageContent HierId="1"><Paragraph Language="en"/></PageContent><PageContent HierId="2"><Paragraph Language="en"/></PageContent></PageObject>
111EOT;
112
113 $this->assertXmlEquals(
114 $expected,
115 $page->getXMLFromDom()
116 );
117 }
118
119 public function testGetHierIdsForPCIds(): void
120 {
121 $page = $this->getEmptyPageWithDom();
122 $id_manager = $this->getIDManager($page);
123
124 $this->insertParagraphAt($page, "pg");
125 $this->insertParagraphAt($page, "1");
126 $this->insertParagraphAt($page, "2");
127 $id_manager->insertPCIds();
128
129 $hier_ids = $id_manager->getHierIdsForPCIds([
130 "00000000000000000000000000000001", "00000000000000000000000000000002"
131 ]);
132
133 $this->assertEquals(
134 [
135 "00000000000000000000000000000001" => "1",
136 "00000000000000000000000000000002" => "2"
137 ],
138 $hier_ids
139 );
140 }
141
142 public function testGetHierIdForPCId(): void
143 {
144 $page = $this->getEmptyPageWithDom();
145 $id_manager = $this->getIDManager($page);
146
147 $this->insertParagraphAt($page, "pg");
148 $this->insertParagraphAt($page, "1");
149 $this->insertParagraphAt($page, "2");
150 $id_manager->insertPCIds();
151
152 $this->assertEquals(
153 "2",
154 $id_manager->getHierIdForPCId("00000000000000000000000000000002")
155 );
156 }
157
158 public function testGetPCIdsForHierIds(): void
159 {
160 $page = $this->getEmptyPageWithDom();
161 $id_manager = $this->getIDManager($page);
162
163 $this->insertParagraphAt($page, "pg");
164 $this->insertParagraphAt($page, "1");
165 $this->insertParagraphAt($page, "2");
166 $id_manager->insertPCIds();
167
168 $hier_ids = $id_manager->getPCIdsForHierIds([
169 "1", "2"
170 ]);
171
172 $this->assertEquals(
173 [
174 "1" => "00000000000000000000000000000001",
175 "2" => "00000000000000000000000000000002"
176 ],
177 $hier_ids
178 );
179 }
180
181 public function testGetPCIdForHierId(): void
182 {
183 $page = $this->getEmptyPageWithDom();
184 $id_manager = $this->getIDManager($page);
185
186 $this->insertParagraphAt($page, "pg");
187 $this->insertParagraphAt($page, "1");
188 $this->insertParagraphAt($page, "2");
189 $id_manager->insertPCIds();
190
191 $this->assertEquals(
192 "00000000000000000000000000000002",
193 $id_manager->getPCIdForHierId("2")
194 );
195 }
196
197 public function testCheckPCIds(): void
198 {
199 $page = $this->getEmptyPageWithDom();
200 $id_manager = $this->getIDManager($page);
201
202 $this->insertParagraphAt($page, "pg");
203 $this->insertParagraphAt($page, "1");
204 $this->insertParagraphAt($page, "2");
205
206 $this->assertEquals(
207 false,
208 $id_manager->checkPCIds()
209 );
210
211 $id_manager->insertPCIds();
212
213 $this->assertEquals(
214 true,
215 $id_manager->checkPCIds()
216 );
217 }
218
219 public function testGetAllPCIds(): void
220 {
221 $page = $this->getEmptyPageWithDom();
222 $id_manager = $this->getIDManager($page);
223
224 $this->insertParagraphAt($page, "pg");
225 $this->insertParagraphAt($page, "1");
226 $this->insertParagraphAt($page, "2");
227 $id_manager->insertPCIds();
228
229 $this->assertEquals(
230 [
231 "00000000000000000000000000000001",
232 "00000000000000000000000000000002",
233 "00000000000000000000000000000003"
234 ],
235 $id_manager->getAllPCIds()
236 );
237 }
238}
insertParagraphAt(\ilPageObject $page, string $hier_id, string $text="")
getIDManager(\ilPageObject $page)
assertXmlEquals(string $expected_xml_as_string, string $html_xml_string)
const TEMPLATE_TWO_COLUMN