From 1b2b44f4bd4457a3dc7b559d3e86cd38644ffe6f Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 15 Oct 2015 12:25:38 +0200 Subject: [PATCH 1/2] PLUGIN: addlink_toolbar Add a field in linklist page to paste a new link. Displayed in fields toolbar. --- plugins/addlink_toolbar/addlink_toolbar.css | 4 +++ plugins/addlink_toolbar/addlink_toolbar.html | 6 ++++ plugins/addlink_toolbar/addlink_toolbar.php | 29 ++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100755 plugins/addlink_toolbar/addlink_toolbar.css create mode 100755 plugins/addlink_toolbar/addlink_toolbar.html create mode 100755 plugins/addlink_toolbar/addlink_toolbar.php diff --git a/plugins/addlink_toolbar/addlink_toolbar.css b/plugins/addlink_toolbar/addlink_toolbar.css new file mode 100755 index 00000000..b6a612f0 --- /dev/null +++ b/plugins/addlink_toolbar/addlink_toolbar.css @@ -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 index 00000000..f38c41a0 --- /dev/null +++ b/plugins/addlink_toolbar/addlink_toolbar.html @@ -0,0 +1,6 @@ + \ 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 index 00000000..826a0922 --- /dev/null +++ b/plugins/addlink_toolbar/addlink_toolbar.php @@ -0,0 +1,29 @@ + Date: Sun, 8 Nov 2015 12:40:14 +0100 Subject: [PATCH 2/2] unit test for addlink_toolbar + coding style --- plugins/addlink_toolbar/addlink_toolbar.php | 13 ++- tests/plugins/PluginAddlinkTest.php | 100 ++++++++++++++++++++ 2 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 tests/plugins/PluginAddlinkTest.php diff --git a/plugins/addlink_toolbar/addlink_toolbar.php b/plugins/addlink_toolbar/addlink_toolbar.php index 826a0922..ba3849cf 100755 --- a/plugins/addlink_toolbar/addlink_toolbar.php +++ b/plugins/addlink_toolbar/addlink_toolbar.php @@ -1,12 +1,19 @@ $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); + } +}