aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--plugins/qrcode/qrcode.php13
-rw-r--r--tests/plugins/PlugQrcodeTest.php67
2 files changed, 76 insertions, 4 deletions
diff --git a/plugins/qrcode/qrcode.php b/plugins/qrcode/qrcode.php
index 5db40929..1080c964 100644
--- a/plugins/qrcode/qrcode.php
+++ b/plugins/qrcode/qrcode.php
@@ -1,11 +1,15 @@
1<?php 1<?php
2 2/**
3// TODO: Can't be tested in localhost 3 * Plugin qrcode
4 * Add QRCode containing URL for each links.
5 * Display a QRCode icon in link list.
6 */
4 7
5/** 8/**
6 * Add qrcode icon to link_plugin when rendering linklist. 9 * Add qrcode icon to link_plugin when rendering linklist.
7 * 10 *
8 * @param $data - linklist data. 11 * @param array $data - linklist data.
12 *
9 * @return mixed - linklist data with qrcode plugin. 13 * @return mixed - linklist data with qrcode plugin.
10 */ 14 */
11function hook_qrcode_render_linklist($data) 15function hook_qrcode_render_linklist($data)
@@ -24,6 +28,7 @@ function hook_qrcode_render_linklist($data)
24 * When linklist is displayed, include qrcode JS files. 28 * When linklist is displayed, include qrcode JS files.
25 * 29 *
26 * @param array $data - footer data. 30 * @param array $data - footer data.
31 *
27 * @return mixed - footer data with qrcode JS files added. 32 * @return mixed - footer data with qrcode JS files added.
28 */ 33 */
29function hook_qrcode_render_footer($data) 34function hook_qrcode_render_footer($data)
@@ -33,4 +38,4 @@ function hook_qrcode_render_footer($data)
33 } 38 }
34 39
35 return $data; 40 return $data;
36} \ No newline at end of file 41}
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}