]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Add unit tests for the QRCode plugin 285/head
authorArthurHoaro <arthur@hoa.ro>
Sat, 7 Nov 2015 15:13:08 +0000 (16:13 +0100)
committerArthurHoaro <arthur@hoa.ro>
Sat, 7 Nov 2015 15:13:08 +0000 (16:13 +0100)
+ coding style

plugins/qrcode/qrcode.php
tests/plugins/PlugQrcodeTest.php [new file with mode: 0644]

index 5db409291c772e3ad811ed26eb9c199163e14b76..1080c9645d32bfebd76c7914d6d85f3747324f10 100644 (file)
@@ -1,11 +1,15 @@
 <?php
-
-// TODO: Can't be tested in localhost
+/**
+ * Plugin qrcode
+ * Add QRCode containing URL for each links.
+ * Display a QRCode icon in link list.
+ */
 
 /**
  * Add qrcode icon to link_plugin when rendering linklist.
  *
- * @param $data - linklist data.
+ * @param array $data - linklist data.
+ *
  * @return mixed - linklist data with qrcode plugin.
  */
 function hook_qrcode_render_linklist($data)
@@ -24,6 +28,7 @@ function hook_qrcode_render_linklist($data)
  * When linklist is displayed, include qrcode JS files.
  *
  * @param array $data - footer data.
+ *
  * @return mixed - footer data with qrcode JS files added.
  */
 function hook_qrcode_render_footer($data)
@@ -33,4 +38,4 @@ function hook_qrcode_render_footer($data)
     }
 
     return $data;
-}
\ No newline at end of file
+}
diff --git a/tests/plugins/PlugQrcodeTest.php b/tests/plugins/PlugQrcodeTest.php
new file mode 100644 (file)
index 0000000..86dc7f2
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+
+/**
+ * PlugQrcodeTest.php
+ */
+
+require_once 'plugins/qrcode/qrcode.php';
+require_once 'application/Router.php';
+
+/**
+ * Class PlugQrcodeTest
+ * Unit test for the QR-Code plugin
+ */
+class PlugQrcodeTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * Reset plugin path
+     */
+    function setUp() {
+        PluginManager::$PLUGINS_PATH = 'plugins';
+    }
+
+    /**
+     * Test render_linklist hook.
+     */
+    function testQrcodeLinklist()
+    {
+        $str = 'http://randomstr.com/test';
+        $data = array(
+            'title' => $str,
+            'links' => array(
+                array(
+                    'url' => $str,
+                )
+            )
+        );
+
+        $data = hook_qrcode_render_linklist($data);
+        $link = $data['links'][0];
+        // data shouldn't be altered
+        $this->assertEquals($str, $data['title']);
+        $this->assertEquals($str, $link['url']);
+
+        // plugin data
+        $this->assertEquals(1, count($link['link_plugin']));
+        $this->assertNotFalse(strpos($link['link_plugin'][0], $str));
+    }
+
+    /**
+     * Test render_footer hook.
+     */
+    function testQrcodeFooter()
+    {
+        $str = 'stuff';
+        $data = array($str => $str);
+        $data['_PAGE_'] = Router::$PAGE_LINKLIST;
+
+        $data = hook_qrcode_render_footer($data);
+        $this->assertEquals($str, $data[$str]);
+        $this->assertEquals(1, count($data['js_files']));
+
+        $data = array($str => $str);
+        $data['_PAGE_'] = $str;
+        $this->assertEquals($str, $data[$str]);
+        $this->assertArrayNotHasKey('js_files', $data);
+    }
+}