aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--[-rwxr-xr-x]tests/ConfigTest.php354
-rw-r--r--tests/PluginManagerTest.php66
-rw-r--r--tests/RouterTest.php515
-rw-r--r--tests/plugins/PlugQrcodeTest.php67
-rw-r--r--tests/plugins/PluginAddlinkTest.php100
-rw-r--r--tests/plugins/PluginArchiveorgTest.php48
-rw-r--r--tests/plugins/PluginPlayvideosTest.php61
-rw-r--r--tests/plugins/PluginReadityourselfTest.php75
-rw-r--r--tests/plugins/PluginWallabagTest.php49
-rw-r--r--tests/plugins/test/test.php21
10 files changed, 1179 insertions, 177 deletions
diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php
index a239d8b7..adebfcc3 100755..100644
--- a/tests/ConfigTest.php
+++ b/tests/ConfigTest.php
@@ -1,177 +1,177 @@
1<?php 1<?php
2/** 2/**
3 * Config' tests 3 * Config' tests
4 */ 4 */
5 5
6require_once 'application/Config.php'; 6require_once 'application/Config.php';
7 7
8/** 8/**
9 * Unitary tests for Shaarli config related functions 9 * Unitary tests for Shaarli config related functions
10 */ 10 */
11class ConfigTest extends PHPUnit_Framework_TestCase 11class ConfigTest extends PHPUnit_Framework_TestCase
12{ 12{
13 // Configuration input set. 13 // Configuration input set.
14 private static $_configFields; 14 private static $configFields;
15 15
16 /** 16 /**
17 * Executed before each test. 17 * Executed before each test.
18 */ 18 */
19 public function setUp() 19 public function setUp()
20 { 20 {
21 self::$_configFields = array( 21 self::$configFields = array(
22 'login' => 'login', 22 'login' => 'login',
23 'hash' => 'hash', 23 'hash' => 'hash',
24 'salt' => 'salt', 24 'salt' => 'salt',
25 'timezone' => 'Europe/Paris', 25 'timezone' => 'Europe/Paris',
26 'title' => 'title', 26 'title' => 'title',
27 'titleLink' => 'titleLink', 27 'titleLink' => 'titleLink',
28 'redirector' => '', 28 'redirector' => '',
29 'disablesessionprotection' => false, 29 'disablesessionprotection' => false,
30 'privateLinkByDefault' => false, 30 'privateLinkByDefault' => false,
31 'config' => array( 31 'config' => array(
32 'CONFIG_FILE' => 'tests/config.php', 32 'CONFIG_FILE' => 'tests/config.php',
33 'DATADIR' => 'tests', 33 'DATADIR' => 'tests',
34 'config1' => 'config1data', 34 'config1' => 'config1data',
35 'config2' => 'config2data', 35 'config2' => 'config2data',
36 ) 36 )
37 ); 37 );
38 } 38 }
39 39
40 /** 40 /**
41 * Executed after each test. 41 * Executed after each test.
42 * 42 *
43 * @return void 43 * @return void
44 */ 44 */
45 public function tearDown() 45 public function tearDown()
46 { 46 {
47 if (is_file(self::$_configFields['config']['CONFIG_FILE'])) { 47 if (is_file(self::$configFields['config']['CONFIG_FILE'])) {
48 unlink(self::$_configFields['config']['CONFIG_FILE']); 48 unlink(self::$configFields['config']['CONFIG_FILE']);
49 } 49 }
50 } 50 }
51 51
52 /** 52 /**
53 * Test writeConfig function, valid use case, while being logged in. 53 * Test writeConfig function, valid use case, while being logged in.
54 */ 54 */
55 public function testWriteConfig() 55 public function testWriteConfig()
56 { 56 {
57 writeConfig(self::$_configFields, true); 57 writeConfig(self::$configFields, true);
58 58
59 include self::$_configFields['config']['CONFIG_FILE']; 59 include self::$configFields['config']['CONFIG_FILE'];
60 $this->assertEquals(self::$_configFields['login'], $GLOBALS['login']); 60 $this->assertEquals(self::$configFields['login'], $GLOBALS['login']);
61 $this->assertEquals(self::$_configFields['hash'], $GLOBALS['hash']); 61 $this->assertEquals(self::$configFields['hash'], $GLOBALS['hash']);
62 $this->assertEquals(self::$_configFields['salt'], $GLOBALS['salt']); 62 $this->assertEquals(self::$configFields['salt'], $GLOBALS['salt']);
63 $this->assertEquals(self::$_configFields['timezone'], $GLOBALS['timezone']); 63 $this->assertEquals(self::$configFields['timezone'], $GLOBALS['timezone']);
64 $this->assertEquals(self::$_configFields['title'], $GLOBALS['title']); 64 $this->assertEquals(self::$configFields['title'], $GLOBALS['title']);
65 $this->assertEquals(self::$_configFields['titleLink'], $GLOBALS['titleLink']); 65 $this->assertEquals(self::$configFields['titleLink'], $GLOBALS['titleLink']);
66 $this->assertEquals(self::$_configFields['redirector'], $GLOBALS['redirector']); 66 $this->assertEquals(self::$configFields['redirector'], $GLOBALS['redirector']);
67 $this->assertEquals(self::$_configFields['disablesessionprotection'], $GLOBALS['disablesessionprotection']); 67 $this->assertEquals(self::$configFields['disablesessionprotection'], $GLOBALS['disablesessionprotection']);
68 $this->assertEquals(self::$_configFields['privateLinkByDefault'], $GLOBALS['privateLinkByDefault']); 68 $this->assertEquals(self::$configFields['privateLinkByDefault'], $GLOBALS['privateLinkByDefault']);
69 $this->assertEquals(self::$_configFields['config']['config1'], $GLOBALS['config']['config1']); 69 $this->assertEquals(self::$configFields['config']['config1'], $GLOBALS['config']['config1']);
70 $this->assertEquals(self::$_configFields['config']['config2'], $GLOBALS['config']['config2']); 70 $this->assertEquals(self::$configFields['config']['config2'], $GLOBALS['config']['config2']);
71 } 71 }
72 72
73 /** 73 /**
74 * Test writeConfig option while logged in: 74 * Test writeConfig option while logged in:
75 * 1. init fields. 75 * 1. init fields.
76 * 2. update fields, add new sub config, add new root config. 76 * 2. update fields, add new sub config, add new root config.
77 * 3. rewrite config. 77 * 3. rewrite config.
78 * 4. check result. 78 * 4. check result.
79 */ 79 */
80 public function testWriteConfigFieldUpdate() 80 public function testWriteConfigFieldUpdate()
81 { 81 {
82 writeConfig(self::$_configFields, true); 82 writeConfig(self::$configFields, true);
83 self::$_configFields['title'] = 'ok'; 83 self::$configFields['title'] = 'ok';
84 self::$_configFields['config']['config1'] = 'ok'; 84 self::$configFields['config']['config1'] = 'ok';
85 self::$_configFields['config']['config_new'] = 'ok'; 85 self::$configFields['config']['config_new'] = 'ok';
86 self::$_configFields['new'] = 'should not be saved'; 86 self::$configFields['new'] = 'should not be saved';
87 writeConfig(self::$_configFields, true); 87 writeConfig(self::$configFields, true);
88 88
89 include self::$_configFields['config']['CONFIG_FILE']; 89 include self::$configFields['config']['CONFIG_FILE'];
90 $this->assertEquals('ok', $GLOBALS['title']); 90 $this->assertEquals('ok', $GLOBALS['title']);
91 $this->assertEquals('ok', $GLOBALS['config']['config1']); 91 $this->assertEquals('ok', $GLOBALS['config']['config1']);
92 $this->assertEquals('ok', $GLOBALS['config']['config_new']); 92 $this->assertEquals('ok', $GLOBALS['config']['config_new']);
93 $this->assertFalse(isset($GLOBALS['new'])); 93 $this->assertFalse(isset($GLOBALS['new']));
94 } 94 }
95 95
96 /** 96 /**
97 * Test writeConfig function with an empty array. 97 * Test writeConfig function with an empty array.
98 * 98 *
99 * @expectedException MissingFieldConfigException 99 * @expectedException MissingFieldConfigException
100 */ 100 */
101 public function testWriteConfigEmpty() 101 public function testWriteConfigEmpty()
102 { 102 {
103 writeConfig(array(), true); 103 writeConfig(array(), true);
104 } 104 }
105 105
106 /** 106 /**
107 * Test writeConfig function with a missing mandatory field. 107 * Test writeConfig function with a missing mandatory field.
108 * 108 *
109 * @expectedException MissingFieldConfigException 109 * @expectedException MissingFieldConfigException
110 */ 110 */
111 public function testWriteConfigMissingField() 111 public function testWriteConfigMissingField()
112 { 112 {
113 unset(self::$_configFields['login']); 113 unset(self::$configFields['login']);
114 writeConfig(self::$_configFields, true); 114 writeConfig(self::$configFields, true);
115 } 115 }
116 116
117 /** 117 /**
118 * Test writeConfig function while being logged out, and there is no config file existing. 118 * Test writeConfig function while being logged out, and there is no config file existing.
119 */ 119 */
120 public function testWriteConfigLoggedOutNoFile() 120 public function testWriteConfigLoggedOutNoFile()
121 { 121 {
122 writeConfig(self::$_configFields, false); 122 writeConfig(self::$configFields, false);
123 } 123 }
124 124
125 /** 125 /**
126 * Test writeConfig function while being logged out, and a config file already exists. 126 * Test writeConfig function while being logged out, and a config file already exists.
127 * 127 *
128 * @expectedException UnauthorizedConfigException 128 * @expectedException UnauthorizedConfigException
129 */ 129 */
130 public function testWriteConfigLoggedOutWithFile() 130 public function testWriteConfigLoggedOutWithFile()
131 { 131 {
132 file_put_contents(self::$_configFields['config']['CONFIG_FILE'], ''); 132 file_put_contents(self::$configFields['config']['CONFIG_FILE'], '');
133 writeConfig(self::$_configFields, false); 133 writeConfig(self::$configFields, false);
134 } 134 }
135 135
136 /** 136 /**
137 * Test mergeDeprecatedConfig while being logged in: 137 * Test mergeDeprecatedConfig while being logged in:
138 * 1. init a config file. 138 * 1. init a config file.
139 * 2. init a options.php file with update value. 139 * 2. init a options.php file with update value.
140 * 3. merge. 140 * 3. merge.
141 * 4. check updated value in config file. 141 * 4. check updated value in config file.
142 */ 142 */
143 public function testMergeDeprecatedConfig() 143 public function testMergeDeprecatedConfig()
144 { 144 {
145 // init 145 // init
146 writeConfig(self::$_configFields, true); 146 writeConfig(self::$configFields, true);
147 $configCopy = self::$_configFields; 147 $configCopy = self::$configFields;
148 $invert = !$configCopy['privateLinkByDefault']; 148 $invert = !$configCopy['privateLinkByDefault'];
149 $configCopy['privateLinkByDefault'] = $invert; 149 $configCopy['privateLinkByDefault'] = $invert;
150 150
151 // Use writeConfig to create a options.php 151 // Use writeConfig to create a options.php
152 $configCopy['config']['CONFIG_FILE'] = 'tests/options.php'; 152 $configCopy['config']['CONFIG_FILE'] = 'tests/options.php';
153 writeConfig($configCopy, true); 153 writeConfig($configCopy, true);
154 154
155 $this->assertTrue(is_file($configCopy['config']['CONFIG_FILE'])); 155 $this->assertTrue(is_file($configCopy['config']['CONFIG_FILE']));
156 156
157 // merge configs 157 // merge configs
158 mergeDeprecatedConfig(self::$_configFields, true); 158 mergeDeprecatedConfig(self::$configFields, true);
159 159
160 // make sure updated field is changed 160 // make sure updated field is changed
161 include self::$_configFields['config']['CONFIG_FILE']; 161 include self::$configFields['config']['CONFIG_FILE'];
162 $this->assertEquals($invert, $GLOBALS['privateLinkByDefault']); 162 $this->assertEquals($invert, $GLOBALS['privateLinkByDefault']);
163 $this->assertFalse(is_file($configCopy['config']['CONFIG_FILE'])); 163 $this->assertFalse(is_file($configCopy['config']['CONFIG_FILE']));
164 } 164 }
165 165
166 /** 166 /**
167 * Test mergeDeprecatedConfig while being logged in without options file. 167 * Test mergeDeprecatedConfig while being logged in without options file.
168 */ 168 */
169 public function testMergeDeprecatedConfigNoFile() 169 public function testMergeDeprecatedConfigNoFile()
170 { 170 {
171 writeConfig(self::$_configFields, true); 171 writeConfig(self::$configFields, true);
172 mergeDeprecatedConfig(self::$_configFields, true); 172 mergeDeprecatedConfig(self::$configFields, true);
173 173
174 include self::$_configFields['config']['CONFIG_FILE']; 174 include self::$configFields['config']['CONFIG_FILE'];
175 $this->assertEquals(self::$_configFields['login'], $GLOBALS['login']); 175 $this->assertEquals(self::$configFields['login'], $GLOBALS['login']);
176 } 176 }
177} 177}
diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php
new file mode 100644
index 00000000..df2614b5
--- /dev/null
+++ b/tests/PluginManagerTest.php
@@ -0,0 +1,66 @@
1<?php
2
3/**
4 * Plugin Manager tests
5 */
6
7require_once 'application/PluginManager.php';
8
9/**
10 * Unit tests for Plugins
11 */
12class PluginManagerTest extends PHPUnit_Framework_TestCase
13{
14 /**
15 * Path to tests plugin.
16 * @var string $pluginPath
17 */
18 private static $pluginPath = 'tests/plugins';
19
20 /**
21 * Test plugin.
22 * @var string $pluginName
23 */
24 private static $pluginName = 'test';
25
26 /**
27 * Test plugin loading and hook execution.
28 *
29 * @return void
30 */
31 public function testPlugin()
32 {
33 $pluginManager = PluginManager::getInstance();
34
35 PluginManager::$PLUGINS_PATH = self::$pluginPath;
36 $pluginManager->load(array(self::$pluginName));
37
38 $this->assertTrue(function_exists('hook_test_random'));
39
40 $data = array(0 => 'woot');
41 $pluginManager->executeHooks('random', $data);
42 $this->assertEquals('woot', $data[1]);
43
44 $data = array(0 => 'woot');
45 $pluginManager->executeHooks('random', $data, array('target' => 'test'));
46 $this->assertEquals('page test', $data[1]);
47
48 $data = array(0 => 'woot');
49 $pluginManager->executeHooks('random', $data, array('loggedin' => true));
50 $this->assertEquals('loggedin', $data[1]);
51 }
52
53 /**
54 * Test missing plugin loading.
55 *
56 * @return void
57 */
58 public function testPluginNotFound()
59 {
60 $pluginManager = PluginManager::getInstance();
61
62 $pluginManager->load(array());
63
64 $pluginManager->load(array('nope', 'renope'));
65 }
66} \ No newline at end of file
diff --git a/tests/RouterTest.php b/tests/RouterTest.php
new file mode 100644
index 00000000..544bcf9c
--- /dev/null
+++ b/tests/RouterTest.php
@@ -0,0 +1,515 @@
1<?php
2
3/**
4 * Router tests
5 */
6
7require_once 'application/Router.php';
8
9/**
10 * Unit tests for Router
11 */
12class RouterTest extends PHPUnit_Framework_TestCase
13{
14 /**
15 * Test findPage: login page output.
16 * Valid: page should be return.
17 *
18 * @return void
19 */
20 public function testFindPageLoginValid()
21 {
22 $this->assertEquals(
23 Router::$PAGE_LOGIN,
24 Router::findPage('do=login', array(), false)
25 );
26
27 $this->assertEquals(
28 Router::$PAGE_LOGIN,
29 Router::findPage('do=login', array(), 1)
30 );
31
32 $this->assertEquals(
33 Router::$PAGE_LOGIN,
34 Router::findPage('do=login&stuff', array(), false)
35 );
36 }
37
38 /**
39 * Test findPage: login page output.
40 * Invalid: page shouldn't be return.
41 *
42 * @return void
43 */
44 public function testFindPageLoginInvalid()
45 {
46 $this->assertNotEquals(
47 Router::$PAGE_LOGIN,
48 Router::findPage('do=login', array(), true)
49 );
50
51 $this->assertNotEquals(
52 Router::$PAGE_LOGIN,
53 Router::findPage('do=other', array(), false)
54 );
55 }
56
57 /**
58 * Test findPage: picwall page output.
59 * Valid: page should be return.
60 *
61 * @return void
62 */
63 public function testFindPagePicwallValid()
64 {
65 $this->assertEquals(
66 Router::$PAGE_PICWALL,
67 Router::findPage('do=picwall', array(), false)
68 );
69
70 $this->assertEquals(
71 Router::$PAGE_PICWALL,
72 Router::findPage('do=picwall', array(), true)
73 );
74 }
75
76 /**
77 * Test findPage: picwall page output.
78 * Invalid: page shouldn't be return.
79 *
80 * @return void
81 */
82 public function testFindPagePicwallInvalid()
83 {
84 $this->assertEquals(
85 Router::$PAGE_PICWALL,
86 Router::findPage('do=picwall&stuff', array(), false)
87 );
88
89 $this->assertNotEquals(
90 Router::$PAGE_PICWALL,
91 Router::findPage('do=other', array(), false)
92 );
93 }
94
95 /**
96 * Test findPage: tagcloud page output.
97 * Valid: page should be return.
98 *
99 * @return void
100 */
101 public function testFindPageTagcloudValid()
102 {
103 $this->assertEquals(
104 Router::$PAGE_TAGCLOUD,
105 Router::findPage('do=tagcloud', array(), false)
106 );
107
108 $this->assertEquals(
109 Router::$PAGE_TAGCLOUD,
110 Router::findPage('do=tagcloud', array(), true)
111 );
112
113 $this->assertEquals(
114 Router::$PAGE_TAGCLOUD,
115 Router::findPage('do=tagcloud&stuff', array(), false)
116 );
117 }
118
119 /**
120 * Test findPage: tagcloud page output.
121 * Invalid: page shouldn't be return.
122 *
123 * @return void
124 */
125 public function testFindPageTagcloudInvalid()
126 {
127 $this->assertNotEquals(
128 Router::$PAGE_TAGCLOUD,
129 Router::findPage('do=other', array(), false)
130 );
131 }
132
133 /**
134 * Test findPage: linklist page output.
135 * Valid: page should be return.
136 *
137 * @return void
138 */
139 public function testFindPageLinklistValid()
140 {
141 $this->assertEquals(
142 Router::$PAGE_LINKLIST,
143 Router::findPage('', array(), true)
144 );
145
146 $this->assertEquals(
147 Router::$PAGE_LINKLIST,
148 Router::findPage('whatever', array(), true)
149 );
150
151 $this->assertEquals(
152 Router::$PAGE_LINKLIST,
153 Router::findPage('whatever', array(), false)
154 );
155
156 $this->assertEquals(
157 Router::$PAGE_LINKLIST,
158 Router::findPage('do=tools', array(), false)
159 );
160 }
161
162 /**
163 * Test findPage: tools page output.
164 * Valid: page should be return.
165 *
166 * @return void
167 */
168 public function testFindPageToolsValid()
169 {
170 $this->assertEquals(
171 Router::$PAGE_TOOLS,
172 Router::findPage('do=tools', array(), true)
173 );
174
175 $this->assertEquals(
176 Router::$PAGE_TOOLS,
177 Router::findPage('do=tools&stuff', array(), true)
178 );
179 }
180
181 /**
182 * Test findPage: tools page output.
183 * Invalid: page shouldn't be return.
184 *
185 * @return void
186 */
187 public function testFindPageToolsInvalid()
188 {
189 $this->assertNotEquals(
190 Router::$PAGE_TOOLS,
191 Router::findPage('do=tools', array(), 1)
192 );
193
194 $this->assertNotEquals(
195 Router::$PAGE_TOOLS,
196 Router::findPage('do=tools', array(), false)
197 );
198
199 $this->assertNotEquals(
200 Router::$PAGE_TOOLS,
201 Router::findPage('do=other', array(), true)
202 );
203 }
204
205 /**
206 * Test findPage: changepasswd page output.
207 * Valid: page should be return.
208 *
209 * @return void
210 */
211 public function testFindPageChangepasswdValid()
212 {
213 $this->assertEquals(
214 Router::$PAGE_CHANGEPASSWORD,
215 Router::findPage('do=changepasswd', array(), true)
216 );
217 $this->assertEquals(
218 Router::$PAGE_CHANGEPASSWORD,
219 Router::findPage('do=changepasswd&stuff', array(), true)
220 );
221
222 }
223
224 /**
225 * Test findPage: changepasswd page output.
226 * Invalid: page shouldn't be return.
227 *
228 * @return void
229 */
230 public function testFindPageChangepasswdInvalid()
231 {
232 $this->assertNotEquals(
233 Router::$PAGE_CHANGEPASSWORD,
234 Router::findPage('do=changepasswd', array(), 1)
235 );
236
237 $this->assertNotEquals(
238 Router::$PAGE_CHANGEPASSWORD,
239 Router::findPage('do=changepasswd', array(), false)
240 );
241
242 $this->assertNotEquals(
243 Router::$PAGE_CHANGEPASSWORD,
244 Router::findPage('do=other', array(), true)
245 );
246 }
247 /**
248 * Test findPage: configure page output.
249 * Valid: page should be return.
250 *
251 * @return void
252 */
253 public function testFindPageConfigureValid()
254 {
255 $this->assertEquals(
256 Router::$PAGE_CONFIGURE,
257 Router::findPage('do=configure', array(), true)
258 );
259
260 $this->assertEquals(
261 Router::$PAGE_CONFIGURE,
262 Router::findPage('do=configure&stuff', array(), true)
263 );
264 }
265
266 /**
267 * Test findPage: configure page output.
268 * Invalid: page shouldn't be return.
269 *
270 * @return void
271 */
272 public function testFindPageConfigureInvalid()
273 {
274 $this->assertNotEquals(
275 Router::$PAGE_CONFIGURE,
276 Router::findPage('do=configure', array(), 1)
277 );
278
279 $this->assertNotEquals(
280 Router::$PAGE_CONFIGURE,
281 Router::findPage('do=configure', array(), false)
282 );
283
284 $this->assertNotEquals(
285 Router::$PAGE_CONFIGURE,
286 Router::findPage('do=other', array(), true)
287 );
288 }
289
290 /**
291 * Test findPage: changetag page output.
292 * Valid: page should be return.
293 *
294 * @return void
295 */
296 public function testFindPageChangetagValid()
297 {
298 $this->assertEquals(
299 Router::$PAGE_CHANGETAG,
300 Router::findPage('do=changetag', array(), true)
301 );
302
303 $this->assertEquals(
304 Router::$PAGE_CHANGETAG,
305 Router::findPage('do=changetag&stuff', array(), true)
306 );
307 }
308
309 /**
310 * Test findPage: changetag page output.
311 * Invalid: page shouldn't be return.
312 *
313 * @return void
314 */
315 public function testFindPageChangetagInvalid()
316 {
317 $this->assertNotEquals(
318 Router::$PAGE_CHANGETAG,
319 Router::findPage('do=changetag', array(), 1)
320 );
321
322 $this->assertNotEquals(
323 Router::$PAGE_CHANGETAG,
324 Router::findPage('do=changetag', array(), false)
325 );
326
327 $this->assertNotEquals(
328 Router::$PAGE_CHANGETAG,
329 Router::findPage('do=other', array(), true)
330 );
331 }
332
333 /**
334 * Test findPage: addlink page output.
335 * Valid: page should be return.
336 *
337 * @return void
338 */
339 public function testFindPageAddlinkValid()
340 {
341 $this->assertEquals(
342 Router::$PAGE_ADDLINK,
343 Router::findPage('do=addlink', array(), true)
344 );
345
346 $this->assertEquals(
347 Router::$PAGE_ADDLINK,
348 Router::findPage('do=addlink&stuff', array(), true)
349 );
350 }
351
352 /**
353 * Test findPage: addlink page output.
354 * Invalid: page shouldn't be return.
355 *
356 * @return void
357 */
358 public function testFindPageAddlinkInvalid()
359 {
360 $this->assertNotEquals(
361 Router::$PAGE_ADDLINK,
362 Router::findPage('do=addlink', array(), 1)
363 );
364
365 $this->assertNotEquals(
366 Router::$PAGE_ADDLINK,
367 Router::findPage('do=addlink', array(), false)
368 );
369
370 $this->assertNotEquals(
371 Router::$PAGE_ADDLINK,
372 Router::findPage('do=other', array(), true)
373 );
374 }
375
376 /**
377 * Test findPage: export page output.
378 * Valid: page should be return.
379 *
380 * @return void
381 */
382 public function testFindPageExportValid()
383 {
384 $this->assertEquals(
385 Router::$PAGE_EXPORT,
386 Router::findPage('do=export', array(), true)
387 );
388
389 $this->assertEquals(
390 Router::$PAGE_EXPORT,
391 Router::findPage('do=export&stuff', array(), true)
392 );
393 }
394
395 /**
396 * Test findPage: export page output.
397 * Invalid: page shouldn't be return.
398 *
399 * @return void
400 */
401 public function testFindPageExportInvalid()
402 {
403 $this->assertNotEquals(
404 Router::$PAGE_EXPORT,
405 Router::findPage('do=export', array(), 1)
406 );
407
408 $this->assertNotEquals(
409 Router::$PAGE_EXPORT,
410 Router::findPage('do=export', array(), false)
411 );
412
413 $this->assertNotEquals(
414 Router::$PAGE_EXPORT,
415 Router::findPage('do=other', array(), true)
416 );
417 }
418
419 /**
420 * Test findPage: import page output.
421 * Valid: page should be return.
422 *
423 * @return void
424 */
425 public function testFindPageImportValid()
426 {
427 $this->assertEquals(
428 Router::$PAGE_IMPORT,
429 Router::findPage('do=import', array(), true)
430 );
431
432 $this->assertEquals(
433 Router::$PAGE_IMPORT,
434 Router::findPage('do=import&stuff', array(), true)
435 );
436 }
437
438 /**
439 * Test findPage: import page output.
440 * Invalid: page shouldn't be return.
441 *
442 * @return void
443 */
444 public function testFindPageImportInvalid()
445 {
446 $this->assertNotEquals(
447 Router::$PAGE_IMPORT,
448 Router::findPage('do=import', array(), 1)
449 );
450
451 $this->assertNotEquals(
452 Router::$PAGE_IMPORT,
453 Router::findPage('do=import', array(), false)
454 );
455
456 $this->assertNotEquals(
457 Router::$PAGE_IMPORT,
458 Router::findPage('do=other', array(), true)
459 );
460 }
461
462 /**
463 * Test findPage: editlink page output.
464 * Valid: page should be return.
465 *
466 * @return void
467 */
468 public function testFindPageEditlinkValid()
469 {
470 $this->assertEquals(
471 Router::$PAGE_EDITLINK,
472 Router::findPage('whatever', array('edit_link' => 1), true)
473 );
474
475 $this->assertEquals(
476 Router::$PAGE_EDITLINK,
477 Router::findPage('', array('edit_link' => 1), true)
478 );
479
480
481 $this->assertEquals(
482 Router::$PAGE_EDITLINK,
483 Router::findPage('whatever', array('post' => 1), true)
484 );
485
486 $this->assertEquals(
487 Router::$PAGE_EDITLINK,
488 Router::findPage('whatever', array('post' => 1, 'edit_link' => 1), true)
489 );
490 }
491
492 /**
493 * Test findPage: editlink page output.
494 * Invalid: page shouldn't be return.
495 *
496 * @return void
497 */
498 public function testFindPageEditlinkInvalid()
499 {
500 $this->assertNotEquals(
501 Router::$PAGE_EDITLINK,
502 Router::findPage('whatever', array('edit_link' => 1), false)
503 );
504
505 $this->assertNotEquals(
506 Router::$PAGE_EDITLINK,
507 Router::findPage('whatever', array('edit_link' => 1), 1)
508 );
509
510 $this->assertNotEquals(
511 Router::$PAGE_EDITLINK,
512 Router::findPage('whatever', array(), true)
513 );
514 }
515}
diff --git a/tests/plugins/PlugQrcodeTest.php b/tests/plugins/PlugQrcodeTest.php
new file mode 100644
index 00000000..86dc7f29
--- /dev/null
+++ b/tests/plugins/PlugQrcodeTest.php
@@ -0,0 +1,67 @@
1<?php
2
3/**
4 * PlugQrcodeTest.php
5 */
6
7require_once 'plugins/qrcode/qrcode.php';
8require_once 'application/Router.php';
9
10/**
11 * Class PlugQrcodeTest
12 * Unit test for the QR-Code plugin
13 */
14class PlugQrcodeTest extends PHPUnit_Framework_TestCase
15{
16 /**
17 * Reset plugin path
18 */
19 function setUp() {
20 PluginManager::$PLUGINS_PATH = 'plugins';
21 }
22
23 /**
24 * Test render_linklist hook.
25 */
26 function testQrcodeLinklist()
27 {
28 $str = 'http://randomstr.com/test';
29 $data = array(
30 'title' => $str,
31 'links' => array(
32 array(
33 'url' => $str,
34 )
35 )
36 );
37
38 $data = hook_qrcode_render_linklist($data);
39 $link = $data['links'][0];
40 // data shouldn't be altered
41 $this->assertEquals($str, $data['title']);
42 $this->assertEquals($str, $link['url']);
43
44 // plugin data
45 $this->assertEquals(1, count($link['link_plugin']));
46 $this->assertNotFalse(strpos($link['link_plugin'][0], $str));
47 }
48
49 /**
50 * Test render_footer hook.
51 */
52 function testQrcodeFooter()
53 {
54 $str = 'stuff';
55 $data = array($str => $str);
56 $data['_PAGE_'] = Router::$PAGE_LINKLIST;
57
58 $data = hook_qrcode_render_footer($data);
59 $this->assertEquals($str, $data[$str]);
60 $this->assertEquals(1, count($data['js_files']));
61
62 $data = array($str => $str);
63 $data['_PAGE_'] = $str;
64 $this->assertEquals($str, $data[$str]);
65 $this->assertArrayNotHasKey('js_files', $data);
66 }
67}
diff --git a/tests/plugins/PluginAddlinkTest.php b/tests/plugins/PluginAddlinkTest.php
new file mode 100644
index 00000000..a2f25bec
--- /dev/null
+++ b/tests/plugins/PluginAddlinkTest.php
@@ -0,0 +1,100 @@
1<?php
2
3/**
4 * PluginPlayvideosTest.php
5 */
6
7require_once 'plugins/addlink_toolbar/addlink_toolbar.php';
8require_once 'application/Router.php';
9
10/**
11 * Class PluginAddlinkTest
12 * Unit test for the Addlink toolbar plugin
13 */
14class PluginAddlinkTest extends PHPUnit_Framework_TestCase
15{
16 /**
17 * Reset plugin path.
18 */
19 function setUp()
20 {
21 PluginManager::$PLUGINS_PATH = 'plugins';
22 }
23
24 /**
25 * Test render_header hook while logged in.
26 */
27 function testAddlinkHeaderLoggedIn()
28 {
29 $str = 'stuff';
30 $data = array($str => $str);
31 $data['_PAGE_'] = Router::$PAGE_LINKLIST;
32 $data['_LOGGEDIN_'] = true;
33
34 $data = hook_addlink_toolbar_render_header($data);
35 $this->assertEquals($str, $data[$str]);
36 $this->assertEquals(1, count($data['fields_toolbar']));
37
38 $data = array($str => $str);
39 $data['_PAGE_'] = $str;
40 $data['_LOGGEDIN_'] = true;
41 $data = hook_addlink_toolbar_render_header($data);
42 $this->assertEquals($str, $data[$str]);
43 $this->assertArrayNotHasKey('fields_toolbar', $data);
44 }
45
46 /**
47 * Test render_header hook while logged out.
48 */
49 function testAddlinkHeaderLoggedOut()
50 {
51 $str = 'stuff';
52 $data = array($str => $str);
53 $data['_PAGE_'] = Router::$PAGE_LINKLIST;
54 $data['_LOGGEDIN_'] = false;
55
56 $data = hook_addlink_toolbar_render_header($data);
57 $this->assertEquals($str, $data[$str]);
58 $this->assertArrayNotHasKey('fields_toolbar', $data);
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}
diff --git a/tests/plugins/PluginArchiveorgTest.php b/tests/plugins/PluginArchiveorgTest.php
new file mode 100644
index 00000000..dbc52bc8
--- /dev/null
+++ b/tests/plugins/PluginArchiveorgTest.php
@@ -0,0 +1,48 @@
1<?php
2
3/**
4 * PluginArchiveorgTest.php
5 */
6
7require_once 'plugins/archiveorg/archiveorg.php';
8
9/**
10 * Class PlugQrcodeTest
11 * Unit test for the QR-Code plugin
12 */
13class PluginArchiveorgTest 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 render_linklist hook.
25 */
26 function testArchiveorgLinklist()
27 {
28 $str = 'http://randomstr.com/test';
29 $data = array(
30 'title' => $str,
31 'links' => array(
32 array(
33 'url' => $str,
34 )
35 )
36 );
37
38 $data = hook_archiveorg_render_linklist($data);
39 $link = $data['links'][0];
40 // data shouldn't be altered
41 $this->assertEquals($str, $data['title']);
42 $this->assertEquals($str, $link['url']);
43
44 // plugin data
45 $this->assertEquals(1, count($link['link_plugin']));
46 $this->assertNotFalse(strpos($link['link_plugin'][0], $str));
47 }
48}
diff --git a/tests/plugins/PluginPlayvideosTest.php b/tests/plugins/PluginPlayvideosTest.php
new file mode 100644
index 00000000..be1ef774
--- /dev/null
+++ b/tests/plugins/PluginPlayvideosTest.php
@@ -0,0 +1,61 @@
1<?php
2
3/**
4 * PluginPlayvideosTest.php
5 */
6
7require_once 'plugins/playvideos/playvideos.php';
8require_once 'application/Router.php';
9
10/**
11 * Class PluginPlayvideosTest
12 * Unit test for the PlayVideos plugin
13 */
14class PluginPlayvideosTest extends PHPUnit_Framework_TestCase
15{
16 /**
17 * Reset plugin path
18 */
19 function setUp()
20 {
21 PluginManager::$PLUGINS_PATH = 'plugins';
22 }
23
24 /**
25 * Test render_linklist hook.
26 */
27 function testPlayvideosHeader()
28 {
29 $str = 'stuff';
30 $data = array($str => $str);
31 $data['_PAGE_'] = Router::$PAGE_LINKLIST;
32
33 $data = hook_playvideos_render_header($data);
34 $this->assertEquals($str, $data[$str]);
35 $this->assertEquals(1, count($data['buttons_toolbar']));
36
37 $data = array($str => $str);
38 $data['_PAGE_'] = $str;
39 $this->assertEquals($str, $data[$str]);
40 $this->assertArrayNotHasKey('buttons_toolbar', $data);
41 }
42
43 /**
44 * Test render_footer hook.
45 */
46 function testPlayvideosFooter()
47 {
48 $str = 'stuff';
49 $data = array($str => $str);
50 $data['_PAGE_'] = Router::$PAGE_LINKLIST;
51
52 $data = hook_playvideos_render_footer($data);
53 $this->assertEquals($str, $data[$str]);
54 $this->assertEquals(2, count($data['js_files']));
55
56 $data = array($str => $str);
57 $data['_PAGE_'] = $str;
58 $this->assertEquals($str, $data[$str]);
59 $this->assertArrayNotHasKey('js_files', $data);
60 }
61}
diff --git a/tests/plugins/PluginReadityourselfTest.php b/tests/plugins/PluginReadityourselfTest.php
new file mode 100644
index 00000000..8bf17bf1
--- /dev/null
+++ b/tests/plugins/PluginReadityourselfTest.php
@@ -0,0 +1,75 @@
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 render_linklist hook.
25 */
26 function testReadityourselfLinklist()
27 {
28 $GLOBALS['plugins']['READITYOUSELF_URL'] = 'value';
29 $str = 'http://randomstr.com/test';
30 $data = array(
31 'title' => $str,
32 'links' => array(
33 array(
34 'url' => $str,
35 )
36 )
37 );
38
39 $data = hook_readityourself_render_linklist($data);
40 $link = $data['links'][0];
41 // data shouldn't be altered
42 $this->assertEquals($str, $data['title']);
43 $this->assertEquals($str, $link['url']);
44
45 // plugin data
46 $this->assertEquals(1, count($link['link_plugin']));
47 $this->assertNotFalse(strpos($link['link_plugin'][0], $str));
48 }
49
50 /**
51 * Test without config: nothing should happened.
52 */
53 function testReadityourselfLinklistWithoutConfig()
54 {
55 unset($GLOBALS['plugins']['READITYOUSELF_URL']);
56 $str = 'http://randomstr.com/test';
57 $data = array(
58 'title' => $str,
59 'links' => array(
60 array(
61 'url' => $str,
62 )
63 )
64 );
65
66 $data = hook_readityourself_render_linklist($data);
67 $link = $data['links'][0];
68 // data shouldn't be altered
69 $this->assertEquals($str, $data['title']);
70 $this->assertEquals($str, $link['url']);
71
72 // plugin data
73 $this->assertArrayNotHasKey('link_plugin', $link);
74 }
75}
diff --git a/tests/plugins/PluginWallabagTest.php b/tests/plugins/PluginWallabagTest.php
new file mode 100644
index 00000000..7cc83f4f
--- /dev/null
+++ b/tests/plugins/PluginWallabagTest.php
@@ -0,0 +1,49 @@
1<?php
2
3/**
4 * PluginWallabagTest.php.php
5 */
6
7require_once 'plugins/wallabag/wallabag.php';
8
9/**
10 * Class PluginWallabagTest
11 * Unit test for the Wallabag plugin
12 */
13class PluginWallabagTest 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 render_linklist hook.
25 */
26 function testWallabagLinklist()
27 {
28 $GLOBALS['plugins']['WALLABAG_URL'] = 'value';
29 $str = 'http://randomstr.com/test';
30 $data = array(
31 'title' => $str,
32 'links' => array(
33 array(
34 'url' => $str,
35 )
36 )
37 );
38
39 $data = hook_wallabag_render_linklist($data);
40 $link = $data['links'][0];
41 // data shouldn't be altered
42 $this->assertEquals($str, $data['title']);
43 $this->assertEquals($str, $link['url']);
44
45 // plugin data
46 $this->assertEquals(1, count($link['link_plugin']));
47 $this->assertNotFalse(strpos($link['link_plugin'][0], $str));
48 }
49}
diff --git a/tests/plugins/test/test.php b/tests/plugins/test/test.php
new file mode 100644
index 00000000..3d750c90
--- /dev/null
+++ b/tests/plugins/test/test.php
@@ -0,0 +1,21 @@
1<?php
2
3/**
4 * Hook for test.
5 *
6 * @param array $data - data passed to plugin.
7 *
8 * @return mixed altered data.
9 */
10function hook_test_random($data)
11{
12 if (isset($data['_PAGE_']) && $data['_PAGE_'] == 'test') {
13 $data[1] = 'page test';
14 } else if (isset($data['_LOGGEDIN_']) && $data['_LOGGEDIN_'] === true) {
15 $data[1] = 'loggedin';
16 } else {
17 $data[1] = $data[0];
18 }
19
20 return $data;
21}