diff options
author | ArthurHoaro <arthur@hoa.ro> | 2019-07-27 12:34:30 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2019-07-27 12:34:30 +0200 |
commit | 38672ba0d1c722e5d6d33a58255ceb55e9410e46 (patch) | |
tree | dae4c7c47532380eac3ae641db99122fc77c93dc /tests/plugins/PluginMarkdownTest.php | |
parent | 83faedadff76c5bdca036f39f13943f63b27e164 (diff) | |
parent | 1e77e0448bbd25675d8c0fe4a73206ad9048904b (diff) | |
download | Shaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.tar.gz Shaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.tar.zst Shaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.zip |
Merge tag 'v0.10.4' into stable
Release v0.10.4
Diffstat (limited to 'tests/plugins/PluginMarkdownTest.php')
-rw-r--r-- | tests/plugins/PluginMarkdownTest.php | 99 |
1 files changed, 81 insertions, 18 deletions
diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php index 96891f1f..44364b05 100644 --- a/tests/plugins/PluginMarkdownTest.php +++ b/tests/plugins/PluginMarkdownTest.php | |||
@@ -47,6 +47,32 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase | |||
47 | $data = hook_markdown_render_linklist($data, $this->conf); | 47 | $data = hook_markdown_render_linklist($data, $this->conf); |
48 | $this->assertNotFalse(strpos($data['links'][0]['description'], '<h1>')); | 48 | $this->assertNotFalse(strpos($data['links'][0]['description'], '<h1>')); |
49 | $this->assertNotFalse(strpos($data['links'][0]['description'], '<p>')); | 49 | $this->assertNotFalse(strpos($data['links'][0]['description'], '<p>')); |
50 | |||
51 | $this->assertEquals($markdown, $data['links'][0]['description_src']); | ||
52 | } | ||
53 | |||
54 | /** | ||
55 | * Test render_feed hook. | ||
56 | */ | ||
57 | public function testMarkdownFeed() | ||
58 | { | ||
59 | $markdown = '# My title' . PHP_EOL . 'Very interesting content.'; | ||
60 | $markdown .= '— <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>'; | ||
61 | $data = array( | ||
62 | 'links' => array( | ||
63 | 0 => array( | ||
64 | 'description' => $markdown, | ||
65 | ), | ||
66 | ), | ||
67 | ); | ||
68 | |||
69 | $data = hook_markdown_render_feed($data, $this->conf); | ||
70 | $this->assertNotFalse(strpos($data['links'][0]['description'], '<h1>')); | ||
71 | $this->assertNotFalse(strpos($data['links'][0]['description'], '<p>')); | ||
72 | $this->assertStringEndsWith( | ||
73 | '— <a href="http://domain.tld/?0oc_VQ">Permalien</a></p></div>', | ||
74 | $data['links'][0]['description'] | ||
75 | ); | ||
50 | } | 76 | } |
51 | 77 | ||
52 | /** | 78 | /** |
@@ -58,20 +84,17 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase | |||
58 | $markdown = '# My title' . PHP_EOL . 'Very interesting content.'; | 84 | $markdown = '# My title' . PHP_EOL . 'Very interesting content.'; |
59 | $data = array( | 85 | $data = array( |
60 | // Columns data | 86 | // Columns data |
61 | 'cols' => array( | 87 | 'linksToDisplay' => array( |
62 | // First, second, third. | 88 | // nth link |
63 | 0 => array( | 89 | 0 => array( |
64 | // nth link | 90 | 'formatedDescription' => $markdown, |
65 | 0 => array( | ||
66 | 'formatedDescription' => $markdown, | ||
67 | ), | ||
68 | ), | 91 | ), |
69 | ), | 92 | ), |
70 | ); | 93 | ); |
71 | 94 | ||
72 | $data = hook_markdown_render_daily($data, $this->conf); | 95 | $data = hook_markdown_render_daily($data, $this->conf); |
73 | $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<h1>')); | 96 | $this->assertNotFalse(strpos($data['linksToDisplay'][0]['formatedDescription'], '<h1>')); |
74 | $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<p>')); | 97 | $this->assertNotFalse(strpos($data['linksToDisplay'][0]['formatedDescription'], '<p>')); |
75 | } | 98 | } |
76 | 99 | ||
77 | /** | 100 | /** |
@@ -86,6 +109,18 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase | |||
86 | } | 109 | } |
87 | 110 | ||
88 | /** | 111 | /** |
112 | * Test reverse_text2clickable(). | ||
113 | */ | ||
114 | public function testReverseText2clickableHashtags() | ||
115 | { | ||
116 | $text = file_get_contents('tests/plugins/resources/hashtags.raw'); | ||
117 | $md = file_get_contents('tests/plugins/resources/hashtags.md'); | ||
118 | $clickableText = hashtag_autolink($text); | ||
119 | $reversedText = reverse_text2clickable($clickableText); | ||
120 | $this->assertEquals($md, $reversedText); | ||
121 | } | ||
122 | |||
123 | /** | ||
89 | * Test reverse_nl2br(). | 124 | * Test reverse_nl2br(). |
90 | */ | 125 | */ |
91 | public function testReverseNl2br() | 126 | public function testReverseNl2br() |
@@ -107,6 +142,37 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase | |||
107 | $this->assertEquals($text, $reversedText); | 142 | $this->assertEquals($text, $reversedText); |
108 | } | 143 | } |
109 | 144 | ||
145 | public function testReverseFeedPermalink() | ||
146 | { | ||
147 | $text = 'Description... '; | ||
148 | $text .= '— <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>'; | ||
149 | $expected = 'Description... — [Permalien](http://domain.tld/?0oc_VQ)'; | ||
150 | $processedText = reverse_feed_permalink($text); | ||
151 | |||
152 | $this->assertEquals($expected, $processedText); | ||
153 | } | ||
154 | |||
155 | public function testReverseLastFeedPermalink() | ||
156 | { | ||
157 | $text = 'Description... '; | ||
158 | $text .= '<br>— <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>'; | ||
159 | $expected = $text; | ||
160 | $text .= '<br>— <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>'; | ||
161 | $expected .= '<br>— [Permalien](http://domain.tld/?0oc_VQ)'; | ||
162 | $processedText = reverse_feed_permalink($text); | ||
163 | |||
164 | $this->assertEquals($expected, $processedText); | ||
165 | } | ||
166 | |||
167 | public function testReverseNoFeedPermalink() | ||
168 | { | ||
169 | $text = 'Hello! Where are you from?'; | ||
170 | $expected = $text; | ||
171 | $processedText = reverse_feed_permalink($text); | ||
172 | |||
173 | $this->assertEquals($expected, $processedText); | ||
174 | } | ||
175 | |||
110 | /** | 176 | /** |
111 | * Test sanitize_html(). | 177 | * Test sanitize_html(). |
112 | */ | 178 | */ |
@@ -148,21 +214,18 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase | |||
148 | 214 | ||
149 | $data = array( | 215 | $data = array( |
150 | // Columns data | 216 | // Columns data |
151 | 'cols' => array( | 217 | 'linksToDisplay' => array( |
152 | // First, second, third. | 218 | // nth link |
153 | 0 => array( | 219 | 0 => array( |
154 | // nth link | 220 | 'formatedDescription' => $str, |
155 | 0 => array( | 221 | 'tags' => NO_MD_TAG, |
156 | 'formatedDescription' => $str, | 222 | 'taglist' => array(), |
157 | 'tags' => NO_MD_TAG, | ||
158 | 'taglist' => array(), | ||
159 | ), | ||
160 | ), | 223 | ), |
161 | ), | 224 | ), |
162 | ); | 225 | ); |
163 | 226 | ||
164 | $data = hook_markdown_render_daily($data, $this->conf); | 227 | $data = hook_markdown_render_daily($data, $this->conf); |
165 | $this->assertEquals($str, $data['cols'][0][0]['formatedDescription']); | 228 | $this->assertEquals($str, $data['linksToDisplay'][0]['formatedDescription']); |
166 | } | 229 | } |
167 | 230 | ||
168 | /** | 231 | /** |
@@ -197,7 +260,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase | |||
197 | $this->conf->get('security.markdown_escape', true), | 260 | $this->conf->get('security.markdown_escape', true), |
198 | $this->conf->get('security.allowed_protocols') | 261 | $this->conf->get('security.allowed_protocols') |
199 | ); | 262 | ); |
200 | $this->assertEquals($html, $data); | 263 | $this->assertEquals($html, $data . PHP_EOL); |
201 | } | 264 | } |
202 | 265 | ||
203 | /** | 266 | /** |