BbcodeParserTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 1398
Duplicated Lines 0 %

Importance

Changes 9
Bugs 0 Features 1
Metric Value
eloc 831
c 9
b 0
f 1
dl 0
loc 1398
rs 9.769
wmc 5

64 Methods

Rating   Name   Duplication   Size   Complexity  
A testEmphasis() 0 6 1
A testBold() 0 6 1
A testStrike() 0 13 1
A testQuoteblock() 0 6 1
A testHr() 0 6 1
B hp$0 ➔ setUp() 0 107 1
A testUploadTypeFile() 0 13 1
A testFloat() 0 14 1
A testUploadTypeFileNoSource() 0 5 1
A testCodeWhitespace() 0 6 1
A testIframeAllDomainsAllowed() 0 9 1
A testEmbedDisabledWithAutolinking() 0 20 1
A hp$0 ➔ tearDown() 0 15 3
A testLinkAuto() 0 65 1
A testCodeNestedTags() 0 11 1
A testReturnText() 0 6 1
A hp$0 ➔ setSingle() 0 3 1
A testImageNestedInExternalLink() 0 23 1
A testHtml5Audio() 0 23 1
A testHashLinkSuccess() 0 48 1
A testEmailNoMailto() 0 12 1
A testFlash() 0 13 1
A testQuote() 0 15 1
setUp() 0 107 ?
A testUploadTypeAudio() 0 14 1
A testCodeLangAttribute() 0 6 1
A testLinkAutoUrlWithinParentheses() 0 49 1
A testHashLinkFailure() 0 11 1
A testSmiliesNoSmiliesInCodeTag() 0 6 1
A testEmailNoMailtoMask() 0 12 1
A testLinkEmptyUrl() 0 6 1
A testEditMarker() 0 13 1
A testEmailMailtoMask() 0 12 1
A testLinkAutoIgnoreLocalFiles() 0 5 1
A testLinkAutoWithoutHttpPrefix() 0 17 1
A testEmbedNoReplacement() 0 16 1
A testInternalImageAutoLinked() 0 44 1
A testList() 0 17 1
A testLinkAutoSurroundingChars() 0 51 1
tearDown() 0 15 ?
A testMaskLinkWithoutProtocol() 0 15 1
A testHrShort() 0 6 1
B testLink() 0 156 1
A testExternalImageAbsoluteAutoLinkedScaledByTwo() 0 18 1
A testUploadTypeImage() 0 18 1
A testCodeNoCitationMark() 0 9 1
A testUploadTypeFileSrcNotValid() 0 10 1
A testExternalImageAbsoluteAutoLinked() 0 17 1
A testHtml5Video() 0 22 1
A testIframeNoDomainAllowed() 0 11 1
A testEmbedDisabledWithoutAutolinking() 0 11 1
A testAtLinkKnownUsersLinebreak() 0 14 1
A testAtLinkKnownUsers() 0 20 1
A testInternalImageExternallyLinked() 0 20 1
A testParserEngineCaching() 0 7 1
A testCodeDetaginize() 0 5 1
A testSpoiler() 0 24 1
A testCodeSimple() 0 6 1
A testIframe() 0 37 1
A testEmailMailto() 0 12 1
A testExternalImageWithHttpsEnforced() 0 17 1
A testUploadTypeVideo() 0 13 1
A testExternalImageAbsoluteAutoLinkedScaledByOne() 0 17 1
A testExternalImageRelativeAutoLinked() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Saito - The Threaded Web Forum
7
 *
8
 * @copyright Copyright (c) the Saito Project Developers
9
 * @link https://github.com/Schlaefer/Saito
10
 * @license http://opensource.org/licenses/MIT
11
 */
12
13
namespace BbcodeParser\Test\Lib;
14
15
use App\View\Helper\ParserHelper;
16
use Cake\Cache\Cache;
17
use Cake\Core\Configure;
18
use Cake\View\View;
19
use Plugin\BbcodeParser\Lib;
0 ignored issues
show
Bug introduced by
The type Plugin\BbcodeParser\Lib was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Plugin\BbcodeParser\src\Lib\Parser;
21
use Saito\Markup\MarkupSettings;
22
use Saito\Test\SaitoTestCase;
23
use Saito\User\Userlist;
24
use Saito\User\Userlist\UserlistModel;
25
26
class BbcodeParserTest extends SaitoTestCase
27
{
28
29
    /**
30
     * @var Parser
31
     */
32
    protected $_Parser = null;
33
34
    /** @var MarkupSettings */
35
    protected $MarkupSettings;
36
37
    public function testBold()
38
    {
39
        $input = '[b]bold[/b]';
40
        $expected = ['strong' => [], 'bold', '/strong'];
41
        $result = $this->_Parser->parse($input);
42
        $this->assertHtml($expected, $result);
43
    }
44
45
    public function testEmphasis()
46
    {
47
        $input = '[i]italic[/i]';
48
        $expected = ['em' => [], 'italic', '/em'];
49
        $result = $this->_Parser->parse($input);
50
        $this->assertHtml($expected, $result);
51
    }
52
53
    public function testQuoteblock()
54
    {
55
        $input = '[quote]foo bar[/quote]';
56
        $expected = ['blockquote' => [], 'foo bar', '/blockquote'];
57
        $result = $this->_Parser->parse($input);
58
        $this->assertHtml($expected, $result);
59
    }
60
61
    public function testStrike()
62
    {
63
        $expected = ['del' => [], 'text', '/del'];
64
65
        // [strike]
66
        $input = '[strike]text[/strike]';
67
        $result = $this->_Parser->parse($input);
68
        $this->assertHtml($expected, $result);
69
70
        // [s]
71
        $input = '[s]text[/s]';
72
        $result = $this->_Parser->parse($input);
73
        $this->assertHtml($expected, $result);
74
    }
75
76
    public function testSpoiler()
77
    {
78
        $input = 'pre [spoiler] te "\' xt[/spoiler]';
79
        $expected = [
80
            'pre',
81
            [
82
                'div' => [
83
                    'class' => 'richtext-spoiler',
84
                    'style' => 'display: inline;',
85
                ],
86
            ],
87
            [
88
                'a' => [
89
                    'href' => '#',
90
                    'class' => 'richtext-spoiler-link',
91
                    'onclick' => 'preg:/.*" te &amp;quot;&amp;#039; xt".*/',
92
                ],
93
            ],
94
            'preg:/.*▇ Spoiler ▇.*?(?=<)/',
95
            '/a',
96
            '/div',
97
        ];
98
        $result = $this->_Parser->parse($input);
99
        $this->assertHtml($expected, $result);
100
    }
101
102
    public function testList()
103
    {
104
        $input = "[list]\n[*]fooo\n[*]bar\n[/list]";
105
        $expected = [
106
            ['ul' => []],
107
            ['li' => []],
108
            'fooo',
109
            ['br' => []],
110
            '/li',
111
            ['li' => []],
112
            'bar',
113
            ['br' => []],
114
            '/li',
115
            '/ul',
116
        ];
117
        $result = $this->_Parser->parse($input);
118
        $this->assertHtml($expected, $result);
119
    }
120
121
    public function testMaskLinkWithoutProtocol()
122
    {
123
        $input = '[url=thetempe.st/station]purge[/url]';
124
        $expected = [
125
            'a' => [
126
                'href' => 'http://thetempe.st/station',
127
                'class' => 'richtext-link',
128
                'rel' => 'external',
129
                'target' => '_blank',
130
            ],
131
            'purge',
132
            '/a',
133
        ];
134
        $result = $this->_Parser->parse($input);
135
        $this->assertHtml($expected, $result);
136
    }
137
138
    public function testParserEngineCaching()
139
    {
140
        $input = '[img=]foo.png[/img]';
141
        $result = $this->_Parser->parse($input, ['multimedia' => true]);
142
        $this->assertContains('<img src', $result);
143
        $result = $this->_Parser->parse($input, ['multimedia' => false]);
144
        $this->assertNotContains('<img src', $result);
145
    }
146
147
    public function testLink()
148
    {
149
        $input = '[url=http://cgi.ebay.de/ws/eBayISAPI.dll?ViewItem&item=250678480561&ssPageName=ADME:X:RTQ:DE:1123]test[/url]';
150
        $result = $this->_Parser->parse($input);
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
151
        $expected = [
152
            'a' => [
153
                'href' => 'http://cgi.ebay.de/ws/eBayISAPI.dll?ViewItem&amp;item=250678480561&amp;ssPageName=ADME:X:RTQ:DE:1123',
154
                'class' => 'richtext-link',
155
                'rel' => 'external',
156
                'target' => '_blank',
157
            ],
158
            'test',
159
            '/a',
160
            'span' => [
161
                'class' => 'richtext-linkInfo',
162
            ],
163
            '[ebay.de]',
164
            '/span',
165
        ];
166
        $result = $this->_Parser->parse($input);
167
        $this->assertHtml($expected, $result);
168
169
        /*
170
         * external server
171
         */
172
        $input = '[url]http://heise.de/foobar[/url]';
173
        $expected = [
174
            'a' => [
175
                'href' => 'http://heise.de/foobar',
176
                'class' => 'richtext-link truncate',
177
                'rel' => 'external',
178
                'target' => '_blank',
179
            ],
180
            'http://heise.de/foobar',
181
            '/a',
182
        ];
183
        $result = $this->_Parser->parse($input);
184
        $this->assertHtml($expected, $result);
185
186
        $input = '[link]http://heise.de/foobar[/link]';
187
        $expected = [
188
            'a' => [
189
                'href' => 'http://heise.de/foobar',
190
                'class' => 'richtext-link truncate',
191
                'rel' => 'external',
192
                'target' => '_blank',
193
            ],
194
            'http://heise.de/foobar',
195
            '/a',
196
        ];
197
        $result = $this->_Parser->parse($input);
198
        $this->assertHtml($expected, $result);
199
200
        // masked link
201
        $input = '[url=http://heise.de/foobar]foobar[/url]';
202
        $expected = [
203
            'a' => [
204
                'href' => 'http://heise.de/foobar',
205
                'class' => 'richtext-link',
206
                'rel' => 'external',
207
                'target' => '_blank',
208
            ],
209
            'foobar',
210
            '/a',
211
            'span' => ['class' => 'richtext-linkInfo'],
212
            '[heise.de]',
213
            '/span',
214
        ];
215
        $result = $this->_Parser->parse($input);
216
        $this->assertHtml($expected, $result);
217
218
        // masked link with no label
219
        $input = '[url=http://heise.de/foobar  label=none ]foobar[/url]';
220
        $expected = [
221
            'a' => [
222
                'href' => 'http://heise.de/foobar',
223
                'class' => 'richtext-link',
224
                'rel' => 'external',
225
                'target' => '_blank',
226
            ],
227
            'foobar',
228
            '/a',
229
        ];
230
        $result = $this->_Parser->parse($input);
231
        $this->assertHtml($expected, $result);
232
233
        /*
234
         * local server
235
         */
236
        $input = '[url=http://macnemo.de/foobar]foobar[/url]';
237
        $expected = [
238
            'a' => [
239
                'href' => 'http://macnemo.de/foobar',
240
                'class' => 'richtext-link',
241
            ],
242
            'foobar',
243
            '/a',
244
        ];
245
        $result = $this->_Parser->parse($input);
246
        $this->assertHtml($expected, $result);
247
248
        $input = '[url]/foobar[/url]';
249
        $expected = [
250
            'a' => [
251
                'href' => '/foobar',
252
                'class' => 'richtext-link truncate',
253
            ],
254
            'preg:/\/foobar/',
255
            '/a',
256
        ];
257
        $result = $this->_Parser->parse($input);
258
        $this->assertHtml($expected, $result);
259
260
        // test lokaler server with absolute url
261
        $input = '[url=/foobar]foobar[/url]';
262
        $expected = [
263
            'a' => [
264
                'href' => '/foobar',
265
                'class' => 'richtext-link',
266
            ],
267
            'foobar',
268
            '/a',
269
        ];
270
        $result = $this->_Parser->parse($input);
271
        $this->assertHtml($expected, $result);
272
273
        // test 'http://' only
274
        $input = '[url=http://]foobar[/url]';
275
        $expected = [
276
            'a' => [
277
                'href' => 'http://',
278
                'class' => 'richtext-link',
279
            ],
280
            'foobar',
281
            '/a',
282
        ];
283
        $result = $this->_Parser->parse($input);
284
        $this->assertHtml($expected, $result);
285
286
        // test for co.uk
287
        $input = '[url=http://heise.co.uk/foobar]foobar[/url]';
288
        $expected = [
289
            'a' => [
290
                'href' => 'http://heise.co.uk/foobar',
291
                'class' => 'richtext-link',
292
                'rel' => 'external',
293
                'target' => '_blank',
294
            ],
295
            'foobar',
296
            '/a',
297
            'span' => ['class' => 'richtext-linkInfo'],
298
            '[heise.co.uk]',
299
            '/span',
300
        ];
301
        $result = $this->_Parser->parse($input);
302
        $this->assertHtml($expected, $result);
303
    }
304
305
    public function testHashLinkSuccess()
306
    {
307
        // inline content ([i])
308
        $input = "[i]#2234[/i]";
309
        $expected = [
310
            'em' => [],
311
            'a' => [
312
                'class' => 'richtext-link',
313
                'href' => '/hash/2234',
314
            ],
315
            '#2234',
316
            '/a',
317
            '/em',
318
        ];
319
        $result = $this->_Parser->parse($input);
320
        $this->assertHtml($expected, $result);
321
322
        // lists
323
        $input = "[list][*]#2234[/list]";
324
        $expected = [
325
            'ul' => true,
326
            'li' => true,
327
            'a' => [
328
                'class' => 'richtext-link',
329
                'href' => '/hash/2234',
330
            ],
331
            '#2234',
332
            '/a',
333
            '/li',
334
            '/ul',
335
        ];
336
        $result = $this->_Parser->parse($input);
337
        $this->assertHtml($expected, $result);
338
339
        /// in paranthesis
340
        $input = "foo (#2234) bar";
341
        $expected = [
342
            'foo (',
343
            'a' => [
344
                'class' => 'richtext-link',
345
                'href' => '/hash/2234',
346
            ],
347
            '#2234',
348
            '/a',
349
            ') bar',
350
        ];
351
        $result = $this->_Parser->parse($input);
352
        $this->assertHtml($expected, $result);
353
    }
354
355
    public function testHashLinkFailure()
356
    {
357
        // don't hash code
358
        $input = '[code]#2234[/code]';
359
        $result = $this->_Parser->parse($input);
360
        $this->assertNotContains('>#2234</a>', $result);
361
362
        // not a valid hash
363
        $input = '#2234t';
364
        $result = $this->_Parser->parse($input);
365
        $this->assertEquals('#2234t', $result);
366
    }
367
368
    public function testAtLinkKnownUsers()
369
    {
370
        $input = '@Alice @Bob @Bobby Junior @Bobby Tables @Dr. No';
371
        $expected =
372
            "<a href='/at/Alice' class=\"richtext-link\">@Alice</a>" .
373
            " @Bob " .
374
            "<a href='/at/Bobby+Junior' class=\"richtext-link\">@Bobby Junior</a>" .
375
            " @Bobby Tables " .
376
            "<a href='/at/Dr.+No' class=\"richtext-link\">@Dr. No</a>";
377
378
        $result = $this->_Parser->parse($input);
379
        $this->assertEquals(
380
            $expected,
381
            $result,
382
            '@User string is not replaced with link to user profile.'
383
        );
384
385
        $input = '[code]@Alice[/code]';
386
        $result = $this->_Parser->parse($input);
387
        $this->assertNotContains('>@Alice</a>', $result);
388
    }
389
390
    public function testAtLinkKnownUsersLinebreak()
391
    {
392
        $input = "@Alice\nfoo";
393
        $result = $this->_Parser->parse($input);
394
        $expected = [
395
            'a' => [
396
                'class' => 'richtext-link',
397
                'href' => '/at/Alice',
398
            ],
399
            '@Alice',
400
            '/a',
401
            'br' => true,
402
        ];
403
        $this->assertHtml($expected, $result);
404
    }
405
406
    public function testLinkEmptyUrl()
407
    {
408
        $input = '[url=][/url]';
409
        $expected = "<a href='' class=\"richtext-link\"></a>";
410
        $result = $this->_Parser->parse($input);
411
        $this->assertEquals($expected, $result);
412
    }
413
414
    public function testEditMarker()
415
    {
416
        $input = 'pre [e] post';
417
        $expected = [
418
            'pre ',
419
            'span' => [
420
                'class' => 'richtext-editMark',
421
            ],
422
            '/span',
423
            ' post',
424
        ];
425
        $result = $this->_Parser->parse($input);
426
        $this->assertHtml($expected, $result);
427
    }
428
429
    /*
430
     * without obfuscator
431
     *
432
    public function testEmail() {
433
        /*
434
            // mailto:
435
            $input = '[email]mailto:[email protected][/email]';
436
            $expected = "<a href='mailto:[email protected]'>mailto:[email protected]</a>";
437
            $result = $this->Bbcode->parse($input);
438
            $this->assertEquals($expected, $result);
439
440
            // mailto: mask
441
            $input = '[email=mailto:[email protected]]Mail[/email]';
442
            $expected = "<a href='mailto:[email protected]'>Mail</a>";
443
            $result = $this->Bbcode->parse($input);
444
            $this->assertEquals($expected, $result);
445
446
            // no mailto:
447
            $input = '[email][email protected][/email]';
448
            $expected = "<a href='mailto:[email protected]'>[email protected]</a>";
449
            $result = $this->Bbcode->parse($input);
450
            $this->assertEquals($expected, $result);
451
452
            // no mailto: mask
453
            $input = '[[email protected]]Mail[/email]';
454
            $expected = "<a href='mailto:[email protected]'>Mail</a>";
455
            $result = $this->Bbcode->parse($input);
456
            $this->assertEquals($expected, $result);
457
    }
458
            */
459
460
    public function testEmailMailto()
461
    {
462
        $MO = $this->getMockBuilder('MailObfuscator')
463
            ->setMethods(['link'])
464
            ->getMock();
465
        $MO->expects($this->once(4))
0 ignored issues
show
Unused Code introduced by
The call to PHPUnit\Framework\TestCase::once() has too many arguments starting with 4. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

465
        $MO->expects($this->/** @scrutinizer ignore-call */ once(4))

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
466
            ->method('link')
467
            ->with('[email protected]', null);
468
        $this->_Helper->MailObfuscator = $MO;
469
470
        $input = '[email]mailto:[email protected][/email]';
471
        $this->_Parser->parse($input);
472
    }
473
474
    public function testEmailMailtoMask()
475
    {
476
        $MO = $this->getMockBuilder('MailObfuscator')
477
            ->setMethods(['link'])
478
            ->getMock();
479
        $MO->expects($this->once(4))
0 ignored issues
show
Unused Code introduced by
The call to PHPUnit\Framework\TestCase::once() has too many arguments starting with 4. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

479
        $MO->expects($this->/** @scrutinizer ignore-call */ once(4))

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
480
            ->method('link')
481
            ->with('[email protected]', 'Mail');
482
        $this->_Helper->MailObfuscator = $MO;
483
484
        $input = '[email=mailto:[email protected]]Mail[/email]';
485
        $this->_Parser->parse($input);
486
    }
487
488
    public function testEmailNoMailto()
489
    {
490
        $MO = $this->getMockBuilder('MailObfuscator')
491
            ->setMethods(['link'])
492
            ->getMock();
493
        $MO->expects($this->once(4))
0 ignored issues
show
Unused Code introduced by
The call to PHPUnit\Framework\TestCase::once() has too many arguments starting with 4. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

493
        $MO->expects($this->/** @scrutinizer ignore-call */ once(4))

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
494
            ->method('link')
495
            ->with('[email protected]', null);
496
        $this->_Helper->MailObfuscator = $MO;
497
498
        $input = '[email][email protected][/email]';
499
        $this->_Parser->parse($input);
500
    }
501
502
    public function testEmailNoMailtoMask()
503
    {
504
        $MO = $this->getMockBuilder('MailObfuscator')
505
            ->setMethods(['link'])
506
            ->getMock();
507
        $MO->expects($this->once(4))
0 ignored issues
show
Unused Code introduced by
The call to PHPUnit\Framework\TestCase::once() has too many arguments starting with 4. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

507
        $MO->expects($this->/** @scrutinizer ignore-call */ once(4))

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
508
            ->method('link')
509
            ->with('[email protected]', 'Mail');
510
        $this->_Helper->MailObfuscator = $MO;
511
512
        $input = '[[email protected]]Mail[/email]';
513
        $this->_Parser->parse($input);
514
    }
515
516
    public function testFlash()
517
    {
518
        $bbcode = '[flash_video]//www.youtube.com/v/MrBRPYlrGF8?version=3&amp;hl=en_US|560|315[/flash_video]';
519
        $expected = <<<EOF
520
			<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="560" height="315">
521
									<param name="movie" value="//www.youtube.com/v/MrBRPYlrGF8?version=3&amp;amp;hl=en_US"></param>
522
									<embed src="//www.youtube.com/v/MrBRPYlrGF8?version=3&amp;amp;hl=en_US" width="560" height="315" type="application/x-shockwave-flash" wmode="opaque" style="width:560px; height:315px;" id="VideoPlayback" flashvars=""> </embed> </object>
523
EOF;
524
        $actual = $this->_Parser->parse(
525
            $bbcode,
526
            ['video_domains_allowed' => 'youtube']
527
        );
528
        $this->assertEquals(trim($expected), trim($actual));
529
    }
530
531
    public function testFloat()
532
    {
533
        $expected = [
534
            ['div' => ['class' => 'clearfix']],
535
            '/div',
536
            ['div' => ['class' => 'richtext-float']],
537
            'text',
538
            '/div',
539
            'more',
540
        ];
541
542
        $input = '[float]text[/float]more';
543
        $result = $this->_Parser->parse($input);
544
        $this->assertHtml($expected, $result);
545
    }
546
547
    public function testLinkAuto()
548
    {
549
        $input = 'http://heise.de/foobar';
550
        $expected = [
551
            'a' => [
552
                'class' => 'richtext-link truncate',
553
                'href' => 'http://heise.de/foobar',
554
                'rel' => 'external',
555
                'target' => '_blank',
556
            ],
557
            'http://heise.de/foobar',
558
            '/a',
559
        ];
560
        $result = $this->_Parser->parse($input);
561
        $this->assertHtml($expected, $result);
562
563
        // autolink surrounded by text
564
        $input = 'some http://heise.de/foobar text';
565
        $expected = "some <a href='http://heise.de/foobar' rel='external' target='_blank'>http://heise.de/foobar</a> text";
0 ignored issues
show
Unused Code introduced by
The assignment to $expected is dead and can be removed.
Loading history...
566
        $expected = [
567
            'some ',
568
            'a' => [
569
                'class' => 'richtext-link truncate',
570
                'href' => 'http://heise.de/foobar',
571
                'rel' => 'external',
572
                'target' => '_blank',
573
            ],
574
            'http://heise.de/foobar',
575
            '/a',
576
            ' text',
577
        ];
578
        $result = $this->_Parser->parse($input);
579
        $this->assertHtml($expected, $result);
580
581
        // no autolink in [code]
582
        $input = '[code]http://heise.de/foobar[/code]';
583
        $needle = 'heise.de/foobar</a>';
584
        $result = $this->_Parser->parse($input);
585
        $this->assertNotContains($result, $needle);
586
587
        // no autolink in [url]
588
        $input = '[url=http://a.com/]http://b.de/[/url]';
589
        $result = $this->_Parser->parse($input);
590
        $this->assertRegExp(
591
            '#href=["\']http://a.com/["\'][^>]*?>http://b.de/#',
592
            $result
593
        );
594
595
        // email autolink
596
        $input = 'text [email protected] test';
597
        // $expected = "text <a href='mailto:[email protected]'>[email protected]</a> test";
598
        $result = $this->_Parser->parse($input);
599
        // $this->assertEquals($expected, $result);
600
        // @bogus weak test
601
        $this->assertRegExp('/^text .*href=".* test$/sm', $result);
602
603
        //# in list
604
        $input = <<<EOF
605
[list]
606
[*] http://heise.de
607
[/list]
608
EOF;
609
        $result = $this->_Parser->parse($input);
610
        $expected = "<a href='http://heise.de";
611
        $this->assertTextContains($expected, $result);
612
    }
613
614
    public function testLinkAutoWithoutHttpPrefix()
615
    {
616
        $input = 'some www.example.com/foobar text';
617
        $expected = [
618
            'some ',
619
            'a' => [
620
                'href' => 'http://www.example.com/foobar',
621
                'class' => 'richtext-link truncate',
622
                'rel' => 'external',
623
                'target' => '_blank',
624
            ],
625
            'http://www.example.com/foobar',
626
            '/a',
627
            ' text',
628
        ];
629
        $result = $this->_Parser->parse($input);
630
        $this->assertHtml($expected, $result);
631
    }
632
633
    public function testLinkAutoUrlWithinParentheses()
634
    {
635
        $input = 'some (www.example.com/foobar) text';
636
        $expected = [
637
            'some (',
638
            'a' => [
639
                'class' => 'richtext-link truncate',
640
                'href' => 'http://www.example.com/foobar',
641
                'rel' => 'external',
642
                'target' => '_blank',
643
            ],
644
            'http://www.example.com/foobar',
645
            '/a',
646
            ') text',
647
        ];
648
        $result = $this->_Parser->parse($input);
649
        $this->assertHtml($expected, $result);
650
651
        $input = 'some (www.example.com/foo_(bar)) text';
652
        $expected = [
653
            'some (',
654
            'a' => [
655
                'class' => 'richtext-link truncate',
656
                'href' => 'http://www.example.com/foo_(bar)',
657
                'rel' => 'external',
658
                'target' => '_blank',
659
            ],
660
            'http://www.example.com/foo_(bar)',
661
            '/a',
662
            ') text',
663
        ];
664
        $result = $this->_Parser->parse($input);
665
        $this->assertHtml($expected, $result);
666
667
        $input = 'some www.example.com/foo_(bar) text';
668
        $expected = [
669
            'some ',
670
            'a' => [
671
                'class' => 'richtext-link truncate',
672
                'href' => 'http://www.example.com/foo_(bar)',
673
                'rel' => 'external',
674
                'target' => '_blank',
675
            ],
676
            'http://www.example.com/foo_(bar)',
677
            '/a',
678
            ' text',
679
        ];
680
        $result = $this->_Parser->parse($input);
681
        $this->assertHtml($expected, $result);
682
    }
683
684
    public function testLinkAutoSurroundingChars()
685
    {
686
        $input = 'text http://example.com/?foo,,, text';
687
        $result = $this->_Parser->parse($input);
688
        $expected = [
689
            'text ',
690
            'a' => [
691
                'class' => 'richtext-link truncate',
692
                'href' => 'http://example.com/?foo,,',
693
                'rel' => 'external',
694
                'target' => '_blank',
695
            ],
696
            'http://example.com/?foo,,',
697
            '/a',
698
            ', text',
699
        ];
700
        $this->assertHtml($expected, $result);
701
702
        // Question mark
703
        $input = 'question http://example.com/? Text';
704
        $result = $this->_Parser->parse($input);
705
        $expected = [
706
            'question ',
707
            'a' => [
708
                'class' => 'richtext-link truncate',
709
                'href' => 'http://example.com/',
710
                'rel' => 'external',
711
                'target' => '_blank',
712
            ],
713
            'http://example.com/',
714
            '/a',
715
            '? Text',
716
        ];
717
        $this->assertHtml($expected, $result);
718
719
        // No Question mark but url
720
        $input = 'no question http://example.com/?foo=bar text';
721
        $result = $this->_Parser->parse($input);
722
        $expected = [
723
            'no question ',
724
            'a' => [
725
                'class' => 'richtext-link truncate',
726
                'href' => 'http://example.com/?foo=bar',
727
                'rel' => 'external',
728
                'target' => '_blank',
729
            ],
730
            'http://example.com/?foo=bar',
731
            '/a',
732
            ' text',
733
        ];
734
        $this->assertHtml($expected, $result);
735
    }
736
737
    public function testLinkAutoIgnoreLocalFiles()
738
    {
739
        $input = 'a file:///foo.bar b file://foo c file:// d file:///';
740
        $result = $this->_Parser->parse($input);
741
        $this->assertEquals($input, $result);
742
    }
743
744
    public function testReturnText()
745
    {
746
        $in = 'test [b]test[b] test';
747
        $expected = 'test test test';
748
        $actual = $this->_Parser->parse($in, ['return' => 'text']);
749
        $this->assertEquals($expected, $actual);
750
    }
751
752
    public function testIframe()
753
    {
754
        //* test allowed domain
755
        $input = '[iframe height=349 width=560 ' .
756
            'src=http://www.youtube.com/embed/HdoW3t_WorU ' .
757
            'frameborder=0][/iframe]';
758
        $expected = [
759
            [
760
                'div' => [
761
                    'class' => 'embed-responsive embed-responsive-16by9',
762
                ],
763
                'iframe' => [
764
                    'class' => 'embed-responsive-item',
765
                    'src' => 'http://www.youtube.com/embed/HdoW3t_WorU?&amp;wmode=Opaque',
766
                    'height' => '349',
767
                    'width' => '560',
768
                    'frameborder' => '0',
769
                ],
770
            ],
771
            '/iframe',
772
        ];
773
        $result = $this->_Parser->parse(
774
            $input,
775
            ['video_domains_allowed' => 'youtube | vimeo']
776
        );
777
        $this->assertHtml($expected, $result);
778
779
        //* test forbidden domains
780
        $input = '[iframe height=349 width=560 ' .
781
            'src=http://www.youtubescam.com/embed/HdoW3t_WorU ' .
782
            'frameborder=0][/iframe]';
783
        $pattern = '/src/i';
784
        $result = $this->_Parser->parse(
785
            $input,
786
            ['video_domains_allowed' => 'youtube | vimeo']
787
        );
788
        $this->assertNotRegExp($pattern, $result);
789
    }
790
791
    public function testIframeAllDomainsAllowed()
792
    {
793
        $input = '[iframe height=349 width=560 ' .
794
            'src=http://www.youtubescam.com/embed/HdoW3t_WorU ' .
795
            '][/iframe]';
796
        $expected = 'src="http://www.youtubescam.com/embed/HdoW3t_WorU';
797
        $this->MarkupSettings->setSingle('video_domains_allowed', '*');
0 ignored issues
show
introduced by
The method setSingle() does not exist on Saito\Markup\MarkupSettings. Maybe you want to declare this class abstract? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

797
        $this->MarkupSettings->/** @scrutinizer ignore-call */ 
798
                               setSingle('video_domains_allowed', '*');
Loading history...
798
        $result = $this->_Parser->parse($input);
799
        $this->assertContains($expected, $result);
800
    }
801
802
    public function testIframeNoDomainAllowed()
803
    {
804
        $input = '[iframe height=349 width=560 ' .
805
            'src=http://www.youtubescam.com/embed/HdoW3t_WorU ' .
806
            '][/iframe]';
807
        $expected = '/src/i';
808
        $result = $this->_Parser->parse(
809
            $input,
810
            ['video_domains_allowed' => '']
811
        );
812
        $this->assertNotRegExp($expected, $result);
813
    }
814
815
    public function testExternalImageAbsoluteAutoLinked()
816
    {
817
        // test for standard URIs
818
        $input = '[img]http://foo.bar/img/macnemo.png[/img]';
819
        $expected = [
820
            'a' => [
821
                'href' => 'http://foo.bar/img/macnemo.png',
822
                // 'rel' => 'external',
823
                'target' => '_blank',
824
            ],
825
            'img' => [
826
                'src' => 'http://foo.bar/img/macnemo.png',
827
                'alt' => '',
828
            ],
829
        ];
830
        $result = $this->_Parser->parse($input);
831
        $this->assertHtml($expected, $result);
832
    }
833
834
    public function testExternalImageRelativeAutoLinked()
835
    {
836
        // test for standard URIs
837
        $input = '[img]/somewhere/macnemo.png[/img]';
838
        $expected = [
839
            'a' => [
840
                'href' => '/somewhere/macnemo.png',
841
                'target' => '_blank',
842
            ],
843
            'img' => [
844
                'src' => '/somewhere/macnemo.png',
845
                'alt' => '',
846
            ],
847
        ];
848
        $result = $this->_Parser->parse($input);
849
        $this->assertHtml($expected, $result);
850
    }
851
852
    /**
853
     * test scaling with 1 parameter
854
     */
855
    public function testExternalImageAbsoluteAutoLinkedScaledByOne()
856
    {
857
        // test for standard URIs
858
        $input = '[img=50]http://foo.bar/img/macnemo.png[/img]';
859
        $expected = [
860
            'a' => [
861
                'href' => 'http://foo.bar/img/macnemo.png',
862
                'target' => '_blank',
863
            ],
864
            'img' => [
865
                'src' => 'http://foo.bar/img/macnemo.png',
866
                'alt' => '',
867
                'width' => '50',
868
            ],
869
        ];
870
        $result = $this->_Parser->parse($input);
871
        $this->assertHtml($expected, $result);
872
    }
873
874
    /**
875
     * test scaling with 2 parameter
876
     */
877
    public function testExternalImageAbsoluteAutoLinkedScaledByTwo()
878
    {
879
        // test for standard URIs
880
        $input = '[img=50x100]http://foo.bar/img/macnemo.png[/img]';
881
        $expected = [
882
            'a' => [
883
                'href' => 'http://foo.bar/img/macnemo.png',
884
                'target' => '_blank',
885
            ],
886
            'img' => [
887
                'src' => 'http://foo.bar/img/macnemo.png',
888
                'alt' => '',
889
                'height' => '100',
890
                'width' => '50',
891
            ],
892
        ];
893
        $result = $this->_Parser->parse($input);
894
        $this->assertHtml($expected, $result);
895
    }
896
897
    public function testExternalImageWithHttpsEnforced()
898
    {
899
        $_SERVER['HTTPS'] = true;
900
        $input = '[img=]http://foo.bar/img/macnemo.png[/img]';
901
        $expected = [
902
            'a' => [
903
                'href' => 'https://foo.bar/img/macnemo.png',
904
                'target' => '_blank',
905
            ],
906
            'img' => [
907
                'src' => 'https://foo.bar/img/macnemo.png',
908
                'alt' => '',
909
            ],
910
        ];
911
        $result = $this->_Parser->parse($input);
912
        $this->assertHtml($expected, $result);
913
        unset($_SERVER['HTTPS']);
914
    }
915
916
    public function testImageNestedInExternalLink()
917
    {
918
        $input = '[url=http://heise.de][img]http://heise.de/img.png[/img][/url]';
919
920
        $expected = [
921
            [
922
                'a' => [
923
                    'class' => 'richtext-link',
924
                    'href' => 'http://heise.de',
925
                    'rel' => 'external',
926
                    'target' => '_blank',
927
                ],
928
            ],
929
            [
930
                'img' => [
931
                    'src' => 'http://heise.de/img.png',
932
                    'alt' => '',
933
                ],
934
            ],
935
            '/a',
936
        ];
937
        $result = $this->_Parser->parse($input);
938
        $this->assertHtml($expected, $result);
939
    }
940
941
    /**
942
     * [uploads]<image>[/uploads]
943
     */
944
    public function testInternalImageAutoLinked()
945
    {
946
        //// internal image
947
        $input = '[upload]test.png[/upload]';
948
        $expected = [
949
            [
950
                'a' => [
951
                    'href' => '/useruploads/test.png',
952
                    'target' => '_blank',
953
                ],
954
                'img' => [
955
                    'alt' => '',
956
                    'src' => '/useruploads/test.png',
957
                ],
958
            ],
959
        ];
960
        $result = $this->_Parser->parse($input);
961
        $this->assertHtml($expected, $result);
962
963
        //// internal image with attributes
964
        $input = '[upload width=50 height=60]test.png[/upload]';
965
        $expected = [
966
            [
967
                'a' => [
968
                    'href' => '/useruploads/test.png',
969
                    'target' => '_blank',
970
                ],
971
                'img' =>
972
                    [
973
                        'alt' => '',
974
                        'src' => '/useruploads/test.png',
975
                        'width' => '50',
976
                        'height' => '60',
977
                    ],
978
            ],
979
        ];
980
        $result = $this->_Parser->parse($input);
981
        $this->assertHtml($expected, $result);
982
983
        // nested image does not have [domain.info]
984
        $input = '[url=http://heise.de][upload]test.png[/upload][/url]';
985
        $expected = "/richtext-linkInfo/";
986
        $result = $this->_Parser->parse($input);
987
        $this->assertNotRegExp($expected, $result);
988
    }
989
990
    public function testInternalImageExternallyLinked()
991
    {
992
        /// internal image
993
        $input = '[url=http://foo.de][upload]test.png[/upload][/url]';
994
        $expected = [
995
            [
996
                'a' => [
997
                    'class' => 'richtext-link',
998
                    'href' => 'http://foo.de',
999
                    'rel' => 'external',
1000
                    'target' => '_blank',
1001
                ],
1002
                'img' => [
1003
                    'src' => '/useruploads/test.png',
1004
                    'alt' => '',
1005
                ],
1006
            ],
1007
        ];
1008
        $result = $this->_Parser->parse($input);
1009
        $this->assertHtml($expected, $result);
1010
    }
1011
1012
    public function testUploadTypeImage()
1013
    {
1014
        //// internal image
1015
        $input = '[img src=upload]test.png[/img]';
1016
        $expected = [
1017
            [
1018
                'a' => [
1019
                    'href' => '/useruploads/test.png',
1020
                    'target' => '_blank',
1021
                ],
1022
                'img' => [
1023
                    'src' => '/useruploads/test.png',
1024
                    'alt' => '',
1025
                ],
1026
            ],
1027
        ];
1028
        $result = $this->_Parser->parse($input);
1029
        $this->assertHtml($expected, $result);
1030
    }
1031
1032
    public function testUploadTypeAudio()
1033
    {
1034
        /// internal image
1035
        $input = '[audio src=upload]test.mp3[/audio]';
1036
        $expected = [
1037
            'audio' => [
1038
                'controls' => 'controls',
1039
                'preload' => 'auto',
1040
                'src' => '/useruploads/test.mp3',
1041
                'x-webkit-airplay' => 'allow',
1042
            ],
1043
        ];
1044
        $result = $this->_Parser->parse($input);
1045
        $this->assertHtml($expected, $result);
1046
    }
1047
1048
    public function testUploadTypeVideo()
1049
    {
1050
        $input = '[video src=upload]test.mp4[/video]';
1051
        $expected = [
1052
            'video' => [
1053
                'controls' => 'controls',
1054
                'preload' => 'auto',
1055
                'src' => '/useruploads/test.mp4',
1056
                'x-webkit-airplay' => 'allow',
1057
            ],
1058
        ];
1059
        $result = $this->_Parser->parse($input);
1060
        $this->assertHtml($expected, $result);
1061
    }
1062
1063
    public function testUploadTypeFile()
1064
    {
1065
        $input = '[file src=upload]test.txt[/file]';
1066
        $expected = [
1067
            'a' => [
1068
                'href' => '/useruploads/test.txt',
1069
                'target' => '_blank',
1070
            ],
1071
            'test.txt',
1072
            '/a',
1073
        ];
1074
        $result = $this->_Parser->parse($input);
1075
        $this->assertHtml($expected, $result);
1076
    }
1077
1078
    public function testUploadTypeFileSrcNotValid()
1079
    {
1080
        $input = '[file src=foo]test.txt[/file]';
1081
        $expected = [
1082
            'div' => [
1083
                'class' => 'richtext-imessage',
1084
            ],
1085
        ];
1086
        $result = $this->_Parser->parse($input);
1087
        $this->assertHtml($expected, $result);
1088
    }
1089
1090
    public function testUploadTypeFileNoSource()
1091
    {
1092
        $input = '[file]test.txt[/file]';
1093
        $result = $this->_Parser->parse($input);
1094
        $this->assertHtml($input, $result);
0 ignored issues
show
Bug introduced by
$input of type string is incompatible with the type array expected by parameter $expected of Cake\TestSuite\TestCase::assertHtml(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1094
        $this->assertHtml(/** @scrutinizer ignore-type */ $input, $result);
Loading history...
1095
    }
1096
1097
    public function testSmiliesNoSmiliesInCodeTag()
1098
    {
1099
        $input = '[code text]:)[/code]';
1100
        $needle = '<img';
1101
        $result = $this->_Parser->parse($input, ['cache' => false]);
1102
        $this->assertNotContains($needle, $result);
1103
    }
1104
1105
    public function testCodeNestedTags()
1106
    {
1107
        $input = '[code][b]text[b][/code]';
1108
        $expected = [
1109
            [
1110
                'div' => ['class' => 'geshi-wrapper'],
1111
            ],
1112
            'preg:/.*?\[b\]text\[b\].*/',
1113
        ];
1114
        $result = $this->_Parser->parse($input);
1115
        $this->assertHtml($expected, $result);
1116
    }
1117
1118
    public function testCodeWhitespace()
1119
    {
1120
        $input = "[code]\ntest\n[/code]";
1121
        $expected = "/>test</";
1122
        $result = $this->_Parser->parse($input);
1123
        $this->assertRegExp($expected, $result);
1124
    }
1125
1126
    public function testCodeSimple()
1127
    {
1128
        $input = '[code]text[/code]';
1129
        $result = $this->_Parser->parse($input);
1130
        $expected = 'lang="text"';
1131
        $this->assertContains($expected, $result);
1132
    }
1133
1134
    public function testCodeLangAttribute()
1135
    {
1136
        $input = '[code=php]text[/code]';
1137
        $result = $this->_Parser->parse($input);
1138
        $expected = 'lang="php"';
1139
        $this->assertContains($expected, $result);
1140
    }
1141
1142
    /**
1143
     * tests that citation marks are not replaced in code-blocks
1144
     */
1145
    public function testCodeNoCitationMark()
1146
    {
1147
        // [code]<citation mark>[/code] should not be cited
1148
        $input = h(
1149
            "[code]\n" . $this->_Helper->getConfig('quote_symbol') . "\n[/code]"
1150
        );
1151
        $expected = '`span class=.*?richtext-citation`';
1152
        $result = $this->_Parser->parse($input);
1153
        $this->assertNotRegExp($expected, $result);
1154
    }
1155
1156
    public function testCodeDetaginize()
1157
    {
1158
        $input = '[code bash]pre http://example.com post[/code]';
1159
        $result = $this->_Parser->parse($input);
1160
        $this->assertNotContains('autoLink', $result);
1161
    }
1162
1163
    public function testQuote()
1164
    {
1165
        $_qs = $this->MarkupSettings->get('quote_symbol');
1166
        $input = $_qs . ' fo [b]test[/b] ba';
1167
        $result = $this->_Parser->parse($input);
1168
        $expected = [
1169
            'span' => ['class' => 'richtext-citation'],
1170
            $_qs . ' fo ',
1171
            'strong' => [],
1172
            'test',
1173
            '/strong',
1174
            ' ba',
1175
            '/span',
1176
        ];
1177
        $this->assertHtml($expected, $result);
1178
    }
1179
1180
    public function testHtml5Video()
1181
    {
1182
        //* setup
1183
        $bbcodeImg = Configure::read('Saito.Settings.bbcode_img');
1184
        Configure::write('Saito.Settings.bbcode_img', true);
1185
1186
        //* @td write video tests
1187
        $url = 'http://example.com/audio.mp4';
1188
        $input = "[video]{$url}[/video]";
1189
        $result = $this->_Parser->parse($input);
1190
        $expected = [
1191
            'video' => [
1192
                'src' => $url,
1193
                'preload' => 'auto',
1194
                'controls' => 'controls',
1195
                'x-webkit-airplay' => 'allow',
1196
            ],
1197
        ];
1198
        $this->assertHtml($expected, $result);
1199
1200
        //* teardown
1201
        Configure::write('Saito.Settings.bbcode_img', $bbcodeImg);
1202
    }
1203
1204
    public function testHr()
1205
    {
1206
        $input = '[hr][hr]';
1207
        $expected = '<hr><hr>';
1208
        $result = $this->_Parser->parse($input);
1209
        $this->assertEquals($result, $expected);
1210
    }
1211
1212
    public function testHrShort()
1213
    {
1214
        $input = '[---][---]';
1215
        $expected = '<hr><hr>';
1216
        $result = $this->_Parser->parse($input);
1217
        $this->assertEquals($result, $expected);
1218
    }
1219
1220
    public function testEmbedNoReplacement()
1221
    {
1222
        $input = '[embed]http://no.provider/unreplaced[/embed]';
1223
1224
        $result = $this->_Parser->parse($input);
1225
1226
        $expected = [
1227
            'div' => [
1228
                'class' => 'js-embed',
1229
                'data-embed' => '{&quot;url&quot;:&quot;http:\/\/no.provider\/unreplaced&quot;}',
1230
                'id' => 'embed-10478631dd9f8f00da95953f63f6e5f3',
1231
            ],
1232
            '/div',
1233
        ];
1234
1235
        $this->assertHtml($expected, $result);
1236
    }
1237
1238
    public function testEmbedDisabledWithoutAutolinking()
1239
    {
1240
        $this->MarkupSettings->setSingle('autolink', false);
1241
        $this->MarkupSettings->setSingle('content_embed_active', false);
1242
1243
        $url = 'http://foo.bar/baz';
1244
        $input = "[embed]{$url}[/embed]";
1245
1246
        $result = $this->_Parser->parse($input);
1247
1248
        $this->assertHtml($url, $result);
0 ignored issues
show
Bug introduced by
$url of type string is incompatible with the type array expected by parameter $expected of Cake\TestSuite\TestCase::assertHtml(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1248
        $this->assertHtml(/** @scrutinizer ignore-type */ $url, $result);
Loading history...
1249
    }
1250
1251
    public function testEmbedDisabledWithAutolinking()
1252
    {
1253
        $this->MarkupSettings->setSingle('autolink', true);
1254
        $this->MarkupSettings->setSingle('content_embed_active', false);
1255
1256
        $url = 'http://foo.bar/baz';
1257
        $input = "[embed]{$url}[/embed]";
1258
1259
        $result = $this->_Parser->parse($input);
1260
1261
        $expected = [
1262
            'a' => [
1263
                'href' => $url,
1264
                'target' => '_blank',
1265
            ],
1266
            $url,
1267
            '/a',
1268
        ];
1269
1270
        $this->assertHtml($expected, $result);
1271
    }
1272
1273
    public function testHtml5Audio()
1274
    {
1275
        //* setup
1276
        $bbcodeImg = Configure::read('Saito.Settings.bbcode_img');
1277
        Configure::write('Saito.Settings.bbcode_img', true);
1278
1279
        //* simple test
1280
        $url = 'http://example.com/audio3.m4a';
1281
        $input = "[audio]{$url}[/audio]";
1282
        $result = $this->_Parser->parse($input);
1283
        $expected = [
1284
            'audio' => [
1285
                'src' => $url,
1286
                'controls' => 'controls',
1287
                'preload' => 'auto',
1288
                'x-webkit-airplay' => 'allow',
1289
            ],
1290
            '/audio',
1291
        ];
1292
        $this->assertHtml($expected, $result);
1293
1294
        //* teardown
1295
        Configure::write('Saito.Settings.bbcode_img', $bbcodeImg);
1296
    }
1297
1298
    /* ******************** Setup ********************** */
1299
1300
    public function setUp()
1301
    {
1302
        Cache::clear();
1303
1304
        if (Cache::getConfig('bbcodeParserEmbed') === null) {
1305
            Cache::setConfig(
1306
                'bbcodeParserEmbed',
1307
                [
1308
                    'className' => 'File',
1309
                    'prefix' => 'saito_embed-',
1310
                    'path' => CACHE,
1311
                    'groups' => ['embed'],
1312
                    'duration' => '+1 year',
1313
1314
                ]
1315
            );
1316
        }
1317
1318
        if (isset($_SERVER['SERVER_NAME'])) {
1319
            $this->server_name = $_SERVER['SERVER_NAME'];
1320
        } else {
1321
            $this->server_name = false;
1322
        }
1323
1324
        if (isset($_SERVER['SERVER_PORT'])) {
1325
            $this->server_port = $_SERVER['SERVER_PORT'];
1326
        } else {
1327
            $this->server_port = false;
1328
        }
1329
1330
        $this->autolink = Configure::read('Saito.Settings.autolink');
1331
        Configure::write('Saito.Settings.autolink', true);
1332
1333
        $_SERVER['SERVER_NAME'] = 'macnemo.de';
1334
        $_SERVER['SERVER_PORT'] = '80';
1335
1336
        parent::setUp();
1337
1338
        $View = new View();
1339
1340
        //= smiley fixture
1341
        $smiliesFixture = [
1342
            [
1343
                'order' => 1,
1344
                'icon' => 'wink.png',
1345
                'image' => 'wink.png',
1346
                'title' => 'Wink',
1347
                'code' => ';)',
1348
                'type' => 'image',
1349
            ],
1350
            [
1351
                'order' => 2,
1352
                'icon' => 'smile_icon.svg',
1353
                'image' => 'smile_image.svg',
1354
                'title' => 'Smile',
1355
                'code' => ':-)',
1356
                'type' => 'image',
1357
            ],
1358
            [
1359
                'order' => 3,
1360
                'icon' => 'coffee',
1361
                'image' => 'coffee',
1362
                'title' => 'Coffee',
1363
                'code' => '[_]P',
1364
                'type' => 'font',
1365
            ],
1366
        ];
1367
        Cache::write('Saito.Smilies.data', $smiliesFixture);
1368
        $SmileyLoader = new \Saito\Smiley\SmileyLoader();
1369
1370
        //= userlist fixture
1371
        $Userlist = $this->getMockBuilder(UserlistModel::class)
1372
            ->disableOriginalConstructor()
1373
            ->setMethods(['get'])
1374
            ->getMock();
1375
        $Userlist->method('get')->willReturn(['Alice', 'Bobby Junior', 'Dr. No']);
1376
1377
        //= ParserHelper
1378
        $markupSettingsMock = new class extends MarkupSettings {
1379
            public function setSingle(string $key, $value)
1380
            {
1381
                $this->_settings[$key] = $value;
1382
            }
1383
        };
1384
        $this->MarkupSettings = new $markupSettingsMock([
1385
            'UserList' => $Userlist,
1386
            'atBaseUrl' => '/at/',
1387
            'autolink' => true,
1388
            'bbcode_img' => true,
1389
            'content_embed_active' => true,
1390
            'content_embed_media' => true,
1391
            'content_embed_text' => true,
1392
            'hashBaseUrl' => '/hash/',
1393
            'quote_symbol' => '»',
1394
            'smilies' => true,
1395
            'smiliesData' => $SmileyLoader,
1396
            'video_domains_allowed' => 'youtube',
1397
            'webroot' => '',
1398
        ]);
1399
        $this->_Helper = $ParserHelper = new ParserHelper($View);
0 ignored issues
show
Bug Best Practice introduced by
The property _Helper does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1400
        $ParserHelper->beforeRender(null);
1401
1402
        //= Smiley Renderer
1403
        $this->_Helper->getView()->set('smiliesData', $SmileyLoader);
1404
1405
        //= Parser
1406
        $this->_Parser = new Parser($ParserHelper, $this->MarkupSettings);
1407
    }
1408
1409
    public function tearDown()
1410
    {
1411
        parent::tearDown();
1412
        if ($this->server_name) {
0 ignored issues
show
Bug Best Practice introduced by
The property server_name does not exist on BbcodeParser\Test\Lib\BbcodeParserTest. Did you maybe forget to declare it?
Loading history...
1413
            $_SERVER['SERVER_NAME'] = $this->server_name;
1414
        }
1415
1416
        if ($this->server_name) {
1417
            $_SERVER['SERVER_PORT'] = $this->server_port;
0 ignored issues
show
Bug Best Practice introduced by
The property server_port does not exist on BbcodeParser\Test\Lib\BbcodeParserTest. Did you maybe forget to declare it?
Loading history...
1418
        }
1419
1420
        Configure::write('Saito.Settings.autolink', $this->autolink);
0 ignored issues
show
Bug Best Practice introduced by
The property autolink does not exist on BbcodeParser\Test\Lib\BbcodeParserTest. Did you maybe forget to declare it?
Loading history...
1421
1422
        Cache::clear();
1423
        unset($this->_Parser);
1424
    }
1425
}
1426