]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #279 from ArthurHoaro/plugin-addlink_toolbar
authorArthur <arthur@hoa.ro>
Sun, 8 Nov 2015 11:45:07 +0000 (12:45 +0100)
committerArthur <arthur@hoa.ro>
Sun, 8 Nov 2015 11:45:07 +0000 (12:45 +0100)
PLUGIN: addlink_toolbar

plugins/addlink_toolbar/addlink_toolbar.css [new file with mode: 0755]
plugins/addlink_toolbar/addlink_toolbar.html [new file with mode: 0755]
plugins/addlink_toolbar/addlink_toolbar.php [new file with mode: 0755]
tests/plugins/PluginAddlinkTest.php [new file with mode: 0644]

diff --git a/plugins/addlink_toolbar/addlink_toolbar.css b/plugins/addlink_toolbar/addlink_toolbar.css
new file mode 100755 (executable)
index 0000000..b6a612f
--- /dev/null
@@ -0,0 +1,4 @@
+#addlink_toolbar {
+    display: inline;
+    margin: 0 0 0 25px;
+}
\ No newline at end of file
diff --git a/plugins/addlink_toolbar/addlink_toolbar.html b/plugins/addlink_toolbar/addlink_toolbar.html
new file mode 100755 (executable)
index 0000000..f38c41a
--- /dev/null
@@ -0,0 +1,6 @@
+<div id="addlink_toolbar">
+    <form method="GET" action="" name="addform" class="addform">
+        <input type="text" name="post" placeholder="URI">
+        <input type="submit" value="Add link" class="bigbutton">
+    </form>
+</div>
\ No newline at end of file
diff --git a/plugins/addlink_toolbar/addlink_toolbar.php b/plugins/addlink_toolbar/addlink_toolbar.php
new file mode 100755 (executable)
index 0000000..ba3849c
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * Plugin addlink_toolbar.
+ * Adds the addlink input on the linklist page.
+ */
+
+/**
+ * When linklist is displayed, add play videos to header's toolbar.
+ *
+ * @param array $data - header data.
+ *
+ * @return mixed - header data with addlink toolbar item.
+ */
+function hook_addlink_toolbar_render_header($data)
+{
+    if ($data['_PAGE_'] == Router::$PAGE_LINKLIST && $data['_LOGGEDIN_'] === true) {
+        $data['fields_toolbar'][] = file_get_contents(PluginManager::$PLUGINS_PATH . '/addlink_toolbar/addlink_toolbar.html');
+    }
+
+    return $data;
+}
+
+/**
+ * When link list is displayed, include markdown CSS.
+ *
+ * @param array $data - includes data.
+ *
+ * @return mixed - includes data with markdown CSS file added.
+ */
+function hook_addlink_toolbar_render_includes($data)
+{
+    if ($data['_PAGE_'] == Router::$PAGE_LINKLIST && $data['_LOGGEDIN_'] === true) {
+        $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/addlink_toolbar/addlink_toolbar.css';
+    }
+
+    return $data;
+}
\ No newline at end of file
diff --git a/tests/plugins/PluginAddlinkTest.php b/tests/plugins/PluginAddlinkTest.php
new file mode 100644 (file)
index 0000000..a2f25be
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+
+/**
+ * PluginPlayvideosTest.php
+ */
+
+require_once 'plugins/addlink_toolbar/addlink_toolbar.php';
+require_once 'application/Router.php';
+
+/**
+ * Class PluginAddlinkTest
+ * Unit test for the Addlink toolbar plugin
+ */
+class PluginAddlinkTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * Reset plugin path.
+     */
+    function setUp()
+    {
+        PluginManager::$PLUGINS_PATH = 'plugins';
+    }
+
+    /**
+     * Test render_header hook while logged in.
+     */
+    function testAddlinkHeaderLoggedIn()
+    {
+        $str = 'stuff';
+        $data = array($str => $str);
+        $data['_PAGE_'] = Router::$PAGE_LINKLIST;
+        $data['_LOGGEDIN_'] = true;
+
+        $data = hook_addlink_toolbar_render_header($data);
+        $this->assertEquals($str, $data[$str]);
+        $this->assertEquals(1, count($data['fields_toolbar']));
+
+        $data = array($str => $str);
+        $data['_PAGE_'] = $str;
+        $data['_LOGGEDIN_'] = true;
+        $data = hook_addlink_toolbar_render_header($data);
+        $this->assertEquals($str, $data[$str]);
+        $this->assertArrayNotHasKey('fields_toolbar', $data);
+    }
+
+    /**
+     * Test render_header hook while logged out.
+     */
+    function testAddlinkHeaderLoggedOut()
+    {
+        $str = 'stuff';
+        $data = array($str => $str);
+        $data['_PAGE_'] = Router::$PAGE_LINKLIST;
+        $data['_LOGGEDIN_'] = false;
+
+        $data = hook_addlink_toolbar_render_header($data);
+        $this->assertEquals($str, $data[$str]);
+        $this->assertArrayNotHasKey('fields_toolbar', $data);
+    }
+
+    /**
+     * Test render_includes hook while logged in.
+     */
+    function testAddlinkIncludesLoggedIn()
+    {
+        $str = 'stuff';
+        $data = array($str => $str);
+        $data['_PAGE_'] = Router::$PAGE_LINKLIST;
+        $data['_LOGGEDIN_'] = true;
+
+        $data = hook_addlink_toolbar_render_includes($data);
+        $this->assertEquals($str, $data[$str]);
+        $this->assertEquals(1, count($data['css_files']));
+
+        $str = 'stuff';
+        $data = array($str => $str);
+        $data['_PAGE_'] = $str;
+        $data['_LOGGEDIN_'] = true;
+
+        $data = hook_addlink_toolbar_render_includes($data);
+        $this->assertEquals($str, $data[$str]);
+        $this->assertArrayNotHasKey('css_files', $data);
+    }
+
+    /**
+     * Test render_includes hook.
+     * Should not affect css files while logged out.
+     */
+    function testAddlinkIncludesLoggedOut()
+    {
+        $str = 'stuff';
+        $data = array($str => $str);
+        $data['_PAGE_'] = Router::$PAGE_LINKLIST;
+        $data['_LOGGEDIN_'] = false;
+
+        $data = hook_addlink_toolbar_render_includes($data);
+        $this->assertEquals($str, $data[$str]);
+        $this->assertArrayNotHasKey('css_files', $data);
+    }
+}