aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/plugins
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2019-07-27 12:34:30 +0200
committerArthurHoaro <arthur@hoa.ro>2019-07-27 12:34:30 +0200
commit38672ba0d1c722e5d6d33a58255ceb55e9410e46 (patch)
treedae4c7c47532380eac3ae641db99122fc77c93dc /tests/plugins
parent83faedadff76c5bdca036f39f13943f63b27e164 (diff)
parent1e77e0448bbd25675d8c0fe4a73206ad9048904b (diff)
downloadShaarli-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')
-rw-r--r--tests/plugins/PluginIssoTest.php16
-rw-r--r--tests/plugins/PluginMarkdownTest.php99
-rw-r--r--tests/plugins/PluginQrcodeTest.php3
-rw-r--r--tests/plugins/resources/hashtags.md10
-rw-r--r--tests/plugins/resources/hashtags.raw10
-rw-r--r--tests/plugins/resources/markdown.html12
-rw-r--r--tests/plugins/resources/markdown.md2
-rw-r--r--tests/plugins/test/test.php2
8 files changed, 121 insertions, 33 deletions
diff --git a/tests/plugins/PluginIssoTest.php b/tests/plugins/PluginIssoTest.php
index 0ae73183..2c9efbcd 100644
--- a/tests/plugins/PluginIssoTest.php
+++ b/tests/plugins/PluginIssoTest.php
@@ -21,7 +21,7 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
21 /** 21 /**
22 * Test Isso init without errors. 22 * Test Isso init without errors.
23 */ 23 */
24 public function testWallabagInitNoError() 24 public function testIssoInitNoError()
25 { 25 {
26 $conf = new ConfigManager(''); 26 $conf = new ConfigManager('');
27 $conf->set('plugins.ISSO_SERVER', 'value'); 27 $conf->set('plugins.ISSO_SERVER', 'value');
@@ -32,7 +32,7 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
32 /** 32 /**
33 * Test Isso init with errors. 33 * Test Isso init with errors.
34 */ 34 */
35 public function testWallabagInitError() 35 public function testIssoInitError()
36 { 36 {
37 $conf = new ConfigManager(''); 37 $conf = new ConfigManager('');
38 $errors = isso_init($conf); 38 $errors = isso_init($conf);
@@ -96,19 +96,22 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
96 array( 96 array(
97 'id' => 12, 97 'id' => 12,
98 'url' => $str, 98 'url' => $str,
99 'shorturl' => $short1 = 'abcd',
99 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date1), 100 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date1),
100 ), 101 ),
101 array( 102 array(
102 'id' => 13, 103 'id' => 13,
103 'url' => $str . '2', 104 'url' => $str . '2',
105 'shorturl' => $short2 = 'efgh',
104 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date2), 106 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date2),
105 ), 107 ),
106 ) 108 )
107 ); 109 );
108 110
109 $processed = hook_isso_render_linklist($data, $conf); 111 $processed = hook_isso_render_linklist($data, $conf);
110 // data shouldn't be altered 112 // link_plugin should be added for the icon
111 $this->assertEquals($data, $processed); 113 $this->assertContains('<a href="?'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]);
114 $this->assertContains('<a href="?'. $short2 .'#isso-thread">', $processed['links'][1]['link_plugin'][0]);
112 } 115 }
113 116
114 /** 117 /**
@@ -127,6 +130,7 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
127 array( 130 array(
128 'id' => 12, 131 'id' => 12,
129 'url' => $str, 132 'url' => $str,
133 'shorturl' => $short1 = 'abcd',
130 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date), 134 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date),
131 ) 135 )
132 ), 136 ),
@@ -135,8 +139,8 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
135 139
136 $processed = hook_isso_render_linklist($data, $conf); 140 $processed = hook_isso_render_linklist($data, $conf);
137 141
138 // data shouldn't be altered 142 // link_plugin should be added for the icon
139 $this->assertEquals($data, $processed); 143 $this->assertContains('<a href="?'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]);
140 } 144 }
141 145
142 /** 146 /**
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 .= '&#8212; <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 '&#8212; <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 .= '&#8212; <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>';
149 $expected = 'Description... &#8212; [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>&#8212; <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>';
159 $expected = $text;
160 $text .= '<br>&#8212; <a href="http://domain.tld/?0oc_VQ" title="Permalien">Permalien</a>';
161 $expected .= '<br>&#8212; [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 /**
diff --git a/tests/plugins/PluginQrcodeTest.php b/tests/plugins/PluginQrcodeTest.php
index ebfadddf..dd632eee 100644
--- a/tests/plugins/PluginQrcodeTest.php
+++ b/tests/plugins/PluginQrcodeTest.php
@@ -15,7 +15,8 @@ class PluginQrcodeTest extends PHPUnit_Framework_TestCase
15 /** 15 /**
16 * Reset plugin path 16 * Reset plugin path
17 */ 17 */
18 public function setUp() { 18 public function setUp()
19 {
19 PluginManager::$PLUGINS_PATH = 'plugins'; 20 PluginManager::$PLUGINS_PATH = 'plugins';
20 } 21 }
21 22
diff --git a/tests/plugins/resources/hashtags.md b/tests/plugins/resources/hashtags.md
new file mode 100644
index 00000000..46326de3
--- /dev/null
+++ b/tests/plugins/resources/hashtags.md
@@ -0,0 +1,10 @@
1[#lol](?addtag=lol)
2
3 #test
4
5`#test2`
6
7```
8bla #bli blo
9#bla
10```
diff --git a/tests/plugins/resources/hashtags.raw b/tests/plugins/resources/hashtags.raw
new file mode 100644
index 00000000..9d2dc98a
--- /dev/null
+++ b/tests/plugins/resources/hashtags.raw
@@ -0,0 +1,10 @@
1#lol
2
3 #test
4
5`#test2`
6
7```
8bla #bli blo
9#bla
10```
diff --git a/tests/plugins/resources/markdown.html b/tests/plugins/resources/markdown.html
index 844a6f31..c3460bf7 100644
--- a/tests/plugins/resources/markdown.html
+++ b/tests/plugins/resources/markdown.html
@@ -8,15 +8,15 @@
8</ul> 8</ul>
9<ol> 9<ol>
10<li><a href="http://link.tld">zero</a> 10<li><a href="http://link.tld">zero</a>
11<ol> 11<ol start="2">
12<li><a href="http://link.tld">two</a></li> 12<li><a href="http://link.tld">two</a></li>
13<li><a href="http://link.tld">three</a></li> 13<li><a href="http://link.tld">three</a></li>
14<li><a href="http://link.tld">four</a></li> 14<li><a href="http://link.tld">four</a></li>
15<li>foo &lt;a href=&quot;?addtag=foobar&quot; title=&quot;Hashtag foobar&quot;&gt;#foobar&lt;/a&gt;</li> 15<li>foo <a href="?addtag=foobar">#foobar</a></li>
16</ol></li> 16</ol></li>
17</ol> 17</ol>
18<p>&lt;a href=&quot;?addtag=foobar&quot; title=&quot;Hashtag foobar&quot;&gt;#foobar&lt;/a&gt; foo <code>lol #foo</code> &lt;a href=&quot;?addtag=bar&quot; title=&quot;Hashtag bar&quot;&gt;#bar&lt;/a&gt;</p> 18<p><a href="?addtag=foobar">#foobar</a> foo <code>lol #foo</code> <a href="?addtag=bar">#bar</a></p>
19<p>fsdfs <a href="http://link.tld">http://link.tld</a> &lt;a href=&quot;?addtag=foobar&quot; title=&quot;Hashtag foobar&quot;&gt;#foobar&lt;/a&gt; <code>http://link.tld</code></p> 19<p>fsdfs <a href="http://link.tld">http://link.tld</a> <a href="?addtag=foobar">#foobar</a> <code>http://link.tld</code></p>
20<pre><code>http://link.tld #foobar 20<pre><code>http://link.tld #foobar
21next #foo</code></pre> 21next #foo</code></pre>
22<p>Block:</p> 22<p>Block:</p>
@@ -29,5 +29,5 @@ next #foo</code></pre>
29<a href="https://test.tld/path/?query=value#hash">link</a><br /> 29<a href="https://test.tld/path/?query=value#hash">link</a><br />
30<a href="ftp://test.tld/path/?query=value#hash">link</a><br /> 30<a href="ftp://test.tld/path/?query=value#hash">link</a><br />
31<a href="magnet:test.tld/path/?query=value#hash">link</a><br /> 31<a href="magnet:test.tld/path/?query=value#hash">link</a><br />
32<a href="http://alert('xss')">link</a><br /> 32<a href="http://alert(&#039;xss&#039;)">link</a><br />
33<a href="http://test.tld/path/?query=value#hash">link</a></p></div> \ No newline at end of file 33<a href="http://test.tld/path/?query=value#hash">link</a></p></div>
diff --git a/tests/plugins/resources/markdown.md b/tests/plugins/resources/markdown.md
index b8ebd934..9350a8c7 100644
--- a/tests/plugins/resources/markdown.md
+++ b/tests/plugins/resources/markdown.md
@@ -31,4 +31,4 @@ lorem ipsum #foobar http://link.tld
31[link](ftp://test.tld/path/?query=value#hash) 31[link](ftp://test.tld/path/?query=value#hash)
32[link](magnet:test.tld/path/?query=value#hash) 32[link](magnet:test.tld/path/?query=value#hash)
33[link](javascript:alert('xss')) 33[link](javascript:alert('xss'))
34[link](other://test.tld/path/?query=value#hash) \ No newline at end of file 34[link](other://test.tld/path/?query=value#hash)
diff --git a/tests/plugins/test/test.php b/tests/plugins/test/test.php
index 3d750c90..2aaf5122 100644
--- a/tests/plugins/test/test.php
+++ b/tests/plugins/test/test.php
@@ -11,7 +11,7 @@ function hook_test_random($data)
11{ 11{
12 if (isset($data['_PAGE_']) && $data['_PAGE_'] == 'test') { 12 if (isset($data['_PAGE_']) && $data['_PAGE_'] == 'test') {
13 $data[1] = 'page test'; 13 $data[1] = 'page test';
14 } else if (isset($data['_LOGGEDIN_']) && $data['_LOGGEDIN_'] === true) { 14 } elseif (isset($data['_LOGGEDIN_']) && $data['_LOGGEDIN_'] === true) {
15 $data[1] = 'loggedin'; 15 $data[1] = 'loggedin';
16 } else { 16 } else {
17 $data[1] = $data[0]; 17 $data[1] = $data[0];