This repository has been archived by the owner on Oct 20, 2023. It is now read-only.
/
BbcodeParserTest.php
96 lines (88 loc) · 2.13 KB
/
BbcodeParserTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* Copyright 2010-2012, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010-2012, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('BbcodeParser', 'MarkupParsers.Parser');
/**
* HtmlParser test case
*
* @package markup_parsers
* @subpackage markup_parsers.tests.cases.libs
*/
class BbcodeParserTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setup() {
$this->Parser = new BbcodeParser();
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
ClassRegistry::flush();
unset($this->Parser);
}
/**
* testParse
*
* @return void
* @access public
*/
public function testParse() {
$testText = <<<TEXT
[h1]Test[/h1]
This [b]is[/b] some [i]nice[/i] Text.
With an URL to [url url=http://www.cakedc.com]cakedc.com[/url].
[s]Strike through text[/s]
TEXT;
$expected = <<<HTML
<h1>Test</h1>
This <strong>is</strong> some <span style="font-style:italic;">nice</span> Text.<br />
With an URL to <a href="http://www.cakedc.com">cakedc.com</a>.<br />
<del>Strike through text</del>
HTML;
$result = $this->Parser->parse($testText);
$this->assertTextEquals($expected, $result);
}
/**
* test Parse BBCode with a not closed tag
*
* @return void
* @access public
*/
public function testParseNotClosedTags() {
$testText = <<<TEXT
[h1]Test[/h1]
This is an [i]incorrect[/i BBCode markup.
TEXT;
$expected = <<<HTML
<h1>Test</h1>
This is an [i]incorrect[/i BBCode markup.
HTML;
$result = $this->Parser->parse($testText);
$this->assertTextEquals($expected, $result);
$testText = <<<TEXT
[h1]Test[/h1]
A first [i]italic text[/i]
This is an [i]incorrect[/i BBCode [i]markup[/i].
TEXT;
$expected = <<<HTML
<h1>Test</h1>
A first <span style="font-style:italic;">italic text</span>
This is an <span style="font-style:italic;">incorrect[/i BBCode [i]markup</span>.
HTML;
$result = $this->Parser->parse($testText);
$this->assertTextEquals($expected, $result);
}
}