Passed
Push — develop ( d656be...83fcd2 )
by Schlaefer
03:24
created

BbcodeParserTest::testShortenLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 15
rs 9.9332
c 0
b 0
f 0
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
            ['script' => true],
88
            'preg:/(.*?)"string":" te &quot;&#039; xt"(.*?)(?=<)/',
89
            '/script',
90
            [
91
                'a' => [
92
                    'href' => '#',
93
                    'class' => 'richtext-spoiler-link',
94
                    'onclick'
95
                ]
96
            ],
97
            'preg:/.*▇ Spoiler ▇.*?(?=<)/',
98
            '/a',
99
            '/div'
100
        ];
101
        $result = $this->_Parser->parse($input);
102
        $this->assertHtml($expected, $result);
103
    }
104
105
    public function testList()
106
    {
107
        $input = "[list]\n[*]fooo\n[*]bar\n[/list]";
108
        $expected = [
109
            ['ul' => []],
110
            ['li' => []],
111
            'fooo',
112
            ['br' => []],
113
            '/li',
114
            ['li' => []],
115
            'bar',
116
            ['br' => []],
117
            '/li',
118
            '/ul'
119
        ];
120
        $result = $this->_Parser->parse($input);
121
        $this->assertHtml($expected, $result);
122
    }
123
124
    public function testMaskLinkWithoutProtocol()
125
    {
126
        $input = '[url=thetempe.st/station]purge[/url]';
127
        $expected = [
128
            'a' => [
129
                'href' => 'http://thetempe.st/station',
130
                'class' => 'richtext-link',
131
                'rel' => 'external',
132
                'target' => '_blank'
133
            ],
134
            'purge',
135
            '/a'
136
        ];
137
        $result = $this->_Parser->parse($input);
138
        $this->assertHtml($expected, $result);
139
    }
140
141
    public function testParserEngineCaching()
142
    {
143
        $input = '[img=]foo.png[/img]';
144
        $result = $this->_Parser->parse($input, ['multimedia' => true]);
145
        $this->assertContains('<img src', $result);
146
        $result = $this->_Parser->parse($input, ['multimedia' => false]);
147
        $this->assertNotContains('<img src', $result);
148
    }
149
150
    public function testLink()
151
    {
152
        $input = '[url=http://cgi.ebay.de/ws/eBayISAPI.dll?ViewItem&item=250678480561&ssPageName=ADME:X:RTQ:DE:1123]test[/url]';
153
        $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...
154
        $expected = [
155
            'a' => [
156
                'href' => 'http://cgi.ebay.de/ws/eBayISAPI.dll?ViewItem&amp;item=250678480561&amp;ssPageName=ADME:X:RTQ:DE:1123',
157
                'class' => 'richtext-link',
158
                'rel' => 'external',
159
                'target' => '_blank'
160
            ],
161
            'test',
162
            '/a',
163
            'span' => [
164
                'class' => 'richtext-linkInfo'
165
            ],
166
            '[ebay.de]',
167
            '/span',
168
        ];
169
        $result = $this->_Parser->parse($input);
170
        $this->assertHtml($expected, $result);
171
172
        /*
173
         * external server
174
         */
175
        $input = '[url]http://heise.de/foobar[/url]';
176
        $expected = [
177
            'a' => [
178
                'href' => 'http://heise.de/foobar',
179
                'class' => 'richtext-link truncate',
180
                'rel' => 'external',
181
                'target' => '_blank'
182
            ],
183
            'http://heise.de/foobar',
184
            '/a'
185
        ];
186
        $result = $this->_Parser->parse($input);
187
        $this->assertHtml($expected, $result);
188
189
        $input = '[link]http://heise.de/foobar[/link]';
190
        $expected = [
191
            'a' => [
192
                'href' => 'http://heise.de/foobar',
193
                'class' => 'richtext-link truncate',
194
                'rel' => 'external',
195
                'target' => '_blank'
196
            ],
197
            'http://heise.de/foobar',
198
            '/a'
199
        ];
200
        $result = $this->_Parser->parse($input);
201
        $this->assertHtml($expected, $result);
202
203
        // masked link
204
        $input = '[url=http://heise.de/foobar]foobar[/url]';
205
        $expected = [
206
            'a' => [
207
                'href' => 'http://heise.de/foobar',
208
                'class' => 'richtext-link',
209
                'rel' => 'external',
210
                'target' => '_blank'
211
            ],
212
            'foobar',
213
            '/a',
214
            'span' => ['class' => 'richtext-linkInfo'],
215
            '[heise.de]',
216
            '/span'
217
        ];
218
        $result = $this->_Parser->parse($input);
219
        $this->assertHtml($expected, $result);
220
221
        // masked link with no label
222
        $input = '[url=http://heise.de/foobar  label=none ]foobar[/url]';
223
        $expected = [
224
            'a' => [
225
                'href' => 'http://heise.de/foobar',
226
                'class' => 'richtext-link',
227
                'rel' => 'external',
228
                'target' => '_blank',
229
            ],
230
            'foobar',
231
            '/a',
232
        ];
233
        $result = $this->_Parser->parse($input);
234
        $this->assertHtml($expected, $result);
235
236
        /*
237
         * local server
238
         */
239
        $input = '[url=http://macnemo.de/foobar]foobar[/url]';
240
        $expected = [
241
            'a' => [
242
                'href' => 'http://macnemo.de/foobar',
243
                'class' => 'richtext-link',
244
            ],
245
            'foobar',
246
            '/a',
247
        ];
248
        $result = $this->_Parser->parse($input);
249
        $this->assertHtml($expected, $result);
250
251
        $input = '[url]/foobar[/url]';
252
        $expected = [
253
            'a' => [
254
                'href' => '/foobar',
255
                'class' => 'richtext-link truncate',
256
            ],
257
            'preg:/\/foobar/',
258
            '/a',
259
        ];
260
        $result = $this->_Parser->parse($input);
261
        $this->assertHtml($expected, $result);
262
263
        // test lokaler server with absolute url
264
        $input = '[url=/foobar]foobar[/url]';
265
        $expected = [
266
            'a' => [
267
                'href' => '/foobar',
268
                'class' => 'richtext-link',
269
            ],
270
            'foobar',
271
            '/a',
272
        ];
273
        $result = $this->_Parser->parse($input);
274
        $this->assertHtml($expected, $result);
275
276
        // test 'http://' only
277
        $input = '[url=http://]foobar[/url]';
278
        $expected = [
279
            'a' => [
280
                'href' => 'http://',
281
                'class' => 'richtext-link',
282
            ],
283
            'foobar',
284
            '/a',
285
        ];
286
        $result = $this->_Parser->parse($input);
287
        $this->assertHtml($expected, $result);
288
289
        // test for co.uk
290
        $input = '[url=http://heise.co.uk/foobar]foobar[/url]';
291
        $expected = [
292
            'a' => [
293
                'href' => 'http://heise.co.uk/foobar',
294
                'class' => 'richtext-link',
295
                'rel' => 'external',
296
                'target' => '_blank'
297
            ],
298
            'foobar',
299
            '/a',
300
            'span' => ['class' => 'richtext-linkInfo'],
301
            '[heise.co.uk]',
302
            '/span'
303
        ];
304
        $result = $this->_Parser->parse($input);
305
        $this->assertHtml($expected, $result);
306
    }
307
308
    public function testHashLinkSuccess()
309
    {
310
        // inline content ([i])
311
        $input = "[i]#2234[/i]";
312
        $expected = [
313
            'em' => [],
314
            'a' => [
315
                'class' => 'richtext-link',
316
                'href' => '/hash/2234'
317
            ],
318
            '#2234',
319
            '/a',
320
            '/em'
321
        ];
322
        $result = $this->_Parser->parse($input);
323
        $this->assertHtml($expected, $result);
324
325
        // lists
326
        $input = "[list][*]#2234[/list]";
327
        $expected = [
328
            'ul' => true,
329
            'li' => true,
330
            'a' => [
331
                'class' => 'richtext-link',
332
                'href' => '/hash/2234'
333
            ],
334
            '#2234',
335
            '/a',
336
            '/li',
337
            '/ul'
338
        ];
339
        $result = $this->_Parser->parse($input);
340
        $this->assertHtml($expected, $result);
341
342
        /// in paranthesis
343
        $input = "foo (#2234) bar";
344
        $expected = [
345
            'foo (',
346
            'a' => [
347
                'class' => 'richtext-link',
348
                'href' => '/hash/2234'
349
            ],
350
            '#2234',
351
            '/a',
352
            ') bar'
353
        ];
354
        $result = $this->_Parser->parse($input);
355
        $this->assertHtml($expected, $result);
356
    }
357
358
    public function testHashLinkFailure()
359
    {
360
        // don't hash code
361
        $input = '[code]#2234[/code]';
362
        $result = $this->_Parser->parse($input);
363
        $this->assertNotContains('>#2234</a>', $result);
364
365
        // not a valid hash
366
        $input = '#2234t';
367
        $result = $this->_Parser->parse($input);
368
        $this->assertEquals('#2234t', $result);
369
    }
370
371
    public function testAtLinkKnownUsers()
372
    {
373
        $input = '@Alice @Bob @Bobby Junior @Bobby Tables @Dr. No';
374
        $expected =
375
            "<a href='/at/Alice' class=\"richtext-link\">@Alice</a>" .
376
            " @Bob " .
377
            "<a href='/at/Bobby+Junior' class=\"richtext-link\">@Bobby Junior</a>" .
378
            " @Bobby Tables " .
379
            "<a href='/at/Dr.+No' class=\"richtext-link\">@Dr. No</a>";
380
381
        $result = $this->_Parser->parse($input);
382
        $this->assertEquals(
383
            $expected,
384
            $result,
385
            '@User string is not replaced with link to user profile.'
386
        );
387
388
        $input = '[code]@Alice[/code]';
389
        $result = $this->_Parser->parse($input);
390
        $this->assertNotContains('>@Alice</a>', $result);
391
    }
392
393
    public function testAtLinkKnownUsersLinebreak()
394
    {
395
        $input = "@Alice\nfoo";
396
        $result = $this->_Parser->parse($input);
397
        $expected = [
398
            'a' => [
399
                'class' => 'richtext-link',
400
                'href' => '/at/Alice'
401
            ],
402
            '@Alice',
403
            '/a',
404
            'br' => true
405
        ];
406
        $this->assertHtml($expected, $result);
407
    }
408
409
    public function testLinkEmptyUrl()
410
    {
411
        $input = '[url=][/url]';
412
        $expected = "<a href='' class=\"richtext-link\"></a>";
413
        $result = $this->_Parser->parse($input);
414
        $this->assertEquals($expected, $result);
415
    }
416
417
    public function testEditMarker()
418
    {
419
        $input = 'pre [e] post';
420
        $expected = [
421
            'pre ',
422
            'span' => [
423
                'class' => 'richtext-editMark'
424
            ],
425
            '/span',
426
            ' post'
427
        ];
428
        $result = $this->_Parser->parse($input);
429
        $this->assertHtml($expected, $result);
430
    }
431
432
    /*
433
     * without obfuscator
434
     *
435
    public function testEmail() {
436
        /*
437
            // mailto:
438
            $input = '[email]mailto:[email protected][/email]';
439
            $expected = "<a href='mailto:[email protected]'>mailto:[email protected]</a>";
440
            $result = $this->Bbcode->parse($input);
441
            $this->assertEquals($expected, $result);
442
443
            // mailto: mask
444
            $input = '[email=mailto:[email protected]]Mail[/email]';
445
            $expected = "<a href='mailto:[email protected]'>Mail</a>";
446
            $result = $this->Bbcode->parse($input);
447
            $this->assertEquals($expected, $result);
448
449
            // no mailto:
450
            $input = '[email][email protected][/email]';
451
            $expected = "<a href='mailto:[email protected]'>[email protected]</a>";
452
            $result = $this->Bbcode->parse($input);
453
            $this->assertEquals($expected, $result);
454
455
            // no mailto: mask
456
            $input = '[[email protected]]Mail[/email]';
457
            $expected = "<a href='mailto:[email protected]'>Mail</a>";
458
            $result = $this->Bbcode->parse($input);
459
            $this->assertEquals($expected, $result);
460
    }
461
            */
462
463
    public function testEmailMailto()
464
    {
465
        $MO = $this->getMockBuilder('MailObfuscator')
466
            ->setMethods(['link'])
467
            ->getMock();
468
        $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

468
        $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...
469
            ->method('link')
470
            ->with('[email protected]', null);
471
        $this->_Helper->MailObfuscator = $MO;
472
473
        $input = '[email]mailto:[email protected][/email]';
474
        $this->_Parser->parse($input);
475
    }
476
477
    public function testEmailMailtoMask()
478
    {
479
        $MO = $this->getMockBuilder('MailObfuscator')
480
            ->setMethods(['link'])
481
            ->getMock();
482
        $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

482
        $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...
483
            ->method('link')
484
            ->with('[email protected]', 'Mail');
485
        $this->_Helper->MailObfuscator = $MO;
486
487
        $input = '[email=mailto:[email protected]]Mail[/email]';
488
        $this->_Parser->parse($input);
489
    }
490
491
    public function testEmailNoMailto()
492
    {
493
        $MO = $this->getMockBuilder('MailObfuscator')
494
            ->setMethods(['link'])
495
            ->getMock();
496
        $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

496
        $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...
497
            ->method('link')
498
            ->with('[email protected]', null);
499
        $this->_Helper->MailObfuscator = $MO;
500
501
        $input = '[email][email protected][/email]';
502
        $this->_Parser->parse($input);
503
    }
504
505
    public function testEmailNoMailtoMask()
506
    {
507
        $MO = $this->getMockBuilder('MailObfuscator')
508
            ->setMethods(['link'])
509
            ->getMock();
510
        $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

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

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

1065
        $this->assertHtml(/** @scrutinizer ignore-type */ $input, $result);
Loading history...
1066
    }
1067
1068
    public function testSmiliesNoSmiliesInCodeTag()
1069
    {
1070
        $input = '[code text]:)[/code]';
1071
        $needle = '<img';
1072
        $result = $this->_Parser->parse($input, ['cache' => false]);
1073
        $this->assertNotContains($needle, $result);
1074
    }
1075
1076
    public function testCodeNestedTags()
1077
    {
1078
        $input = '[code][b]text[b][/code]';
1079
        $expected = [
1080
            [
1081
                'div' => ['class' => 'geshi-wrapper']
1082
            ],
1083
            'preg:/.*?\[b\]text\[b\].*/',
1084
        ];
1085
        $result = $this->_Parser->parse($input);
1086
        $this->assertHtml($expected, $result);
1087
    }
1088
1089
    public function testCodeWhitespace()
1090
    {
1091
        $input = "[code]\ntest\n[/code]";
1092
        $expected = "/>test</";
1093
        $result = $this->_Parser->parse($input);
1094
        $this->assertRegExp($expected, $result);
1095
    }
1096
1097
    public function testCodeSimple()
1098
    {
1099
        $input = '[code]text[/code]';
1100
        $result = $this->_Parser->parse($input);
1101
        $expected = 'lang="text"';
1102
        $this->assertContains($expected, $result);
1103
    }
1104
1105
    public function testCodeLangAttribute()
1106
    {
1107
        $input = '[code=php]text[/code]';
1108
        $result = $this->_Parser->parse($input);
1109
        $expected = 'lang="php"';
1110
        $this->assertContains($expected, $result);
1111
    }
1112
1113
    /**
1114
     * tests that citation marks are not replaced in code-blocks
1115
     */
1116
    public function testCodeNoCitationMark()
1117
    {
1118
        // [code]<citation mark>[/code] should not be cited
1119
        $input = h(
1120
            "[code]\n" . $this->_Helper->getConfig('quote_symbol') . "\n[/code]"
1121
        );
1122
        $expected = '`span class=.*?richtext-citation`';
1123
        $result = $this->_Parser->parse($input);
1124
        $this->assertNotRegExp($expected, $result);
1125
    }
1126
1127
    public function testCodeDetaginize()
1128
    {
1129
        $input = '[code bash]pre http://example.com post[/code]';
1130
        $result = $this->_Parser->parse($input);
1131
        $this->assertNotContains('autoLink', $result);
1132
    }
1133
1134
    public function testQuote()
1135
    {
1136
        $_qs = $this->MarkupSettings->get('quote_symbol');
1137
        $input = $_qs . ' fo [b]test[/b] ba';
1138
        $result = $this->_Parser->parse($input);
1139
        $expected = [
1140
            'span' => ['class' => 'richtext-citation'],
1141
            $_qs . ' fo ',
1142
            'strong' => [],
1143
            'test',
1144
            '/strong',
1145
            ' ba',
1146
            '/span'
1147
        ];
1148
        $this->assertHtml($expected, $result);
1149
    }
1150
1151
    public function testHtml5Video()
1152
    {
1153
        //* setup
1154
        $bbcodeImg = Configure::read('Saito.Settings.bbcode_img');
1155
        Configure::write('Saito.Settings.bbcode_img', true);
1156
1157
        //* @td write video tests
1158
        $url = 'http://example.com/audio.mp4';
1159
        $input = "[video]{$url}[/video]";
1160
        $result = $this->_Parser->parse($input);
1161
        $expected = [
1162
            'video' => [
1163
                'src' => $url,
1164
                'preload' => 'auto',
1165
                'controls' => 'controls',
1166
                'x-webkit-airplay' => 'allow'
1167
            ],
1168
        ];
1169
        $this->assertHtml($expected, $result);
1170
1171
        //* teardown
1172
        Configure::write('Saito.Settings.bbcode_img', $bbcodeImg);
1173
    }
1174
1175
    public function testHr()
1176
    {
1177
        $input = '[hr][hr]';
1178
        $expected = '<hr><hr>';
1179
        $result = $this->_Parser->parse($input);
1180
        $this->assertEquals($result, $expected);
1181
    }
1182
1183
    public function testHrShort()
1184
    {
1185
        $input = '[---][---]';
1186
        $expected = '<hr><hr>';
1187
        $result = $this->_Parser->parse($input);
1188
        $this->assertEquals($result, $expected);
1189
    }
1190
1191
    public function testEmbedNoReplacement()
1192
    {
1193
        $input = '[embed]http://no.provider/unreplaced[/embed]';
1194
1195
        $result = $this->_Parser->parse($input);
1196
1197
        $expected = [
1198
            'div' => [
1199
                'class' => 'js-embed',
1200
                'data-embed' => '{&quot;url&quot;:&quot;http:\/\/no.provider\/unreplaced&quot;}',
1201
                'id' => 'embed-10478631dd9f8f00da95953f63f6e5f3',
1202
            ],
1203
            '/div',
1204
        ];
1205
1206
        $this->assertHtml($expected, $result);
1207
    }
1208
1209
    public function testEmbedDisabledWithoutAutolinking()
1210
    {
1211
        $this->MarkupSettings->setSingle('autolink', false);
1212
        $this->MarkupSettings->setSingle('content_embed_active', false);
1213
1214
        $url = 'http://foo.bar/baz';
1215
        $input = "[embed]{$url}[/embed]";
1216
1217
        $result = $this->_Parser->parse($input);
1218
1219
        $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

1219
        $this->assertHtml(/** @scrutinizer ignore-type */ $url, $result);
Loading history...
1220
    }
1221
1222
    public function testEmbedDisabledWithAutolinking()
1223
    {
1224
        $this->MarkupSettings->setSingle('autolink', true);
1225
        $this->MarkupSettings->setSingle('content_embed_active', false);
1226
1227
        $url = 'http://foo.bar/baz';
1228
        $input = "[embed]{$url}[/embed]";
1229
1230
        $result = $this->_Parser->parse($input);
1231
1232
        $expected = [
1233
            'a' => [
1234
                'href' => $url,
1235
                'target' => '_blank',
1236
            ],
1237
            $url,
1238
            '/a',
1239
        ];
1240
1241
        $this->assertHtml($expected, $result);
1242
    }
1243
1244
    public function testHtml5Audio()
1245
    {
1246
        //* setup
1247
        $bbcodeImg = Configure::read('Saito.Settings.bbcode_img');
1248
        Configure::write('Saito.Settings.bbcode_img', true);
1249
1250
        //* simple test
1251
        $url = 'http://example.com/audio3.m4a';
1252
        $input = "[audio]{$url}[/audio]";
1253
        $result = $this->_Parser->parse($input);
1254
        $expected = [
1255
            'audio' => [
1256
                'src' => $url,
1257
                'controls' => 'controls',
1258
                'preload' => 'auto',
1259
                'x-webkit-airplay' => 'allow',
1260
            ],
1261
            '/audio',
1262
        ];
1263
        $this->assertHtml($expected, $result);
1264
1265
        //* teardown
1266
        Configure::write('Saito.Settings.bbcode_img', $bbcodeImg);
1267
    }
1268
1269
    /* ******************** Setup ********************** */
1270
1271
    public function setUp()
1272
    {
1273
        Cache::clear();
1274
1275
        if (Cache::getConfig('bbcodeParserEmbed') === null) {
1276
            Cache::setConfig(
1277
                'bbcodeParserEmbed',
1278
                [
1279
                    'className' => 'File',
1280
                    'prefix' => 'saito_embed-',
1281
                    'path' => CACHE,
1282
                    'groups' => ['embed'],
1283
                    'duration' => '+1 year'
1284
1285
                ]
1286
            );
1287
        }
1288
1289
        if (isset($_SERVER['SERVER_NAME'])) {
1290
            $this->server_name = $_SERVER['SERVER_NAME'];
1291
        } else {
1292
            $this->server_name = false;
1293
        }
1294
1295
        if (isset($_SERVER['SERVER_PORT'])) {
1296
            $this->server_port = $_SERVER['SERVER_PORT'];
1297
        } else {
1298
            $this->server_port = false;
1299
        }
1300
1301
        $this->autolink = Configure::read('Saito.Settings.autolink');
1302
        Configure::write('Saito.Settings.autolink', true);
1303
1304
        $_SERVER['SERVER_NAME'] = 'macnemo.de';
1305
        $_SERVER['SERVER_PORT'] = '80';
1306
1307
        parent::setUp();
1308
1309
        $View = new View();
1310
1311
        //= smiley fixture
1312
        $smiliesFixture = [
1313
            [
1314
                'order' => 1,
1315
                'icon' => 'wink.png',
1316
                'image' => 'wink.png',
1317
                'title' => 'Wink',
1318
                'code' => ';)',
1319
                'type' => 'image'
1320
            ],
1321
            [
1322
                'order' => 2,
1323
                'icon' => 'smile_icon.svg',
1324
                'image' => 'smile_image.svg',
1325
                'title' => 'Smile',
1326
                'code' => ':-)',
1327
                'type' => 'image'
1328
            ],
1329
            [
1330
                'order' => 3,
1331
                'icon' => 'coffee',
1332
                'image' => 'coffee',
1333
                'title' => 'Coffee',
1334
                'code' => '[_]P',
1335
                'type' => 'font'
1336
            ],
1337
        ];
1338
        Cache::write('Saito.Smilies.data', $smiliesFixture);
1339
        $SmileyLoader = new \Saito\Smiley\SmileyLoader();
1340
1341
        //= userlist fixture
1342
        $Userlist = $this->getMockBuilder(UserlistModel::class)
1343
            ->disableOriginalConstructor()
1344
            ->setMethods(['get'])
1345
            ->getMock();
1346
        $Userlist->method('get')->willReturn(['Alice', 'Bobby Junior', 'Dr. No']);
1347
1348
        //= ParserHelper
1349
        $markupSettingsMock = new class extends MarkupSettings {
1350
            public function setSingle(string $key, $value)
1351
            {
1352
                $this->_settings[$key] = $value;
1353
            }
1354
        };
1355
        $this->MarkupSettings = new $markupSettingsMock([
1356
            'UserList' => $Userlist,
1357
            'atBaseUrl' => '/at/',
1358
            'autolink' => true,
1359
            'bbcode_img' => true,
1360
            'content_embed_active' => true,
1361
            'content_embed_media' => true,
1362
            'content_embed_text' => true,
1363
            'hashBaseUrl' => '/hash/',
1364
            'quote_symbol' => '»',
1365
            'smilies' => true,
1366
            'smiliesData' => $SmileyLoader,
1367
            'video_domains_allowed' => 'youtube',
1368
            'webroot' => ''
1369
        ]);
1370
        $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...
1371
        $ParserHelper->beforeRender(null);
1372
1373
        //= Smiley Renderer
1374
        $this->_Helper->getView()->set('smiliesData', $SmileyLoader);
1375
1376
        //= Parser
1377
        $this->_Parser = new Parser($ParserHelper, $this->MarkupSettings);
1378
    }
1379
1380
    public function tearDown()
1381
    {
1382
        parent::tearDown();
1383
        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...
1384
            $_SERVER['SERVER_NAME'] = $this->server_name;
1385
        }
1386
1387
        if ($this->server_name) {
1388
            $_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...
1389
        }
1390
1391
        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...
1392
1393
        Cache::clear();
1394
        unset($this->_Parser);
1395
    }
1396
}
1397