ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
WikiUtilTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
23
29class WikiUtilTest extends TestCase
30{
31 protected function setGlobalVariable(string $name, $value): void
32 {
33 global $DIC;
34
35 $GLOBALS[$name] = $value;
36
37 unset($DIC[$name]);
38 $DIC[$name] = static function (Container $c) use ($value) {
39 return $value;
40 };
41 }
42
43 protected function setUp(): void
44 {
45 parent::setUp();
46
47 if (!defined("ILIAS_LOG_ENABLED")) {
48 define("ILIAS_LOG_ENABLED", false);
49 }
51 $GLOBALS['DIC'] = $dic;
52
53 $db_mock = $this->createMock(ilDBInterface::class);
54 $this->setGlobalVariable(
55 "ilDB",
56 $db_mock
57 );
58 }
59
60 protected function tearDown(): void
61 {
62 }
63
64 public function testMakeUrlTitle(): void
65 {
66 $input_expected = [
67 ["a", "a"]
68 ,["z", "z"]
69 ,["0", "0"]
70 ,[" ", "_"]
71 ,["_", "_"]
72 ,["!", "%21"]
73 ,["§", "%C2%A7"]
74 ,["$", "%24"]
75 ,["%", "%25"]
76 ,["&", "%26"]
77 ,["/", "%2F"]
78 ,["(", "%28"]
79 ,["+", "%2B"]
80 ,[";", "%3B"]
81 ,[":", "%3A"]
82 ,["-", "-"]
83 ,["#", "%23"]
84 ,["?", "%3F"]
85 ,["\x00", ""]
86 ,["\n", ""]
87 ,["\r", ""]
88 ];
89 foreach ($input_expected as $ie) {
90 $result = ilWikiUtil::makeUrlTitle($ie[0]);
91
92 $this->assertEquals(
93 $ie[1],
94 $result
95 );
96 }
97 }
98
99 public function testMakeDbTitle(): void
100 {
101 $input_expected = [
102 ["a", "a"]
103 ,["z", "z"]
104 ,["0", "0"]
105 ,[" ", " "]
106 ,["_", " "]
107 ,["!", "!"]
108 ,["§", "§"]
109 ,["$", "$"]
110 ,["%", "%"]
111 ,["&", "&"]
112 ,["/", "/"]
113 ,["(", "("]
114 ,["+", "+"]
115 ,[";", ";"]
116 ,[":", ":"]
117 ,["-", "-"]
118 ,["#", "#"]
119 ,["?", "?"]
120 ,["\x00", ""]
121 ,["\n", ""]
122 ,["\r", ""]
123 ];
124 foreach ($input_expected as $ie) {
125 $result = ilWikiUtil::makeDbTitle($ie[0]);
126
127 $this->assertEquals(
128 $ie[1],
129 $result
130 );
131 }
132 }
133
134 protected function processInternalLinksExtCollect(string $xml): array
135 {
137 $xml,
138 0,
139 true,
141 );
142 }
143
145 {
146 $input_expected = [
147 ["", []]
148 ,["<Foo></Foo>", []]
149 ];
150 foreach ($input_expected as $ie) {
151 $result = $this->processInternalLinksExtCollect($ie[0]);
152
153 $this->assertEquals(
154 $ie[1],
155 $result
156 );
157 }
158 }
159
161 {
162 $xml = "<Foo>[[bar]]</Foo>";
163 $r = $this->processInternalLinksExtCollect($xml);
164 $this->assertEquals(
165 "bar",
166 $r[0]["nt"]->mTextform
167 );
168 $this->assertEquals(
169 "bar",
170 $r[0]["text"]
171 );
172 }
173
175 {
176 $xml = "<Foo>[[bar]]</Foo><Par>[[bar1]] some text [[bar2]]</Par>";
177 $r = $this->processInternalLinksExtCollect($xml);
178 $this->assertEquals(
179 "bar",
180 $r[0]["nt"]->mTextform
181 );
182 $this->assertEquals(
183 "bar1",
184 $r[1]["nt"]->mTextform
185 );
186 $this->assertEquals(
187 "bar2",
188 $r[2]["nt"]->mTextform
189 );
190 }
191
193 {
194 $xml = "<Foo>[[bar]]</Foo><Par>[[bar1]] some text [[bar]]</Par>";
195 $r = $this->processInternalLinksExtCollect($xml);
196 $this->assertEquals(
197 "bar",
198 $r[0]["nt"]->mTextform
199 );
200 $this->assertEquals(
201 "bar1",
202 $r[1]["nt"]->mTextform
203 );
204 $this->assertEquals(
205 "bar",
206 $r[2]["nt"]->mTextform
207 );
208 }
209
211 {
212 $xml = "<Foo>[[bar|some text]]</Foo>";
213 $r = $this->processInternalLinksExtCollect($xml);
214 $this->assertEquals(
215 "bar",
216 $r[0]["nt"]->mTextform
217 );
218 $this->assertEquals(
219 "some text",
220 $r[0]["text"]
221 );
222 }
223
225 {
226 $xml = "<Foo>lore [[bar|some text]] ipsum</Foo><Par>More [[second link|some text for second]]</Par>";
227 $r = $this->processInternalLinksExtCollect($xml);
228 $this->assertEquals(
229 "bar",
230 $r[0]["nt"]->mTextform
231 );
232 $this->assertEquals(
233 "some text",
234 $r[0]["text"]
235 );
236 $this->assertEquals(
237 "second link",
238 $r[1]["nt"]->mTextform
239 );
240 $this->assertEquals(
241 "some text for second",
242 $r[1]["text"]
243 );
244 }
245
246 protected function processInternalLinksCollect(string $xml): array
247 {
249 $xml,
250 0,
251 true,
253 );
254 }
255
257 {
258 $xml = "<Foo>[[bar]]</Foo>";
259 $r = $this->processInternalLinksCollect($xml);
260 $this->assertEquals(
261 ["bar"],
262 $r
263 );
264 }
265
267 {
268 $xml = "<Foo>[[bar]]</Foo><Par>[[bar1]] some text [[bar]]</Par>";
269 $r = $this->processInternalLinksCollect($xml);
270 $this->assertEquals(
271 ["bar", "bar1"],
272 $r
273 );
274 }
275
277 {
278 $xml = "<Foo>lore [[bar|some text]] ipsum</Foo><Par>More [[second link|some text for second]]</Par>";
279 $r = $this->processInternalLinksCollect($xml);
280 $this->assertEquals(
281 ["bar", "second link"],
282 $r
283 );
284 }
285
286 protected function processInternalLinksReplace(string $xml): string
287 {
289 $xml,
290 0,
291 false
292 );
293 }
294
296 {
297 $xml = "<Foo>Some text without a link</Par>";
298 $r = $this->processInternalLinksReplace($xml);
299 $this->assertEquals(
300 $xml,
301 $r
302 );
303 }
304
305 /*
306 public function testProcessInternalLinksReplaceSimple(): void
307 {
308 $xml = "<Foo>Some text with [[simple]] a link</Par>";
309 $r = $this->processInternalLinksReplace($xml);
310 $this->assertEquals(
311 "todo",
312 $r
313 );
314 }*/
315
316}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
Wiki util test.
testProcessInternalLinksExtCollect()
testProcessInternalLinksExtCollectMultipleSame()
testProcessInternalLinksExtCollectMultiText()
processInternalLinksExtCollect(string $xml)
testProcessInternalLinksExtCollectOneSimple()
processInternalLinksCollect(string $xml)
testProcessInternalLinksCollectMultipleSame()
testProcessInternalLinksReplaceWithoutLink()
testProcessInternalLinksExtCollectMultipleSimple()
testProcessInternalLinksCollectMultiText()
testProcessInternalLinksCollectOneSimple()
processInternalLinksReplace(string $xml)
setGlobalVariable(string $name, $value)
testProcessInternalLinksExtCollectOneText()
const IL_WIKI_MODE_COLLECT
const IL_WIKI_MODE_EXT_COLLECT
static makeUrlTitle(string $a_par)
static replaceInternalLinks(string $s, int $a_wiki_id, bool $a_offline=false, string $lang="-")
This one is based on Mediawiki Parser->replaceInternalLinks since we display images in another way,...
static collectInternalLinks(string $s, int $a_wiki_id, bool $a_collect_non_ex=false, string $mode=IL_WIKI_MODE_COLLECT)
Collect internal wiki links of a string.
static makeDbTitle(string $a_par)
$c
Definition: deliver.php:25
$dic
Definition: ltiresult.php:33
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54