1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mos\TextFilter; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* A testclass |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
class CTextFilterTest extends \PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Supported filters. |
13
|
|
|
*/ |
14
|
|
|
private $standardFilters = [ |
15
|
|
|
'yamlfrontmatter', |
16
|
|
|
'bbcode', |
17
|
|
|
'clickable', |
18
|
|
|
'markdown', |
19
|
|
|
'geshi', |
20
|
|
|
'nl2br', |
21
|
|
|
'shortcode', |
22
|
|
|
'purify', |
23
|
|
|
'titlefromh1', |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Test. |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
|
|
public function testMore() |
34
|
|
|
{ |
35
|
|
|
$filter = new CTextFilter(); |
36
|
|
|
|
37
|
|
|
$text = ""; |
38
|
|
|
$exp = ""; |
39
|
|
|
$res = $filter->parse($text, []); |
40
|
|
|
$this->assertEquals($exp, $res->excerpt, "More did not match"); |
41
|
|
|
|
42
|
|
|
$text = "A<!--more-->B"; |
43
|
|
|
$exp = "A"; |
44
|
|
|
$res = $filter->parse($text, []); |
45
|
|
|
$this->assertEquals($exp, $res->excerpt, "More did not match"); |
46
|
|
|
|
47
|
|
|
$text = "A<!--stop-->B<!--more-->C"; |
48
|
|
|
$exp = "A"; |
49
|
|
|
$res = $filter->parse($text, []); |
50
|
|
|
$this->assertEquals($exp, $res->excerpt, "More did not match"); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Test. |
57
|
|
|
* |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
|
|
public function testStop() |
61
|
|
|
{ |
62
|
|
|
$filter = new CTextFilter(); |
63
|
|
|
|
64
|
|
|
$text = ""; |
65
|
|
|
$exp = ""; |
66
|
|
|
$res = $filter->parse($text, []); |
67
|
|
|
$this->assertEquals($exp, $res->excerpt, "Stop did not match"); |
68
|
|
|
|
69
|
|
|
$text = "A<!--stop-->B"; |
70
|
|
|
$exp = "A"; |
71
|
|
|
$res = $filter->parse($text, []); |
72
|
|
|
$this->assertEquals($exp, $res->excerpt, "Stop did not match"); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Test. |
79
|
|
|
* |
80
|
|
|
* @return void |
81
|
|
|
*/ |
82
|
|
|
public function testSyntaxHighlightGeshiMethod() |
83
|
|
|
{ |
84
|
|
|
$filter = new CTextFilter(); |
85
|
|
|
|
86
|
|
|
$text = ""; |
87
|
|
|
$exp = '<pre class="text geshi"> </pre>'; |
88
|
|
|
$res = $filter->parse($text, ["geshi"]); |
89
|
|
|
$this->assertEquals($exp, $res->text, "Geshi did not match"); |
90
|
|
|
|
91
|
|
|
$text = <<<'EOD' |
92
|
|
|
$php = "hi"; |
93
|
|
|
EOD; |
94
|
|
|
$exp = '<pre class="text geshi">$php = "hi";</pre>'; |
95
|
|
|
$res = $filter->parse($text, ["geshi"]); |
96
|
|
|
$this->assertEquals($exp, $res->text, "Geshi did not match"); |
97
|
|
|
|
98
|
|
|
$text = <<<'EOD' |
99
|
|
|
$php = "hi"; |
100
|
|
|
EOD; |
101
|
|
|
|
102
|
|
|
// @codingStandardsIgnoreStart |
103
|
|
|
$exp = <<<'EOD' |
104
|
|
|
<pre class="php geshi"><span class="re0">$php</span> <span class="sy0">=</span> <span class="st0">"hi"</span><span class="sy0">;</span></pre> |
105
|
|
|
EOD; |
106
|
|
|
// @codingStandardsIgnoreEnd |
107
|
|
|
$res = $filter->syntaxHighlightGeSHi($text, "php"); |
108
|
|
|
$this->assertEquals($exp, $res, "Geshi did not match"); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Test. |
115
|
|
|
* |
116
|
|
|
* @return void |
117
|
|
|
*/ |
118
|
|
|
public function testSyntaxHighlightGeshiShortCode() |
119
|
|
|
{ |
120
|
|
|
$filter = new CTextFilter(); |
121
|
|
|
|
122
|
|
|
$text = <<<'EOD' |
123
|
|
|
```text |
124
|
|
|
``` |
125
|
|
|
|
126
|
|
|
EOD; |
127
|
|
|
$exp = <<<'EOD' |
128
|
|
|
<pre class="text geshi"> </pre> |
129
|
|
|
EOD; |
130
|
|
|
$res = $filter->parse($text, ["shortcode"]); |
131
|
|
|
$this->assertEquals($exp, $res->text, "Geshi did not match"); |
132
|
|
|
|
133
|
|
|
$text = <<<'EOD' |
134
|
|
|
``` |
135
|
|
|
``` |
136
|
|
|
|
137
|
|
|
EOD; |
138
|
|
|
$exp = <<<'EOD' |
139
|
|
|
<pre class="text geshi"> </pre> |
140
|
|
|
EOD; |
141
|
|
|
$res = $filter->parse($text, ["shortcode"]); |
142
|
|
|
$this->assertEquals($exp, $res->text, "Geshi did not match"); |
143
|
|
|
|
144
|
|
|
$text = <<<'EOD' |
145
|
|
|
```text |
146
|
|
|
$php = "hi"; |
147
|
|
|
``` |
148
|
|
|
|
149
|
|
|
EOD; |
150
|
|
|
$exp = <<<'EOD' |
151
|
|
|
<pre class="text geshi">$php = "hi"; |
152
|
|
|
</pre> |
153
|
|
|
EOD; |
154
|
|
|
$res = $filter->parse($text, ["shortcode"]); |
155
|
|
|
$this->assertEquals($exp, $res->text, "Geshi did not match"); |
156
|
|
|
|
157
|
|
|
$text = <<<'EOD' |
158
|
|
|
```php |
159
|
|
|
$php = "hi"; |
160
|
|
|
``` |
161
|
|
|
|
162
|
|
|
EOD; |
163
|
|
|
// @codingStandardsIgnoreStart |
164
|
|
|
$exp = <<<'EOD' |
165
|
|
|
<pre class="php geshi"><span class="re0">$php</span> <span class="sy0">=</span> <span class="st0">"hi"</span><span class="sy0">;</span> |
166
|
|
|
</pre> |
167
|
|
|
EOD; |
168
|
|
|
// @codingStandardsIgnoreEnd |
169
|
|
|
$res = $filter->parse($text, ["shortcode"]); |
170
|
|
|
$this->assertEquals($exp, $res->text, "Geshi did not match"); |
171
|
|
|
|
172
|
|
|
$text = <<<'EOD' |
|
|
|
|
173
|
|
|
```php |
174
|
|
|
$php = "hi"; |
175
|
|
|
``` |
176
|
|
|
|
177
|
|
|
EOD; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
|
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Test. |
184
|
|
|
* |
185
|
|
|
* @return void |
186
|
|
|
*/ |
187
|
|
|
public function testTitleFromFirstH1() |
188
|
|
|
{ |
189
|
|
|
$filter = new CTextFilter(); |
190
|
|
|
|
191
|
|
|
$text = ""; |
192
|
|
|
$res = $filter->parse($text, ["titlefromh1"]); |
193
|
|
|
$title = $res->frontmatter["title"]; |
194
|
|
|
$this->assertNull($title, "Title should be null"); |
195
|
|
|
|
196
|
|
|
$text = "<h1>My title</h1>"; |
197
|
|
|
$exp = "My title"; |
198
|
|
|
$res = $filter->parse($text, ["titlefromh1"]); |
199
|
|
|
$title = $res->frontmatter["title"]; |
200
|
|
|
$this->assertEquals($exp, $title, "Title missmatch"); |
201
|
|
|
|
202
|
|
|
$text = "<h1><a href=''>My title</a></h1>"; |
203
|
|
|
$exp = "My title"; |
204
|
|
|
$res = $filter->parse($text, ["titlefromh1"]); |
205
|
|
|
$title = $res->frontmatter["title"]; |
206
|
|
|
$this->assertEquals($exp, $title, "Title missmatch"); |
207
|
|
|
|
208
|
|
|
$text = "<h1 class=''>My title</h1>"; |
209
|
|
|
$exp = "My title"; |
210
|
|
|
$res = $filter->parse($text, ["titlefromh1"]); |
211
|
|
|
$title = $res->frontmatter["title"]; |
212
|
|
|
$this->assertEquals($exp, $title, "Title missmatch"); |
213
|
|
|
|
214
|
|
|
$text = <<<EOD |
215
|
|
|
{{{ |
216
|
|
|
{ |
217
|
|
|
"title": "JSON title" |
218
|
|
|
} |
219
|
|
|
}}} |
220
|
|
|
<h1 class=''>My title</h1> |
221
|
|
|
EOD; |
222
|
|
|
$exp = "JSON title"; |
223
|
|
|
$res = $filter->parse($text, ["titlefromh1", "jsonfrontmatter"]); |
224
|
|
|
$title = $res->frontmatter["title"]; |
225
|
|
|
$this->assertEquals($exp, $title, "Title missmatch"); |
226
|
|
|
|
227
|
|
|
$exp = "JSON title"; |
228
|
|
|
$res = $filter->parse($text, ["jsonfrontmatter", "titlefromh1"]); |
229
|
|
|
$title = $res->frontmatter["title"]; |
230
|
|
|
$this->assertEquals($exp, $title, "Title missmatch"); |
231
|
|
|
|
232
|
|
|
$text = <<<EOD |
233
|
|
|
{{{ |
234
|
|
|
{ |
235
|
|
|
"title": "JSON title" |
236
|
|
|
} |
237
|
|
|
}}} |
238
|
|
|
My title |
239
|
|
|
================================= |
240
|
|
|
|
241
|
|
|
This is the index page. |
242
|
|
|
EOD; |
243
|
|
|
$exp = "JSON title"; |
244
|
|
|
$res = $filter->parse($text, ["jsonfrontmatter", "markdown", "titlefromh1"]); |
245
|
|
|
$title = $res->frontmatter["title"]; |
246
|
|
|
$this->assertEquals($exp, $title, "Title missmatch"); |
247
|
|
|
|
248
|
|
|
$text = <<<EOD |
249
|
|
|
{{{ |
250
|
|
|
{ |
251
|
|
|
"title-no": "JSON title" |
252
|
|
|
} |
253
|
|
|
}}} |
254
|
|
|
My title |
255
|
|
|
================================= |
256
|
|
|
|
257
|
|
|
This is the index page. |
258
|
|
|
EOD; |
259
|
|
|
$exp = "My title"; |
260
|
|
|
$res = $filter->parse($text, ["jsonfrontmatter", "markdown", "titlefromh1"]); |
261
|
|
|
$title = $res->frontmatter["title"]; |
262
|
|
|
$this->assertEquals($exp, $title, "Title missmatch"); |
263
|
|
|
|
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
|
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Test. |
270
|
|
|
* |
271
|
|
|
* @expectedException /Mos/TextFilter/Exception |
272
|
|
|
* |
273
|
|
|
* @return void |
274
|
|
|
*/ |
275
|
|
|
public function testJsonFrontMatterException() |
276
|
|
|
{ |
277
|
|
|
$filter = new CTextFilter(); |
278
|
|
|
|
279
|
|
|
$text = <<<EOD |
280
|
|
|
{{{ |
281
|
|
|
|
282
|
|
|
}}} |
283
|
|
|
EOD; |
284
|
|
|
$filter->parse($text, ["jsonfrontmatter"]); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
|
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* Test. |
291
|
|
|
* |
292
|
|
|
* @return void |
293
|
|
|
*/ |
294
|
|
|
public function testJsonFrontMatter() |
295
|
|
|
{ |
296
|
|
|
$filter = new CTextFilter(); |
297
|
|
|
|
298
|
|
|
$text = ""; |
299
|
|
|
$res = $filter->parse($text, ["jsonfrontmatter"]); |
300
|
|
|
$this->assertNull($res->frontmatter, "Frontmatter should be null"); |
301
|
|
|
$this->assertEmpty($res->text, "Text should be empty"); |
302
|
|
|
|
303
|
|
|
$text = <<<EOD |
304
|
|
|
{{{ |
305
|
|
|
}}} |
306
|
|
|
|
307
|
|
|
EOD; |
308
|
|
|
$res = $filter->parse($text, ["jsonfrontmatter"]); |
309
|
|
|
$this->assertEmpty($res->frontmatter, "Frontmatter should be empty"); |
310
|
|
|
$this->assertEmpty($res->text, "Text should be empty"); |
311
|
|
|
|
312
|
|
|
$txt = "TEXT"; |
313
|
|
|
$text = <<<EOD |
314
|
|
|
{{{ |
315
|
|
|
{ |
316
|
|
|
"key": "value" |
317
|
|
|
} |
318
|
|
|
}}} |
319
|
|
|
$txt |
320
|
|
|
EOD; |
321
|
|
|
$res = $filter->parse($text, ["jsonfrontmatter"]); |
322
|
|
|
$this->assertEquals( |
323
|
|
|
$res->frontmatter, |
324
|
|
|
[ |
325
|
|
|
"key" => "value" |
326
|
|
|
], |
327
|
|
|
"Frontmatter should be empty" |
328
|
|
|
); |
329
|
|
|
$this->assertEquals($txt, $res->text, "Text missmatch"); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
|
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* Test. |
336
|
|
|
* |
337
|
|
|
* @expectedException /Mos/TextFilter/Exception |
338
|
|
|
* |
339
|
|
|
* @return void |
340
|
|
|
*/ |
341
|
|
|
public function testYamlFrontMatterException() |
342
|
|
|
{ |
343
|
|
|
if (!function_exists("yaml_parse")) { |
344
|
|
|
return; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
$filter = new CTextFilter(); |
348
|
|
|
|
349
|
|
|
$text = <<<EOD |
350
|
|
|
--- |
351
|
|
|
|
352
|
|
|
--- |
353
|
|
|
EOD; |
354
|
|
|
$filter->parse($text, ["yamlfrontmatter"]); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
|
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* Test. |
361
|
|
|
* |
362
|
|
|
* @return void |
363
|
|
|
*/ |
364
|
|
|
public function testYamlFrontMatter() |
365
|
|
|
{ |
366
|
|
|
if (!function_exists("yaml_parse")) { |
367
|
|
|
return; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
$filter = new CTextFilter(); |
371
|
|
|
|
372
|
|
|
$text = ""; |
373
|
|
|
$res = $filter->parse($text, ["yamlfrontmatter"]); |
374
|
|
|
$this->assertNull($res->frontmatter, "Frontmatter should be null"); |
375
|
|
|
$this->assertEmpty($res->text, "Text should be empty"); |
376
|
|
|
|
377
|
|
|
$text = <<<EOD |
378
|
|
|
--- |
379
|
|
|
--- |
380
|
|
|
|
381
|
|
|
EOD; |
382
|
|
|
$res = $filter->parse($text, ["yamlfrontmatter"]); |
383
|
|
|
$this->assertEmpty($res->frontmatter, "Frontmatter should be empty"); |
384
|
|
|
$this->assertEmpty($res->text, "Text should be empty"); |
385
|
|
|
|
386
|
|
|
$txt = "TEXT"; |
387
|
|
|
$text = <<<EOD |
388
|
|
|
--- |
389
|
|
|
key: value |
390
|
|
|
--- |
391
|
|
|
$txt |
392
|
|
|
EOD; |
393
|
|
|
$res = $filter->parse($text, ["yamlfrontmatter"]); |
394
|
|
|
$this->assertEquals( |
395
|
|
|
$res->frontmatter, |
396
|
|
|
[ |
397
|
|
|
"key" => "value" |
398
|
|
|
], |
399
|
|
|
"Frontmatter not matching" |
400
|
|
|
); |
401
|
|
|
$this->assertEquals($txt, $res->text, "Text missmatch"); |
402
|
|
|
|
403
|
|
|
$text = <<<EOD |
404
|
|
|
--- |
405
|
|
|
key1: value1 |
406
|
|
|
key2: This is a long sentence. |
407
|
|
|
--- |
408
|
|
|
My Article |
409
|
|
|
================================= |
410
|
|
|
|
411
|
|
|
This is an example on writing text and adding a YAML frontmatter. |
412
|
|
|
|
413
|
|
|
Subheading |
414
|
|
|
--------------------------------- |
415
|
|
|
|
416
|
|
|
More text. |
417
|
|
|
|
418
|
|
|
EOD; |
419
|
|
|
$res = $filter->parse($text, ["yamlfrontmatter", "markdown"]); |
420
|
|
|
$this->assertEquals( |
421
|
|
|
$res->frontmatter, |
422
|
|
|
[ |
423
|
|
|
"key1" => "value1", |
424
|
|
|
"key2" => "This is a long sentence." |
425
|
|
|
], |
426
|
|
|
"Frontmatter not matching" |
427
|
|
|
); |
428
|
|
|
|
429
|
|
|
$text = <<<EOD |
430
|
|
|
My Article |
431
|
|
|
================================= |
432
|
|
|
|
433
|
|
|
This is an example on writing text and adding a YAML frontmatter. |
434
|
|
|
|
435
|
|
|
Subheading |
436
|
|
|
--------------------------------- |
437
|
|
|
|
438
|
|
|
More text. |
439
|
|
|
|
440
|
|
|
EOD; |
441
|
|
|
$res = $filter->parse($text, ["yamlfrontmatter", "markdown"]); |
442
|
|
|
$this->assertEmpty($res->frontmatter, "Frontmatter should be empty"); |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
|
446
|
|
|
|
447
|
|
|
/** |
448
|
|
|
* Test. |
449
|
|
|
* |
450
|
|
|
* @return void |
451
|
|
|
*/ |
452
|
|
|
public function testGetFilters() |
453
|
|
|
{ |
454
|
|
|
$filter = new CTextFilter(); |
455
|
|
|
|
456
|
|
|
$filters = $filter->getFilters(); |
457
|
|
|
$res = array_diff($this->standardFilters, $filters); |
458
|
|
|
$this->assertTrue(empty($res), "Missmatch standard filters."); |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
|
462
|
|
|
|
463
|
|
|
|
464
|
|
|
/** |
465
|
|
|
* Test. |
466
|
|
|
* |
467
|
|
|
* @return void |
468
|
|
|
*/ |
469
|
|
|
public function testHasFilter() |
470
|
|
|
{ |
471
|
|
|
$filter = new CTextFilter(); |
472
|
|
|
|
473
|
|
|
$res = $filter->hasFilter("markdown"); |
474
|
|
|
$this->assertTrue($res, "Missmatch has filters."); |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
|
478
|
|
|
|
479
|
|
|
|
480
|
|
|
/** |
481
|
|
|
* Test. |
482
|
|
|
* |
483
|
|
|
* @expectedException /Mos/TextFilter/Exception |
484
|
|
|
* |
485
|
|
|
* @return void |
486
|
|
|
*/ |
487
|
|
|
public function testHasFilterException() |
488
|
|
|
{ |
489
|
|
|
$filter = new CTextFilter(); |
490
|
|
|
|
491
|
|
|
$filter->hasFilter("NOT EXISTING"); |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
|
495
|
|
|
|
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* Test. |
499
|
|
|
* |
500
|
|
|
* @return void |
501
|
|
|
*/ |
502
|
|
|
public function testPurifier() |
503
|
|
|
{ |
504
|
|
|
$filter = new CTextFilter(); |
505
|
|
|
|
506
|
|
|
$text = "Header\n========="; |
507
|
|
|
$exp = "<h1>Header</h1>\n"; |
508
|
|
|
$res = $filter->parse($text, ["markdown", "purify"]); |
509
|
|
|
$this->assertEquals($exp, $res->text, "Purify failed"); |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
|
513
|
|
|
|
514
|
|
|
/** |
515
|
|
|
* Test. |
516
|
|
|
* |
517
|
|
|
* @return void |
518
|
|
|
*/ |
519
|
|
View Code Duplication |
public function testMarkdown() |
|
|
|
|
520
|
|
|
{ |
521
|
|
|
$filter = new CTextFilter(); |
522
|
|
|
|
523
|
|
|
$html = "Header\n========="; |
524
|
|
|
$exp = "<h1>Header</h1>\n"; |
525
|
|
|
$res = $filter->doFilter($html, "markdown"); |
|
|
|
|
526
|
|
|
$this->assertEquals($exp, $res, "Markdown <h1> failed: '$res'"); |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
|
530
|
|
|
|
531
|
|
|
/** |
532
|
|
|
* Test. |
533
|
|
|
* |
534
|
|
|
* @return void |
535
|
|
|
*/ |
536
|
|
View Code Duplication |
public function testMarkdownAndBBCode() |
|
|
|
|
537
|
|
|
{ |
538
|
|
|
$filter = new CTextFilter(); |
539
|
|
|
|
540
|
|
|
$html = "Header[b]text[/b]\n========="; |
541
|
|
|
$exp = "<h1>Header<strong>text</strong></h1>\n"; |
542
|
|
|
$res = $filter->doFilter($html, "markdown, bbcode"); |
|
|
|
|
543
|
|
|
$this->assertEquals($exp, $res, "Markdown <h1> failed: '$res'"); |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
|
547
|
|
|
|
548
|
|
|
/** |
549
|
|
|
* Test. |
550
|
|
|
* |
551
|
|
|
* @return void |
552
|
|
|
*/ |
553
|
|
View Code Duplication |
public function testMarkdownAndBBCodeAsArray() |
|
|
|
|
554
|
|
|
{ |
555
|
|
|
$filter = new CTextFilter(); |
556
|
|
|
|
557
|
|
|
$html = "Header[b]text[/b]\n========="; |
558
|
|
|
$exp = "<h1>Header<strong>text</strong></h1>\n"; |
559
|
|
|
$res = $filter->doFilter($html, ["markdown", "bbcode"]); |
|
|
|
|
560
|
|
|
$this->assertEquals($exp, $res, "Markdown <h1> failed: '$res'"); |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
|
564
|
|
|
|
565
|
|
|
/** |
566
|
|
|
* Test. |
567
|
|
|
* |
568
|
|
|
* @return void |
569
|
|
|
*/ |
570
|
|
View Code Duplication |
public function testMarkdownArray() |
|
|
|
|
571
|
|
|
{ |
572
|
|
|
$filter = new CTextFilter(); |
573
|
|
|
|
574
|
|
|
$html = "Header\n========="; |
575
|
|
|
$exp = "<h1>Header</h1>\n"; |
576
|
|
|
$res = $filter->doFilter($html, ["markdown"]); |
|
|
|
|
577
|
|
|
$this->assertEquals($exp, $res, "Markdown <h1> failed: '$res'"); |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
|
581
|
|
|
|
582
|
|
|
/** |
583
|
|
|
* Test. |
584
|
|
|
* |
585
|
|
|
* @return void |
586
|
|
|
*/ |
587
|
|
View Code Duplication |
public function testUppercase() |
|
|
|
|
588
|
|
|
{ |
589
|
|
|
$filter = new CTextFilter(); |
590
|
|
|
|
591
|
|
|
$html = "Header\n========="; |
592
|
|
|
$exp = "<h1>Header</h1>\n"; |
593
|
|
|
$res = $filter->doFilter($html, "MARKDOWN"); |
|
|
|
|
594
|
|
|
$this->assertEquals($exp, $res, "Markdown <h1> failed: '$res'"); |
595
|
|
|
} |
596
|
|
|
|
597
|
|
|
|
598
|
|
|
|
599
|
|
|
/** |
600
|
|
|
* Test. |
601
|
|
|
* |
602
|
|
|
* @return void |
603
|
|
|
*/ |
604
|
|
View Code Duplication |
public function testBBCode() |
|
|
|
|
605
|
|
|
{ |
606
|
|
|
$filter = new CTextFilter(); |
607
|
|
|
|
608
|
|
|
$html = "[b]text[/b]"; |
609
|
|
|
$exp = "<strong>text</strong>"; |
610
|
|
|
$res = $filter->doFilter($html, "bbcode"); |
|
|
|
|
611
|
|
|
$this->assertEquals($exp, $res, "BBCode [b] failed: '$res'"); |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
|
615
|
|
|
|
616
|
|
|
/** |
617
|
|
|
* Test. |
618
|
|
|
* |
619
|
|
|
* @return void |
620
|
|
|
*/ |
621
|
|
View Code Duplication |
public function testClickable() |
|
|
|
|
622
|
|
|
{ |
623
|
|
|
$filter = new CTextFilter(); |
624
|
|
|
|
625
|
|
|
$html = "http://example.com/humans.txt"; |
626
|
|
|
$exp = "<a href='$html'>$html</a>"; |
627
|
|
|
$res = $filter->doFilter($html, "clickable"); |
|
|
|
|
628
|
|
|
$this->assertEquals($exp, $res, "clickable failed: '$res'"); |
629
|
|
|
} |
630
|
|
|
|
631
|
|
|
|
632
|
|
|
|
633
|
|
|
/** |
634
|
|
|
* Test. |
635
|
|
|
* |
636
|
|
|
* @return void |
637
|
|
|
*/ |
638
|
|
View Code Duplication |
public function testNl2Br() |
|
|
|
|
639
|
|
|
{ |
640
|
|
|
$filter = new CTextFilter(); |
641
|
|
|
|
642
|
|
|
$html = "hej\nhej"; |
643
|
|
|
$exp = "hej<br />\nhej"; |
644
|
|
|
$res = $filter->doFilter($html, "nl2br"); |
|
|
|
|
645
|
|
|
$this->assertEquals($exp, $res, "nl2br failed: '$res'"); |
646
|
|
|
} |
647
|
|
|
|
648
|
|
|
|
649
|
|
|
|
650
|
|
|
/** |
651
|
|
|
* Test. |
652
|
|
|
* |
653
|
|
|
* @return void |
654
|
|
|
*/ |
655
|
|
|
public function testShortCodeFigure() |
656
|
|
|
{ |
657
|
|
|
$filter = new CTextFilter(); |
658
|
|
|
|
659
|
|
|
$src = "/img/me.png"; |
660
|
|
|
$caption = "This is me."; |
661
|
|
|
|
662
|
|
|
$html = <<<EOD |
663
|
|
|
[FIGURE src=$src caption="$caption"] |
664
|
|
|
EOD; |
665
|
|
|
|
666
|
|
|
$exp = <<<EOD |
667
|
|
|
<figure class='figure'> |
668
|
|
|
<a href='$src'><img src='$src' alt='$caption'/></a> |
669
|
|
|
<figcaption markdown=1>$caption</figcaption> |
670
|
|
|
</figure> |
671
|
|
|
EOD; |
672
|
|
|
$res = $filter->doFilter($html, "shortcode"); |
|
|
|
|
673
|
|
|
$this->assertEquals($exp, $res, "shortcode failed: '$res'"); |
674
|
|
|
} |
675
|
|
|
|
676
|
|
|
|
677
|
|
|
|
678
|
|
|
/** |
679
|
|
|
* Test. |
680
|
|
|
* |
681
|
|
|
* @expectedException Exception |
682
|
|
|
* |
683
|
|
|
* @return void |
684
|
|
|
*/ |
685
|
|
|
public function testDoItException() |
686
|
|
|
{ |
687
|
|
|
$filter = new CTextFilter(); |
688
|
|
|
$filter->doFilter("void", "no-such-filter"); |
|
|
|
|
689
|
|
|
} |
690
|
|
|
} |
691
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.