ILIAS  trunk Revision v11.0_alpha-1838-g59fc79e306b
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
LinkManagerTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\COPage\Test\Link;
22 
25 
30 {
31  public function testGetInternalLinks(): void
32  {
33  $page = $this->getEmptyPageWithDom();
34  $lm = new LinkManager();
35 
36  $cases = [
37  'xx [iln cat="106"] xx [/iln] xx' => [
38  "Target" => "il__obj_106",
39  "Type" => "RepositoryItem",
40  "TargetFrame" => "",
41  "Anchor" => ""
42  ],
43  'xx [iln page="107"] xx [/iln] xx' => [
44  "Target" => "il__pg_107",
45  "Type" => "PageObject",
46  "TargetFrame" => "",
47  "Anchor" => ""
48  ],
49  'xx [iln chap="106"] xx [/iln] xx' => [
50  "Target" => "il__st_106",
51  "Type" => "StructureObject",
52  "TargetFrame" => "",
53  "Anchor" => ""
54  ],
55  'xx [iln inst="123" page="106"] xx [/iln] xx' => [
56  "Target" => "il_123_pg_106",
57  "Type" => "PageObject",
58  "TargetFrame" => "",
59  "Anchor" => ""
60  ],
61  'xx [iln page="106" target="New" anchor="test"] xx [/iln] xx' => [
62  "Target" => "il__pg_106",
63  "Type" => "PageObject",
64  "TargetFrame" => "New",
65  "Anchor" => "test"
66  ],
67  'xx [iln term="106" target="New"] xx [/iln] xx' => [
68  "Target" => "il__git_106",
69  "Type" => "GlossaryItem",
70  "TargetFrame" => "New",
71  "Anchor" => ""
72  ],
73  'xx [iln wpage="106" anchor="test"] xx [/iln] xx' => [
74  "Target" => "il__wpage_106",
75  "Type" => "WikiPage",
76  "TargetFrame" => "",
77  "Anchor" => "test"
78  ],
79  'xx [iln ppage="106"] xx [/iln] xx' => [
80  "Target" => "il__ppage_106",
81  "Type" => "PortfolioPage",
82  "TargetFrame" => "",
83  "Anchor" => ""
84  ],
85  'xx [iln media="545"/] xx ' => [
86  "Target" => "il__mob_545",
87  "Type" => "MediaObject",
88  "TargetFrame" => "",
89  "Anchor" => ""
90  ],
91  'xx [iln media="108" target="Media"] xx [/iln] xx' => [
92  "Target" => "il__mob_108",
93  "Type" => "MediaObject",
94  "TargetFrame" => "Media",
95  "Anchor" => ""
96  ],
97  'xx [iln dfile="546"] xx [/iln] xx' => [
98  "Target" => "il__dfile_546",
99  "Type" => "File",
100  "TargetFrame" => "",
101  "Anchor" => ""
102  ]
103  ];
104 
105  foreach ($cases as $html => $expected) {
106  $html = $this->legacyHtmlToXml(
107  '<div id="1:1234" class="ilc_text_block_Standard">' . $html . '</div>'
108  );
109  $this->insertParagraphAt($page, "pg", $html);
110  $page->insertPCIds();
111 
112  $links = $lm->getInternalLinks($page->getDomDoc());
113 
114  //var_dump($links);
115  //exit;
116 
117  $this->assertEquals(
118  $expected,
119  current($links)
120  );
121  }
122  }
123 
124  public function testContainsFileLinkId(): void
125  {
126  $page = $this->getEmptyPageWithDom();
127  $lm = new LinkManager();
128 
129  $html = 'xx [iln dfile="546"] xx [/iln] xx';
130  $html = $this->legacyHtmlToXml(
131  '<div id="1:1234" class="ilc_text_block_Standard">' . $html . '</div>'
132  );
133  $this->insertParagraphAt($page, "pg", $html);
134  $page->insertPCIds();
135 
136  $this->assertEquals(
137  true,
138  $lm->containsFileLinkId($page->getDomDoc(), "il__file_546")
139  );
140 
141  $this->assertEquals(
142  true,
143  $lm->containsFileLinkId($page->getDomDoc(), "il__dfile_546")
144  );
145 
146  $this->assertEquals(
147  false,
148  $lm->containsFileLinkId($page->getDomDoc(), "il__file_555")
149  );
150  }
151 
152  public function testExtractFileFromLinkId(): void
153  {
154  $page = $this->getEmptyPageWithDom();
155  $lm = new LinkManager();
156 
157  $this->assertEquals(
158  555,
159  $lm->extractFileFromLinkId("il__file_555")
160  );
161  }
162 
163  public function testResolveInternalLinks(): void
164  {
165  $this->markTestSkipped('Failed for some unknown reason.');
166 
167  $lm = new LinkManager();
168 
169  $cases = [
170  [
171  "html" => 'xx [iln inst="20" page="107"] xx [/iln] xx',
172  "map" => [
173  "il_20_pg_107" => "il_0_pg_108"
174  ],
175  "expected" => '<IntLink Target="il__pg_108" Type="PageObject">'
176  ],
177  [
178  "html" => 'xx [iln inst="20" chap="11"] xx [/iln] xx',
179  "map" => [
180  "il_20_st_11" => "il_0_st_12"
181  ],
182  "expected" => '<IntLink Target="il__st_12" Type="StructureObject">'
183  ]
184  ];
185 
186  foreach ($cases as $case) {
187  $page = $this->getEmptyPageWithDom();
188  $html = $this->legacyHtmlToXml(
189  '<div id="1:1234" class="ilc_text_block_Standard">' . $case["html"] . '</div>'
190  );
191  $this->insertParagraphAt($page, "pg", $html);
192  $page->insertPCIds();
193 
194  $dom = $page->getDomDoc();
195  $links = $lm->resolveIntLinks($dom, $case["map"]);
196 
197  $this->assertStringContainsString(
198  $case["expected"],
199  $page->getXMLFromDom()
200  );
201  }
202  }
203 
204  public function testMoveInternalLinks(): void
205  {
206  $lm = new LinkManager();
207 
208  $cases = [
209  [
210  "html" => 'xx [iln page="107"] xx [/iln] xx',
211  "map" => [
212  107 => 108
213  ],
214  "expected" => '<IntLink Target="il__pg_108" Type="PageObject">'
215  ],
216  [
217  "html" => 'xx [iln chap="10"] xx [/iln] xx',
218  "map" => [
219  10 => 11
220  ],
221  "expected" => '<IntLink Target="il__st_11" Type="StructureObject">'
222  ]
223  ];
224 
225  foreach ($cases as $case) {
226  $page = $this->getEmptyPageWithDom();
227  $html = $this->legacyHtmlToXml(
228  '<div id="1:1234" class="ilc_text_block_Standard">' . $case["html"] . '</div>'
229  );
230  $this->insertParagraphAt($page, "pg", $html);
231  $page->insertPCIds();
232 
233  $dom = $page->getDomDoc();
234  $links = $lm->moveIntLinks($dom, $case["map"], function (int $id) {
235  $type = [
236  11 => "st",
237  108 => "pg"
238  ];
239  return $type[$id];
240  });
241 
242  $this->assertStringContainsString(
243  $case["expected"],
244  $page->getXMLFromDom()
245  );
246  }
247  }
248 }
insertParagraphAt(\ilPageObject $page, string $hier_id, string $text="")
legacyHtmlToXml(string $content)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23