aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2015-07-15 11:42:15 +0200
committerArthurHoaro <arthur@hoa.ro>2015-11-07 15:27:17 +0100
commit6fc14d530369740d27d6bd641369d4f5f5f04080 (patch)
tree2da553378e8f0ff367dcb677d6f519d1fb3e803c /tests
parent38bedfbbcdd2a40e9f04f5753e0fd6f4fd513c21 (diff)
downloadShaarli-6fc14d530369740d27d6bd641369d4f5f5f04080.tar.gz
Shaarli-6fc14d530369740d27d6bd641369d4f5f5f04080.tar.zst
Shaarli-6fc14d530369740d27d6bd641369d4f5f5f04080.zip
Plugin system - CORE
see shaarli/Shaarli#275
Diffstat (limited to 'tests')
-rwxr-xr-xtests/PluginManagerTest.php66
-rwxr-xr-xtests/RouterTest.php515
-rwxr-xr-xtests/plugins/test/test.php21
3 files changed, 602 insertions, 0 deletions
diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php
new file mode 100755
index 00000000..749ce2b5
--- /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 $_PLUGIN_PATH
17 */
18 private static $_PLUGIN_PATH = 'tests/plugins';
19
20 /**
21 * Test plugin.
22 * @var string $_PLUGIN_NAME
23 */
24 private static $_PLUGIN_NAME = '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::$_PLUGIN_PATH;
36 $pluginManager->load(array(self::$_PLUGIN_NAME));
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 100755
index 00000000..8838bc8d
--- /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} \ No newline at end of file
diff --git a/tests/plugins/test/test.php b/tests/plugins/test/test.php
new file mode 100755
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}