diff options
Diffstat (limited to 'tests/plugins/PluginMarkdownTest.php')
-rw-r--r-- | tests/plugins/PluginMarkdownTest.php | 99 |
1 files changed, 90 insertions, 9 deletions
diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php index fa7e1d52..f1e1acf8 100644 --- a/tests/plugins/PluginMarkdownTest.php +++ b/tests/plugins/PluginMarkdownTest.php | |||
@@ -8,17 +8,23 @@ require_once 'application/Utils.php'; | |||
8 | require_once 'plugins/markdown/markdown.php'; | 8 | require_once 'plugins/markdown/markdown.php'; |
9 | 9 | ||
10 | /** | 10 | /** |
11 | * Class PlugQrcodeTest | 11 | * Class PluginMarkdownTest |
12 | * Unit test for the QR-Code plugin | 12 | * Unit test for the Markdown plugin |
13 | */ | 13 | */ |
14 | class PluginMarkdownTest extends PHPUnit_Framework_TestCase | 14 | class PluginMarkdownTest extends PHPUnit_Framework_TestCase |
15 | { | 15 | { |
16 | /** | 16 | /** |
17 | * @var ConfigManager instance. | ||
18 | */ | ||
19 | protected $conf; | ||
20 | |||
21 | /** | ||
17 | * Reset plugin path | 22 | * Reset plugin path |
18 | */ | 23 | */ |
19 | function setUp() | 24 | function setUp() |
20 | { | 25 | { |
21 | PluginManager::$PLUGINS_PATH = 'plugins'; | 26 | PluginManager::$PLUGINS_PATH = 'plugins'; |
27 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | ||
22 | } | 28 | } |
23 | 29 | ||
24 | /** | 30 | /** |
@@ -36,7 +42,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase | |||
36 | ), | 42 | ), |
37 | ); | 43 | ); |
38 | 44 | ||
39 | $data = hook_markdown_render_linklist($data); | 45 | $data = hook_markdown_render_linklist($data, $this->conf); |
40 | $this->assertNotFalse(strpos($data['links'][0]['description'], '<h1>')); | 46 | $this->assertNotFalse(strpos($data['links'][0]['description'], '<h1>')); |
41 | $this->assertNotFalse(strpos($data['links'][0]['description'], '<p>')); | 47 | $this->assertNotFalse(strpos($data['links'][0]['description'], '<p>')); |
42 | } | 48 | } |
@@ -61,7 +67,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase | |||
61 | ), | 67 | ), |
62 | ); | 68 | ); |
63 | 69 | ||
64 | $data = hook_markdown_render_daily($data); | 70 | $data = hook_markdown_render_daily($data, $this->conf); |
65 | $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<h1>')); | 71 | $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<h1>')); |
66 | $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<p>')); | 72 | $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<p>')); |
67 | } | 73 | } |
@@ -110,6 +116,8 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase | |||
110 | $output = escape($input); | 116 | $output = escape($input); |
111 | $input .= '<a href="#" onmouseHover="alert(\'xss\');" attr="tt">link</a>'; | 117 | $input .= '<a href="#" onmouseHover="alert(\'xss\');" attr="tt">link</a>'; |
112 | $output .= '<a href="#" attr="tt">link</a>'; | 118 | $output .= '<a href="#" attr="tt">link</a>'; |
119 | $input .= '<a href="#" onmouseHover=alert(\'xss\'); attr="tt">link</a>'; | ||
120 | $output .= '<a href="#" attr="tt">link</a>'; | ||
113 | $this->assertEquals($output, sanitize_html($input)); | 121 | $this->assertEquals($output, sanitize_html($input)); |
114 | // Do not touch escaped HTML. | 122 | // Do not touch escaped HTML. |
115 | $input = escape($input); | 123 | $input = escape($input); |
@@ -125,12 +133,16 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase | |||
125 | $data = array( | 133 | $data = array( |
126 | 'links' => array(array( | 134 | 'links' => array(array( |
127 | 'description' => $str, | 135 | 'description' => $str, |
128 | 'tags' => NO_MD_TAG | 136 | 'tags' => NO_MD_TAG, |
137 | 'taglist' => array(NO_MD_TAG), | ||
129 | )) | 138 | )) |
130 | ); | 139 | ); |
131 | 140 | ||
132 | $data = hook_markdown_render_linklist($data); | 141 | $processed = hook_markdown_render_linklist($data, $this->conf); |
133 | $this->assertEquals($str, $data['links'][0]['description']); | 142 | $this->assertEquals($str, $processed['links'][0]['description']); |
143 | |||
144 | $processed = hook_markdown_render_feed($data, $this->conf); | ||
145 | $this->assertEquals($str, $processed['links'][0]['description']); | ||
134 | 146 | ||
135 | $data = array( | 147 | $data = array( |
136 | // Columns data | 148 | // Columns data |
@@ -140,13 +152,82 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase | |||
140 | // nth link | 152 | // nth link |
141 | 0 => array( | 153 | 0 => array( |
142 | 'formatedDescription' => $str, | 154 | 'formatedDescription' => $str, |
143 | 'tags' => NO_MD_TAG | 155 | 'tags' => NO_MD_TAG, |
156 | 'taglist' => array(), | ||
144 | ), | 157 | ), |
145 | ), | 158 | ), |
146 | ), | 159 | ), |
147 | ); | 160 | ); |
148 | 161 | ||
149 | $data = hook_markdown_render_daily($data); | 162 | $data = hook_markdown_render_daily($data, $this->conf); |
150 | $this->assertEquals($str, $data['cols'][0][0]['formatedDescription']); | 163 | $this->assertEquals($str, $data['cols'][0][0]['formatedDescription']); |
151 | } | 164 | } |
165 | |||
166 | /** | ||
167 | * Test that a close value to nomarkdown is not understand as nomarkdown (previous value `.nomarkdown`). | ||
168 | */ | ||
169 | function testNoMarkdownNotExcactlyMatching() | ||
170 | { | ||
171 | $str = 'All _work_ and `no play` makes Jack a *dull* boy.'; | ||
172 | $data = array( | ||
173 | 'links' => array(array( | ||
174 | 'description' => $str, | ||
175 | 'tags' => '.' . NO_MD_TAG, | ||
176 | 'taglist' => array('.'. NO_MD_TAG), | ||
177 | )) | ||
178 | ); | ||
179 | |||
180 | $data = hook_markdown_render_feed($data, $this->conf); | ||
181 | $this->assertContains('<em>', $data['links'][0]['description']); | ||
182 | } | ||
183 | |||
184 | /** | ||
185 | * Test hashtag links processed with markdown. | ||
186 | */ | ||
187 | function testMarkdownHashtagLinks() | ||
188 | { | ||
189 | $md = file_get_contents('tests/plugins/resources/markdown.md'); | ||
190 | $md = format_description($md); | ||
191 | $html = file_get_contents('tests/plugins/resources/markdown.html'); | ||
192 | |||
193 | $data = process_markdown($md); | ||
194 | $this->assertEquals($html, $data); | ||
195 | } | ||
196 | |||
197 | /** | ||
198 | * Make sure that the HTML tags are escaped. | ||
199 | */ | ||
200 | public function testMarkdownWithHtmlEscape() | ||
201 | { | ||
202 | $md = '**strong** <strong>strong</strong>'; | ||
203 | $html = '<div class="markdown"><p><strong>strong</strong> <strong>strong</strong></p></div>'; | ||
204 | $data = array( | ||
205 | 'links' => array( | ||
206 | 0 => array( | ||
207 | 'description' => $md, | ||
208 | ), | ||
209 | ), | ||
210 | ); | ||
211 | $data = hook_markdown_render_linklist($data, $this->conf); | ||
212 | $this->assertEquals($html, $data['links'][0]['description']); | ||
213 | } | ||
214 | |||
215 | /** | ||
216 | * Make sure that the HTML tags aren't escaped with the setting set to false. | ||
217 | */ | ||
218 | public function testMarkdownWithHtmlNoEscape() | ||
219 | { | ||
220 | $this->conf->set('security.markdown_escape', false); | ||
221 | $md = '**strong** <strong>strong</strong>'; | ||
222 | $html = '<div class="markdown"><p><strong>strong</strong> <strong>strong</strong></p></div>'; | ||
223 | $data = array( | ||
224 | 'links' => array( | ||
225 | 0 => array( | ||
226 | 'description' => $md, | ||
227 | ), | ||
228 | ), | ||
229 | ); | ||
230 | $data = hook_markdown_render_linklist($data, $this->conf); | ||
231 | $this->assertEquals($html, $data['links'][0]['description']); | ||
232 | } | ||
152 | } | 233 | } |