aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'tests/plugins')
-rw-r--r--tests/plugins/PluginAddlinkTest.php46
-rw-r--r--tests/plugins/PluginArchiveorgTest.php10
-rw-r--r--tests/plugins/PluginIssoTest.php15
-rw-r--r--tests/plugins/PluginMarkdownTest.php30
-rw-r--r--tests/plugins/PluginPlayvideosTest.php6
-rw-r--r--tests/plugins/PluginPubsubhubbubTest.php55
-rw-r--r--tests/plugins/PluginQrcodeTest.php (renamed from tests/plugins/PlugQrcodeTest.php)13
-rw-r--r--tests/plugins/PluginReadityourselfTest.php98
-rw-r--r--tests/plugins/PluginWallabagTest.php9
-rw-r--r--tests/plugins/WallabagInstanceTest.php8
-rw-r--r--tests/plugins/resources/markdown.html11
-rw-r--r--tests/plugins/resources/markdown.md12
12 files changed, 126 insertions, 187 deletions
diff --git a/tests/plugins/PluginAddlinkTest.php b/tests/plugins/PluginAddlinkTest.php
index a2f25bec..b6239e7f 100644
--- a/tests/plugins/PluginAddlinkTest.php
+++ b/tests/plugins/PluginAddlinkTest.php
@@ -16,7 +16,7 @@ class PluginAddlinkTest extends PHPUnit_Framework_TestCase
16 /** 16 /**
17 * Reset plugin path. 17 * Reset plugin path.
18 */ 18 */
19 function setUp() 19 public function setUp()
20 { 20 {
21 PluginManager::$PLUGINS_PATH = 'plugins'; 21 PluginManager::$PLUGINS_PATH = 'plugins';
22 } 22 }
@@ -24,7 +24,7 @@ class PluginAddlinkTest extends PHPUnit_Framework_TestCase
24 /** 24 /**
25 * Test render_header hook while logged in. 25 * Test render_header hook while logged in.
26 */ 26 */
27 function testAddlinkHeaderLoggedIn() 27 public function testAddlinkHeaderLoggedIn()
28 { 28 {
29 $str = 'stuff'; 29 $str = 'stuff';
30 $data = array($str => $str); 30 $data = array($str => $str);
@@ -46,7 +46,7 @@ class PluginAddlinkTest extends PHPUnit_Framework_TestCase
46 /** 46 /**
47 * Test render_header hook while logged out. 47 * Test render_header hook while logged out.
48 */ 48 */
49 function testAddlinkHeaderLoggedOut() 49 public function testAddlinkHeaderLoggedOut()
50 { 50 {
51 $str = 'stuff'; 51 $str = 'stuff';
52 $data = array($str => $str); 52 $data = array($str => $str);
@@ -57,44 +57,4 @@ class PluginAddlinkTest extends PHPUnit_Framework_TestCase
57 $this->assertEquals($str, $data[$str]); 57 $this->assertEquals($str, $data[$str]);
58 $this->assertArrayNotHasKey('fields_toolbar', $data); 58 $this->assertArrayNotHasKey('fields_toolbar', $data);
59 } 59 }
60
61 /**
62 * Test render_includes hook while logged in.
63 */
64 function testAddlinkIncludesLoggedIn()
65 {
66 $str = 'stuff';
67 $data = array($str => $str);
68 $data['_PAGE_'] = Router::$PAGE_LINKLIST;
69 $data['_LOGGEDIN_'] = true;
70
71 $data = hook_addlink_toolbar_render_includes($data);
72 $this->assertEquals($str, $data[$str]);
73 $this->assertEquals(1, count($data['css_files']));
74
75 $str = 'stuff';
76 $data = array($str => $str);
77 $data['_PAGE_'] = $str;
78 $data['_LOGGEDIN_'] = true;
79
80 $data = hook_addlink_toolbar_render_includes($data);
81 $this->assertEquals($str, $data[$str]);
82 $this->assertArrayNotHasKey('css_files', $data);
83 }
84
85 /**
86 * Test render_includes hook.
87 * Should not affect css files while logged out.
88 */
89 function testAddlinkIncludesLoggedOut()
90 {
91 $str = 'stuff';
92 $data = array($str => $str);
93 $data['_PAGE_'] = Router::$PAGE_LINKLIST;
94 $data['_LOGGEDIN_'] = false;
95
96 $data = hook_addlink_toolbar_render_includes($data);
97 $this->assertEquals($str, $data[$str]);
98 $this->assertArrayNotHasKey('css_files', $data);
99 }
100} 60}
diff --git a/tests/plugins/PluginArchiveorgTest.php b/tests/plugins/PluginArchiveorgTest.php
index 4daa4c9d..fecd5f2c 100644
--- a/tests/plugins/PluginArchiveorgTest.php
+++ b/tests/plugins/PluginArchiveorgTest.php
@@ -15,7 +15,7 @@ class PluginArchiveorgTest extends PHPUnit_Framework_TestCase
15 /** 15 /**
16 * Reset plugin path 16 * Reset plugin path
17 */ 17 */
18 function setUp() 18 public function setUp()
19 { 19 {
20 PluginManager::$PLUGINS_PATH = 'plugins'; 20 PluginManager::$PLUGINS_PATH = 'plugins';
21 } 21 }
@@ -23,7 +23,7 @@ class PluginArchiveorgTest extends PHPUnit_Framework_TestCase
23 /** 23 /**
24 * Test render_linklist hook on external links. 24 * Test render_linklist hook on external links.
25 */ 25 */
26 function testArchiveorgLinklistOnExternalLinks() 26 public function testArchiveorgLinklistOnExternalLinks()
27 { 27 {
28 $str = 'http://randomstr.com/test'; 28 $str = 'http://randomstr.com/test';
29 29
@@ -48,13 +48,12 @@ class PluginArchiveorgTest extends PHPUnit_Framework_TestCase
48 // plugin data 48 // plugin data
49 $this->assertEquals(1, count($link['link_plugin'])); 49 $this->assertEquals(1, count($link['link_plugin']));
50 $this->assertNotFalse(strpos($link['link_plugin'][0], $str)); 50 $this->assertNotFalse(strpos($link['link_plugin'][0], $str));
51
52 } 51 }
53 52
54 /** 53 /**
55 * Test render_linklist hook on internal links. 54 * Test render_linklist hook on internal links.
56 */ 55 */
57 function testArchiveorgLinklistOnInternalLinks() 56 public function testArchiveorgLinklistOnInternalLinks()
58 { 57 {
59 $internalLink1 = 'http://shaarli.shaarli/?qvMAqg'; 58 $internalLink1 = 'http://shaarli.shaarli/?qvMAqg';
60 $internalLinkRealURL1 = '?qvMAqg'; 59 $internalLinkRealURL1 = '?qvMAqg';
@@ -101,7 +100,6 @@ class PluginArchiveorgTest extends PHPUnit_Framework_TestCase
101 ) 100 )
102 ); 101 );
103 102
104
105 $data = hook_archiveorg_render_linklist($data); 103 $data = hook_archiveorg_render_linklist($data);
106 104
107 // Case n°1: first link type, public 105 // Case n°1: first link type, public
@@ -136,7 +134,5 @@ class PluginArchiveorgTest extends PHPUnit_Framework_TestCase
136 $link = $data['links'][5]; 134 $link = $data['links'][5];
137 135
138 $this->assertArrayNotHasKey('link_plugin', $link); 136 $this->assertArrayNotHasKey('link_plugin', $link);
139
140 } 137 }
141
142} 138}
diff --git a/tests/plugins/PluginIssoTest.php b/tests/plugins/PluginIssoTest.php
index 6b7904dd..0ae73183 100644
--- a/tests/plugins/PluginIssoTest.php
+++ b/tests/plugins/PluginIssoTest.php
@@ -1,4 +1,5 @@
1<?php 1<?php
2use Shaarli\Config\ConfigManager;
2 3
3require_once 'plugins/isso/isso.php'; 4require_once 'plugins/isso/isso.php';
4 5
@@ -12,7 +13,7 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
12 /** 13 /**
13 * Reset plugin path 14 * Reset plugin path
14 */ 15 */
15 function setUp() 16 public function setUp()
16 { 17 {
17 PluginManager::$PLUGINS_PATH = 'plugins'; 18 PluginManager::$PLUGINS_PATH = 'plugins';
18 } 19 }
@@ -20,7 +21,7 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
20 /** 21 /**
21 * Test Isso init without errors. 22 * Test Isso init without errors.
22 */ 23 */
23 function testWallabagInitNoError() 24 public function testWallabagInitNoError()
24 { 25 {
25 $conf = new ConfigManager(''); 26 $conf = new ConfigManager('');
26 $conf->set('plugins.ISSO_SERVER', 'value'); 27 $conf->set('plugins.ISSO_SERVER', 'value');
@@ -31,7 +32,7 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
31 /** 32 /**
32 * Test Isso init with errors. 33 * Test Isso init with errors.
33 */ 34 */
34 function testWallabagInitError() 35 public function testWallabagInitError()
35 { 36 {
36 $conf = new ConfigManager(''); 37 $conf = new ConfigManager('');
37 $errors = isso_init($conf); 38 $errors = isso_init($conf);
@@ -41,7 +42,7 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
41 /** 42 /**
42 * Test render_linklist hook with valid settings to display the comment form. 43 * Test render_linklist hook with valid settings to display the comment form.
43 */ 44 */
44 function testIssoDisplayed() 45 public function testIssoDisplayed()
45 { 46 {
46 $conf = new ConfigManager(''); 47 $conf = new ConfigManager('');
47 $conf->set('plugins.ISSO_SERVER', 'value'); 48 $conf->set('plugins.ISSO_SERVER', 'value');
@@ -81,7 +82,7 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
81 /** 82 /**
82 * Test isso plugin when multiple links are displayed (shouldn't be displayed). 83 * Test isso plugin when multiple links are displayed (shouldn't be displayed).
83 */ 84 */
84 function testIssoMultipleLinks() 85 public function testIssoMultipleLinks()
85 { 86 {
86 $conf = new ConfigManager(''); 87 $conf = new ConfigManager('');
87 $conf->set('plugins.ISSO_SERVER', 'value'); 88 $conf->set('plugins.ISSO_SERVER', 'value');
@@ -113,7 +114,7 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
113 /** 114 /**
114 * Test isso plugin when using search (shouldn't be displayed). 115 * Test isso plugin when using search (shouldn't be displayed).
115 */ 116 */
116 function testIssoNotDisplayedWhenSearch() 117 public function testIssoNotDisplayedWhenSearch()
117 { 118 {
118 $conf = new ConfigManager(''); 119 $conf = new ConfigManager('');
119 $conf->set('plugins.ISSO_SERVER', 'value'); 120 $conf->set('plugins.ISSO_SERVER', 'value');
@@ -141,7 +142,7 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
141 /** 142 /**
142 * Test isso plugin without server configuration (shouldn't be displayed). 143 * Test isso plugin without server configuration (shouldn't be displayed).
143 */ 144 */
144 function testIssoWithoutConf() 145 public function testIssoWithoutConf()
145 { 146 {
146 $data = 'abc'; 147 $data = 'abc';
147 $conf = new ConfigManager(''); 148 $conf = new ConfigManager('');
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
diff --git a/tests/plugins/PluginPlayvideosTest.php b/tests/plugins/PluginPlayvideosTest.php
index be1ef774..29ad047f 100644
--- a/tests/plugins/PluginPlayvideosTest.php
+++ b/tests/plugins/PluginPlayvideosTest.php
@@ -16,7 +16,7 @@ class PluginPlayvideosTest extends PHPUnit_Framework_TestCase
16 /** 16 /**
17 * Reset plugin path 17 * Reset plugin path
18 */ 18 */
19 function setUp() 19 public function setUp()
20 { 20 {
21 PluginManager::$PLUGINS_PATH = 'plugins'; 21 PluginManager::$PLUGINS_PATH = 'plugins';
22 } 22 }
@@ -24,7 +24,7 @@ class PluginPlayvideosTest extends PHPUnit_Framework_TestCase
24 /** 24 /**
25 * Test render_linklist hook. 25 * Test render_linklist hook.
26 */ 26 */
27 function testPlayvideosHeader() 27 public function testPlayvideosHeader()
28 { 28 {
29 $str = 'stuff'; 29 $str = 'stuff';
30 $data = array($str => $str); 30 $data = array($str => $str);
@@ -43,7 +43,7 @@ class PluginPlayvideosTest extends PHPUnit_Framework_TestCase
43 /** 43 /**
44 * Test render_footer hook. 44 * Test render_footer hook.
45 */ 45 */
46 function testPlayvideosFooter() 46 public function testPlayvideosFooter()
47 { 47 {
48 $str = 'stuff'; 48 $str = 'stuff';
49 $data = array($str => $str); 49 $data = array($str => $str);
diff --git a/tests/plugins/PluginPubsubhubbubTest.php b/tests/plugins/PluginPubsubhubbubTest.php
new file mode 100644
index 00000000..69d00936
--- /dev/null
+++ b/tests/plugins/PluginPubsubhubbubTest.php
@@ -0,0 +1,55 @@
1<?php
2use Shaarli\Config\ConfigManager;
3
4require_once 'plugins/pubsubhubbub/pubsubhubbub.php';
5require_once 'application/Router.php';
6
7/**
8 * Class PluginPubsubhubbubTest
9 * Unit test for the pubsubhubbub plugin
10 */
11class PluginPubsubhubbubTest extends PHPUnit_Framework_TestCase
12{
13 /**
14 * @var string Config file path (without extension).
15 */
16 protected static $configFile = 'tests/utils/config/configJson';
17
18 /**
19 * Reset plugin path
20 */
21 public function setUp()
22 {
23 PluginManager::$PLUGINS_PATH = 'plugins';
24 }
25
26 /**
27 * Test render_feed hook with an RSS feed.
28 */
29 public function testPubSubRssRenderFeed()
30 {
31 $hub = 'http://domain.hub';
32 $conf = new ConfigManager(self::$configFile);
33 $conf->set('plugins.PUBSUBHUB_URL', $hub);
34 $data['_PAGE_'] = Router::$PAGE_FEED_RSS;
35
36 $data = hook_pubsubhubbub_render_feed($data, $conf);
37 $expected = '<atom:link rel="hub" href="'. $hub .'" />';
38 $this->assertEquals($expected, $data['feed_plugins_header'][0]);
39 }
40
41 /**
42 * Test render_feed hook with an ATOM feed.
43 */
44 public function testPubSubAtomRenderFeed()
45 {
46 $hub = 'http://domain.hub';
47 $conf = new ConfigManager(self::$configFile);
48 $conf->set('plugins.PUBSUBHUB_URL', $hub);
49 $data['_PAGE_'] = Router::$PAGE_FEED_ATOM;
50
51 $data = hook_pubsubhubbub_render_feed($data, $conf);
52 $expected = '<link rel="hub" href="'. $hub .'" />';
53 $this->assertEquals($expected, $data['feed_plugins_header'][0]);
54 }
55}
diff --git a/tests/plugins/PlugQrcodeTest.php b/tests/plugins/PluginQrcodeTest.php
index 86dc7f29..ebfadddf 100644
--- a/tests/plugins/PlugQrcodeTest.php
+++ b/tests/plugins/PluginQrcodeTest.php
@@ -1,29 +1,28 @@
1<?php 1<?php
2
3/** 2/**
4 * PlugQrcodeTest.php 3 * PluginQrcodeTest.php
5 */ 4 */
6 5
7require_once 'plugins/qrcode/qrcode.php'; 6require_once 'plugins/qrcode/qrcode.php';
8require_once 'application/Router.php'; 7require_once 'application/Router.php';
9 8
10/** 9/**
11 * Class PlugQrcodeTest 10 * Class PluginQrcodeTest
12 * Unit test for the QR-Code plugin 11 * Unit test for the QR-Code plugin
13 */ 12 */
14class PlugQrcodeTest extends PHPUnit_Framework_TestCase 13class PluginQrcodeTest extends PHPUnit_Framework_TestCase
15{ 14{
16 /** 15 /**
17 * Reset plugin path 16 * Reset plugin path
18 */ 17 */
19 function setUp() { 18 public function setUp() {
20 PluginManager::$PLUGINS_PATH = 'plugins'; 19 PluginManager::$PLUGINS_PATH = 'plugins';
21 } 20 }
22 21
23 /** 22 /**
24 * Test render_linklist hook. 23 * Test render_linklist hook.
25 */ 24 */
26 function testQrcodeLinklist() 25 public function testQrcodeLinklist()
27 { 26 {
28 $str = 'http://randomstr.com/test'; 27 $str = 'http://randomstr.com/test';
29 $data = array( 28 $data = array(
@@ -49,7 +48,7 @@ class PlugQrcodeTest extends PHPUnit_Framework_TestCase
49 /** 48 /**
50 * Test render_footer hook. 49 * Test render_footer hook.
51 */ 50 */
52 function testQrcodeFooter() 51 public function testQrcodeFooter()
53 { 52 {
54 $str = 'stuff'; 53 $str = 'stuff';
55 $data = array($str => $str); 54 $data = array($str => $str);
diff --git a/tests/plugins/PluginReadityourselfTest.php b/tests/plugins/PluginReadityourselfTest.php
deleted file mode 100644
index 532db146..00000000
--- a/tests/plugins/PluginReadityourselfTest.php
+++ /dev/null
@@ -1,98 +0,0 @@
1<?php
2
3/**
4 * PluginReadityourselfTest.php.php
5 */
6
7require_once 'plugins/readityourself/readityourself.php';
8
9/**
10 * Class PluginWallabagTest
11 * Unit test for the Wallabag plugin
12 */
13class PluginReadityourselfTest extends PHPUnit_Framework_TestCase
14{
15 /**
16 * Reset plugin path
17 */
18 function setUp()
19 {
20 PluginManager::$PLUGINS_PATH = 'plugins';
21 }
22
23 /**
24 * Test Readityourself init without errors.
25 */
26 function testReadityourselfInitNoError()
27 {
28 $conf = new ConfigManager('');
29 $conf->set('plugins.READITYOUSELF_URL', 'value');
30 $errors = readityourself_init($conf);
31 $this->assertEmpty($errors);
32 }
33
34 /**
35 * Test Readityourself init with errors.
36 */
37 function testReadityourselfInitError()
38 {
39 $conf = new ConfigManager('');
40 $errors = readityourself_init($conf);
41 $this->assertNotEmpty($errors);
42 }
43
44 /**
45 * Test render_linklist hook.
46 */
47 function testReadityourselfLinklist()
48 {
49 $conf = new ConfigManager('');
50 $conf->set('plugins.READITYOUSELF_URL', 'value');
51 $str = 'http://randomstr.com/test';
52 $data = array(
53 'title' => $str,
54 'links' => array(
55 array(
56 'url' => $str,
57 )
58 )
59 );
60
61 $data = hook_readityourself_render_linklist($data, $conf);
62 $link = $data['links'][0];
63 // data shouldn't be altered
64 $this->assertEquals($str, $data['title']);
65 $this->assertEquals($str, $link['url']);
66
67 // plugin data
68 $this->assertEquals(1, count($link['link_plugin']));
69 $this->assertNotFalse(strpos($link['link_plugin'][0], $str));
70 }
71
72 /**
73 * Test without config: nothing should happened.
74 */
75 function testReadityourselfLinklistWithoutConfig()
76 {
77 $conf = new ConfigManager('');
78 $conf->set('plugins.READITYOUSELF_URL', null);
79 $str = 'http://randomstr.com/test';
80 $data = array(
81 'title' => $str,
82 'links' => array(
83 array(
84 'url' => $str,
85 )
86 )
87 );
88
89 $data = hook_readityourself_render_linklist($data, $conf);
90 $link = $data['links'][0];
91 // data shouldn't be altered
92 $this->assertEquals($str, $data['title']);
93 $this->assertEquals($str, $link['url']);
94
95 // plugin data
96 $this->assertArrayNotHasKey('link_plugin', $link);
97 }
98}
diff --git a/tests/plugins/PluginWallabagTest.php b/tests/plugins/PluginWallabagTest.php
index 2c268cbd..76b7887e 100644
--- a/tests/plugins/PluginWallabagTest.php
+++ b/tests/plugins/PluginWallabagTest.php
@@ -1,4 +1,5 @@
1<?php 1<?php
2use Shaarli\Config\ConfigManager;
2 3
3/** 4/**
4 * PluginWallabagTest.php.php 5 * PluginWallabagTest.php.php
@@ -15,7 +16,7 @@ class PluginWallabagTest extends PHPUnit_Framework_TestCase
15 /** 16 /**
16 * Reset plugin path 17 * Reset plugin path
17 */ 18 */
18 function setUp() 19 public function setUp()
19 { 20 {
20 PluginManager::$PLUGINS_PATH = 'plugins'; 21 PluginManager::$PLUGINS_PATH = 'plugins';
21 } 22 }
@@ -23,7 +24,7 @@ class PluginWallabagTest extends PHPUnit_Framework_TestCase
23 /** 24 /**
24 * Test wallabag init without errors. 25 * Test wallabag init without errors.
25 */ 26 */
26 function testWallabagInitNoError() 27 public function testWallabagInitNoError()
27 { 28 {
28 $conf = new ConfigManager(''); 29 $conf = new ConfigManager('');
29 $conf->set('plugins.WALLABAG_URL', 'value'); 30 $conf->set('plugins.WALLABAG_URL', 'value');
@@ -34,7 +35,7 @@ class PluginWallabagTest extends PHPUnit_Framework_TestCase
34 /** 35 /**
35 * Test wallabag init with errors. 36 * Test wallabag init with errors.
36 */ 37 */
37 function testWallabagInitError() 38 public function testWallabagInitError()
38 { 39 {
39 $conf = new ConfigManager(''); 40 $conf = new ConfigManager('');
40 $errors = wallabag_init($conf); 41 $errors = wallabag_init($conf);
@@ -44,7 +45,7 @@ class PluginWallabagTest extends PHPUnit_Framework_TestCase
44 /** 45 /**
45 * Test render_linklist hook. 46 * Test render_linklist hook.
46 */ 47 */
47 function testWallabagLinklist() 48 public function testWallabagLinklist()
48 { 49 {
49 $conf = new ConfigManager(''); 50 $conf = new ConfigManager('');
50 $conf->set('plugins.WALLABAG_URL', 'value'); 51 $conf->set('plugins.WALLABAG_URL', 'value');
diff --git a/tests/plugins/WallabagInstanceTest.php b/tests/plugins/WallabagInstanceTest.php
index 7c14c1df..2c466871 100644
--- a/tests/plugins/WallabagInstanceTest.php
+++ b/tests/plugins/WallabagInstanceTest.php
@@ -15,7 +15,7 @@ class WallabagInstanceTest extends PHPUnit_Framework_TestCase
15 /** 15 /**
16 * Reset plugin path 16 * Reset plugin path
17 */ 17 */
18 function setUp() 18 public function setUp()
19 { 19 {
20 $this->instance = 'http://some.url'; 20 $this->instance = 'http://some.url';
21 } 21 }
@@ -23,7 +23,7 @@ class WallabagInstanceTest extends PHPUnit_Framework_TestCase
23 /** 23 /**
24 * Test WallabagInstance with API V1. 24 * Test WallabagInstance with API V1.
25 */ 25 */
26 function testWallabagInstanceV1() 26 public function testWallabagInstanceV1()
27 { 27 {
28 $instance = new WallabagInstance($this->instance, 1); 28 $instance = new WallabagInstance($this->instance, 1);
29 $expected = $this->instance . '/?plainurl='; 29 $expected = $this->instance . '/?plainurl=';
@@ -34,7 +34,7 @@ class WallabagInstanceTest extends PHPUnit_Framework_TestCase
34 /** 34 /**
35 * Test WallabagInstance with API V2. 35 * Test WallabagInstance with API V2.
36 */ 36 */
37 function testWallabagInstanceV2() 37 public function testWallabagInstanceV2()
38 { 38 {
39 $instance = new WallabagInstance($this->instance, 2); 39 $instance = new WallabagInstance($this->instance, 2);
40 $expected = $this->instance . '/bookmarklet?url='; 40 $expected = $this->instance . '/bookmarklet?url=';
@@ -45,7 +45,7 @@ class WallabagInstanceTest extends PHPUnit_Framework_TestCase
45 /** 45 /**
46 * Test WallabagInstance with an invalid API version. 46 * Test WallabagInstance with an invalid API version.
47 */ 47 */
48 function testWallabagInstanceInvalidVersion() 48 public function testWallabagInstanceInvalidVersion()
49 { 49 {
50 $instance = new WallabagInstance($this->instance, false); 50 $instance = new WallabagInstance($this->instance, false);
51 $expected = $this->instance . '/?plainurl='; 51 $expected = $this->instance . '/?plainurl=';
diff --git a/tests/plugins/resources/markdown.html b/tests/plugins/resources/markdown.html
index 07a5a32e..844a6f31 100644
--- a/tests/plugins/resources/markdown.html
+++ b/tests/plugins/resources/markdown.html
@@ -21,4 +21,13 @@
21next #foo</code></pre> 21next #foo</code></pre>
22<p>Block:</p> 22<p>Block:</p>
23<pre><code>lorem ipsum #foobar http://link.tld 23<pre><code>lorem ipsum #foobar http://link.tld
24#foobar http://link.tld</code></pre></div> \ No newline at end of file 24#foobar http://link.tld</code></pre>
25<p><a href="?123456">link</a><br />
26<img src="/img/train.png" alt="link" /><br />
27<a href="http://test.tld/path/?query=value#hash">link</a><br />
28<a href="http://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 />
31<a href="magnet:test.tld/path/?query=value#hash">link</a><br />
32<a href="http://alert('xss')">link</a><br />
33<a href="http://test.tld/path/?query=value#hash">link</a></p></div> \ No newline at end of file
diff --git a/tests/plugins/resources/markdown.md b/tests/plugins/resources/markdown.md
index 0b8be7c5..b8ebd934 100644
--- a/tests/plugins/resources/markdown.md
+++ b/tests/plugins/resources/markdown.md
@@ -21,4 +21,14 @@ Block:
21``` 21```
22lorem ipsum #foobar http://link.tld 22lorem ipsum #foobar http://link.tld
23#foobar http://link.tld 23#foobar http://link.tld
24``` \ No newline at end of file 24```
25
26[link](?123456)
27![link](/img/train.png)
28[link](test.tld/path/?query=value#hash)
29[link](http://test.tld/path/?query=value#hash)
30[link](https://test.tld/path/?query=value#hash)
31[link](ftp://test.tld/path/?query=value#hash)
32[link](magnet:test.tld/path/?query=value#hash)
33[link](javascript:alert('xss'))
34[link](other://test.tld/path/?query=value#hash) \ No newline at end of file