ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
WikiUtilTest.php
Go to the documentation of this file.
1 <?php
2 
4 
10 class WikiUtilTest extends TestCase
11 {
12  protected function tearDown(): void
13  {
14  }
15 
16  public function testMakeUrlTitle(): void
17  {
18  $input_expected = [
19  ["a", "a"]
20  ,["z", "z"]
21  ,["0", "0"]
22  ,[" ", "_"]
23  ,["_", "_"]
24  ,["!", "%21"]
25  ,["§", "%C2%A7"]
26  ,["$", "%24"]
27  ,["%", "%25"]
28  ,["&", "%26"]
29  ,["/", "%2F"]
30  ,["(", "%28"]
31  ,["+", "%2B"]
32  ,[";", "%3B"]
33  ,[":", "%3A"]
34  ,["-", "-"]
35  ,["#", "%23"]
36  ,["?", "%3F"]
37  ,["\x00", ""]
38  ,["\n", ""]
39  ,["\r", ""]
40  ];
41  foreach ($input_expected as $ie) {
43 
44  $this->assertEquals(
45  $ie[1],
46  $result
47  );
48  }
49  }
50 
51  public function testMakeDbTitle(): void
52  {
53  $input_expected = [
54  ["a", "a"]
55  ,["z", "z"]
56  ,["0", "0"]
57  ,[" ", " "]
58  ,["_", " "]
59  ,["!", "!"]
60  ,["§", "§"]
61  ,["$", "$"]
62  ,["%", "%"]
63  ,["&", "&"]
64  ,["/", "/"]
65  ,["(", "("]
66  ,["+", "+"]
67  ,[";", ";"]
68  ,[":", ":"]
69  ,["-", "-"]
70  ,["#", "#"]
71  ,["?", "?"]
72  ,["\x00", ""]
73  ,["\n", ""]
74  ,["\r", ""]
75  ];
76  foreach ($input_expected as $ie) {
78 
79  $this->assertEquals(
80  $ie[1],
81  $result
82  );
83  }
84  }
85 
86  protected function processInternalLinksExtCollect(string $xml):array
87  {
89  $xml,
90  0,
92  );
93  }
94 
95  public function testProcessInternalLinksExtCollect(): void
96  {
97  $input_expected = [
98  ["", []]
99  ,["<Foo></Foo>", []]
100  ];
101  foreach ($input_expected as $ie) {
102  $result = $this->processInternalLinksExtCollect($ie[0]);
103 
104  $this->assertEquals(
105  $ie[1],
106  $result
107  );
108  }
109  }
110 
112  {
113  $xml = "<Foo>[[bar]]</Foo>";
115  $this->assertEquals(
116  "bar",
117  $r[0]["nt"]->mTextform
118  );
119  $this->assertEquals(
120  "bar",
121  $r[0]["text"]
122  );
123  }
124 
126  {
127  $xml = "<Foo>[[bar]]</Foo><Par>[[bar1]] some text [[bar2]]</Par>";
129  $this->assertEquals(
130  "bar",
131  $r[0]["nt"]->mTextform
132  );
133  $this->assertEquals(
134  "bar1",
135  $r[1]["nt"]->mTextform
136  );
137  $this->assertEquals(
138  "bar2",
139  $r[2]["nt"]->mTextform
140  );
141  }
142 
144  {
145  $xml = "<Foo>[[bar]]</Foo><Par>[[bar1]] some text [[bar]]</Par>";
147  $this->assertEquals(
148  "bar",
149  $r[0]["nt"]->mTextform
150  );
151  $this->assertEquals(
152  "bar1",
153  $r[1]["nt"]->mTextform
154  );
155  $this->assertEquals(
156  "bar",
157  $r[2]["nt"]->mTextform
158  );
159  }
160 
162  {
163  $xml = "<Foo>[[bar|some text]]</Foo>";
165  $this->assertEquals(
166  "bar",
167  $r[0]["nt"]->mTextform
168  );
169  $this->assertEquals(
170  "some text",
171  $r[0]["text"]
172  );
173  }
174 
176  {
177  $xml = "<Foo>lore [[bar|some text]] ipsum</Foo><Par>More [[second link|some text for second]]</Par>";
179  $this->assertEquals(
180  "bar",
181  $r[0]["nt"]->mTextform
182  );
183  $this->assertEquals(
184  "some text",
185  $r[0]["text"]
186  );
187  $this->assertEquals(
188  "second link",
189  $r[1]["nt"]->mTextform
190  );
191  $this->assertEquals(
192  "some text for second",
193  $r[1]["text"]
194  );
195  }
196 
197  protected function processInternalLinksCollect(string $xml):array
198  {
200  $xml,
201  0,
203  true
204  );
205  }
206 
208  {
209  $xml = "<Foo>[[bar]]</Foo>";
210  $r = $this->processInternalLinksCollect($xml);
211  $this->assertEquals(
212  ["bar"],
213  $r
214  );
215  }
216 
218  {
219  $xml = "<Foo>[[bar]]</Foo><Par>[[bar1]] some text [[bar]]</Par>";
220  $r = $this->processInternalLinksCollect($xml);
221  $this->assertEquals(
222  ["bar", "bar1"],
223  $r
224  );
225  }
226 
228  {
229  $xml = "<Foo>lore [[bar|some text]] ipsum</Foo><Par>More [[second link|some text for second]]</Par>";
230  $r = $this->processInternalLinksCollect($xml);
231  $this->assertEquals(
232  ["bar", "second link"],
233  $r
234  );
235  }
236 
237  protected function processInternalLinksReplace(string $xml):string
238  {
240  $xml,
241  0,
243  );
244  }
245 
247  {
248  $xml = "<Foo>Some text without a link</Par>";
249  $r = $this->processInternalLinksReplace($xml);
250  $this->assertEquals(
251  $xml,
252  $r
253  );
254  }
255 
256  /*
257  public function testProcessInternalLinksReplaceSimple(): void
258  {
259  $xml = "<Foo>Some text with [[simple]] a link</Par>";
260  $r = $this->processInternalLinksReplace($xml);
261  $this->assertEquals(
262  "todo",
263  $r
264  );
265  }*/
266 
267 }
testProcessInternalLinksCollectMultipleSame()
testProcessInternalLinksExtCollectMultipleSame()
testProcessInternalLinksCollectOneSimple()
$result
processInternalLinksCollect(string $xml)
processInternalLinksExtCollect(string $xml)
processInternalLinksReplace(string $xml)
testProcessInternalLinksExtCollectMultiText()
testProcessInternalLinksExtCollectMultipleSimple()
testProcessInternalLinksExtCollectOneSimple()
Wiki util test.
static processInternalLinks( $s, $a_wiki_id, $a_mode=IL_WIKI_MODE_REPLACE, $a_collect_non_ex=false, $a_offline=false)
Process internal links.
const IL_WIKI_MODE_COLLECT
static makeUrlTitle($a_par)
Set page parameter for Url Embedding.
const IL_WIKI_MODE_REPLACE
Wiki link / page title handling:
testProcessInternalLinksExtCollect()
$xml
Definition: metadata.php:332
static makeDbTitle($a_par)
Handle page GET parameter.
testProcessInternalLinksReplaceWithoutLink()
testProcessInternalLinksCollectMultiText()
const IL_WIKI_MODE_EXT_COLLECT
testProcessInternalLinksExtCollectOneText()