aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/plugins/PluginMarkdownTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/plugins/PluginMarkdownTest.php')
-rw-r--r--tests/plugins/PluginMarkdownTest.php30
1 files changed, 18 insertions, 12 deletions
diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php
index f1e1acf8..96891f1f 100644
--- a/tests/plugins/PluginMarkdownTest.php
+++ b/tests/plugins/PluginMarkdownTest.php
@@ -1,4 +1,5 @@
1<?php 1<?php
2use Shaarli\Config\ConfigManager;
2 3
3/** 4/**
4 * PluginMarkdownTest.php 5 * PluginMarkdownTest.php
@@ -21,17 +22,18 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
21 /** 22 /**
22 * Reset plugin path 23 * Reset plugin path
23 */ 24 */
24 function setUp() 25 public function setUp()
25 { 26 {
26 PluginManager::$PLUGINS_PATH = 'plugins'; 27 PluginManager::$PLUGINS_PATH = 'plugins';
27 $this->conf = new ConfigManager('tests/utils/config/configJson'); 28 $this->conf = new ConfigManager('tests/utils/config/configJson');
29 $this->conf->set('security.allowed_protocols', ['ftp', 'magnet']);
28 } 30 }
29 31
30 /** 32 /**
31 * Test render_linklist hook. 33 * Test render_linklist hook.
32 * Only check that there is basic markdown rendering. 34 * Only check that there is basic markdown rendering.
33 */ 35 */
34 function testMarkdownLinklist() 36 public function testMarkdownLinklist()
35 { 37 {
36 $markdown = '# My title' . PHP_EOL . 'Very interesting content.'; 38 $markdown = '# My title' . PHP_EOL . 'Very interesting content.';
37 $data = array( 39 $data = array(
@@ -51,7 +53,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
51 * Test render_daily hook. 53 * Test render_daily hook.
52 * Only check that there is basic markdown rendering. 54 * Only check that there is basic markdown rendering.
53 */ 55 */
54 function testMarkdownDaily() 56 public function testMarkdownDaily()
55 { 57 {
56 $markdown = '# My title' . PHP_EOL . 'Very interesting content.'; 58 $markdown = '# My title' . PHP_EOL . 'Very interesting content.';
57 $data = array( 59 $data = array(
@@ -75,7 +77,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
75 /** 77 /**
76 * Test reverse_text2clickable(). 78 * Test reverse_text2clickable().
77 */ 79 */
78 function testReverseText2clickable() 80 public function testReverseText2clickable()
79 { 81 {
80 $text = 'stuff http://hello.there/is=someone#here otherstuff'; 82 $text = 'stuff http://hello.there/is=someone#here otherstuff';
81 $clickableText = text2clickable($text, ''); 83 $clickableText = text2clickable($text, '');
@@ -86,7 +88,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
86 /** 88 /**
87 * Test reverse_nl2br(). 89 * Test reverse_nl2br().
88 */ 90 */
89 function testReverseNl2br() 91 public function testReverseNl2br()
90 { 92 {
91 $text = 'stuff' . PHP_EOL . 'otherstuff'; 93 $text = 'stuff' . PHP_EOL . 'otherstuff';
92 $processedText = nl2br($text); 94 $processedText = nl2br($text);
@@ -97,7 +99,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
97 /** 99 /**
98 * Test reverse_space2nbsp(). 100 * Test reverse_space2nbsp().
99 */ 101 */
100 function testReverseSpace2nbsp() 102 public function testReverseSpace2nbsp()
101 { 103 {
102 $text = ' stuff' . PHP_EOL . ' otherstuff and another'; 104 $text = ' stuff' . PHP_EOL . ' otherstuff and another';
103 $processedText = space2nbsp($text); 105 $processedText = space2nbsp($text);
@@ -108,7 +110,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
108 /** 110 /**
109 * Test sanitize_html(). 111 * Test sanitize_html().
110 */ 112 */
111 function testSanitizeHtml() 113 public function testSanitizeHtml()
112 { 114 {
113 $input = '< script src="js.js"/>'; 115 $input = '< script src="js.js"/>';
114 $input .= '< script attr>alert(\'xss\');</script>'; 116 $input .= '< script attr>alert(\'xss\');</script>';
@@ -127,7 +129,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
127 /** 129 /**
128 * Test the no markdown tag. 130 * Test the no markdown tag.
129 */ 131 */
130 function testNoMarkdownTag() 132 public function testNoMarkdownTag()
131 { 133 {
132 $str = 'All _work_ and `no play` makes Jack a *dull* boy.'; 134 $str = 'All _work_ and `no play` makes Jack a *dull* boy.';
133 $data = array( 135 $data = array(
@@ -166,7 +168,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
166 /** 168 /**
167 * Test that a close value to nomarkdown is not understand as nomarkdown (previous value `.nomarkdown`). 169 * Test that a close value to nomarkdown is not understand as nomarkdown (previous value `.nomarkdown`).
168 */ 170 */
169 function testNoMarkdownNotExcactlyMatching() 171 public function testNoMarkdownNotExcactlyMatching()
170 { 172 {
171 $str = 'All _work_ and `no play` makes Jack a *dull* boy.'; 173 $str = 'All _work_ and `no play` makes Jack a *dull* boy.';
172 $data = array( 174 $data = array(
@@ -182,15 +184,19 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
182 } 184 }
183 185
184 /** 186 /**
185 * Test hashtag links processed with markdown. 187 * Make sure that the generated HTML match the reference HTML file.
186 */ 188 */
187 function testMarkdownHashtagLinks() 189 public function testMarkdownGlobalProcessDescription()
188 { 190 {
189 $md = file_get_contents('tests/plugins/resources/markdown.md'); 191 $md = file_get_contents('tests/plugins/resources/markdown.md');
190 $md = format_description($md); 192 $md = format_description($md);
191 $html = file_get_contents('tests/plugins/resources/markdown.html'); 193 $html = file_get_contents('tests/plugins/resources/markdown.html');
192 194
193 $data = process_markdown($md); 195 $data = process_markdown(
196 $md,
197 $this->conf->get('security.markdown_escape', true),
198 $this->conf->get('security.allowed_protocols')
199 );
194 $this->assertEquals($html, $data); 200 $this->assertEquals($html, $data);
195 } 201 }
196 202