diff options
author | Arthur <arthur@hoa.ro> | 2015-11-08 12:45:07 +0100 |
---|---|---|
committer | Arthur <arthur@hoa.ro> | 2015-11-08 12:45:07 +0100 |
commit | 00c25040c523104e1b845fd71d1cd134a1a5e7ff (patch) | |
tree | a1b4f4cb5a5f7ec677acf2c8b495ae514cb8fe96 | |
parent | 245432e796a6e520ec830bd1d486420e115853d8 (diff) | |
parent | ff5bda8238b1914ac80c45ffb3fcb910c4b4568c (diff) | |
download | Shaarli-00c25040c523104e1b845fd71d1cd134a1a5e7ff.tar.gz Shaarli-00c25040c523104e1b845fd71d1cd134a1a5e7ff.tar.zst Shaarli-00c25040c523104e1b845fd71d1cd134a1a5e7ff.zip |
Merge pull request #279 from ArthurHoaro/plugin-addlink_toolbar
PLUGIN: addlink_toolbar
-rwxr-xr-x | plugins/addlink_toolbar/addlink_toolbar.css | 4 | ||||
-rwxr-xr-x | plugins/addlink_toolbar/addlink_toolbar.html | 6 | ||||
-rwxr-xr-x | plugins/addlink_toolbar/addlink_toolbar.php | 38 | ||||
-rw-r--r-- | tests/plugins/PluginAddlinkTest.php | 100 |
4 files changed, 148 insertions, 0 deletions
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 @@ | |||
1 | #addlink_toolbar { | ||
2 | display: inline; | ||
3 | margin: 0 0 0 25px; | ||
4 | } \ 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 @@ | |||
1 | <div id="addlink_toolbar"> | ||
2 | <form method="GET" action="" name="addform" class="addform"> | ||
3 | <input type="text" name="post" placeholder="URI"> | ||
4 | <input type="submit" value="Add link" class="bigbutton"> | ||
5 | </form> | ||
6 | </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 index 00000000..ba3849cf --- /dev/null +++ b/plugins/addlink_toolbar/addlink_toolbar.php | |||
@@ -0,0 +1,38 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Plugin addlink_toolbar. | ||
5 | * Adds the addlink input on the linklist page. | ||
6 | */ | ||
7 | |||
8 | /** | ||
9 | * When linklist is displayed, add play videos to header's toolbar. | ||
10 | * | ||
11 | * @param array $data - header data. | ||
12 | * | ||
13 | * @return mixed - header data with addlink toolbar item. | ||
14 | */ | ||
15 | function hook_addlink_toolbar_render_header($data) | ||
16 | { | ||
17 | if ($data['_PAGE_'] == Router::$PAGE_LINKLIST && $data['_LOGGEDIN_'] === true) { | ||
18 | $data['fields_toolbar'][] = file_get_contents(PluginManager::$PLUGINS_PATH . '/addlink_toolbar/addlink_toolbar.html'); | ||
19 | } | ||
20 | |||
21 | return $data; | ||
22 | } | ||
23 | |||
24 | /** | ||
25 | * When link list is displayed, include markdown CSS. | ||
26 | * | ||
27 | * @param array $data - includes data. | ||
28 | * | ||
29 | * @return mixed - includes data with markdown CSS file added. | ||
30 | */ | ||
31 | function hook_addlink_toolbar_render_includes($data) | ||
32 | { | ||
33 | if ($data['_PAGE_'] == Router::$PAGE_LINKLIST && $data['_LOGGEDIN_'] === true) { | ||
34 | $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/addlink_toolbar/addlink_toolbar.css'; | ||
35 | } | ||
36 | |||
37 | return $data; | ||
38 | } \ No newline at end of file | ||
diff --git a/tests/plugins/PluginAddlinkTest.php b/tests/plugins/PluginAddlinkTest.php new file mode 100644 index 00000000..a2f25bec --- /dev/null +++ b/tests/plugins/PluginAddlinkTest.php | |||
@@ -0,0 +1,100 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * PluginPlayvideosTest.php | ||
5 | */ | ||
6 | |||
7 | require_once 'plugins/addlink_toolbar/addlink_toolbar.php'; | ||
8 | require_once 'application/Router.php'; | ||
9 | |||
10 | /** | ||
11 | * Class PluginAddlinkTest | ||
12 | * Unit test for the Addlink toolbar plugin | ||
13 | */ | ||
14 | class PluginAddlinkTest extends PHPUnit_Framework_TestCase | ||
15 | { | ||
16 | /** | ||
17 | * Reset plugin path. | ||
18 | */ | ||
19 | function setUp() | ||
20 | { | ||
21 | PluginManager::$PLUGINS_PATH = 'plugins'; | ||
22 | } | ||
23 | |||
24 | /** | ||
25 | * Test render_header hook while logged in. | ||
26 | */ | ||
27 | function testAddlinkHeaderLoggedIn() | ||
28 | { | ||
29 | $str = 'stuff'; | ||
30 | $data = array($str => $str); | ||
31 | $data['_PAGE_'] = Router::$PAGE_LINKLIST; | ||
32 | $data['_LOGGEDIN_'] = true; | ||
33 | |||
34 | $data = hook_addlink_toolbar_render_header($data); | ||
35 | $this->assertEquals($str, $data[$str]); | ||
36 | $this->assertEquals(1, count($data['fields_toolbar'])); | ||
37 | |||
38 | $data = array($str => $str); | ||
39 | $data['_PAGE_'] = $str; | ||
40 | $data['_LOGGEDIN_'] = true; | ||
41 | $data = hook_addlink_toolbar_render_header($data); | ||
42 | $this->assertEquals($str, $data[$str]); | ||
43 | $this->assertArrayNotHasKey('fields_toolbar', $data); | ||
44 | } | ||
45 | |||
46 | /** | ||
47 | * Test render_header hook while logged out. | ||
48 | */ | ||
49 | function testAddlinkHeaderLoggedOut() | ||
50 | { | ||
51 | $str = 'stuff'; | ||
52 | $data = array($str => $str); | ||
53 | $data['_PAGE_'] = Router::$PAGE_LINKLIST; | ||
54 | $data['_LOGGEDIN_'] = false; | ||
55 | |||
56 | $data = hook_addlink_toolbar_render_header($data); | ||
57 | $this->assertEquals($str, $data[$str]); | ||
58 | $this->assertArrayNotHasKey('fields_toolbar', $data); | ||
59 | } | ||
60 | |||
61 | /** | ||
62 | * Test render_includes hook while logged in. | ||
63 | */ | ||
64 | function testAddlinkIncludesLoggedIn() | ||
65 | { | ||
66 | $str = 'stuff'; | ||
67 | $data = array($str => $str); | ||
68 | $data['_PAGE_'] = Router::$PAGE_LINKLIST; | ||
69 | $data['_LOGGEDIN_'] = true; | ||
70 | |||
71 | $data = hook_addlink_toolbar_render_includes($data); | ||
72 | $this->assertEquals($str, $data[$str]); | ||
73 | $this->assertEquals(1, count($data['css_files'])); | ||
74 | |||
75 | $str = 'stuff'; | ||
76 | $data = array($str => $str); | ||
77 | $data['_PAGE_'] = $str; | ||
78 | $data['_LOGGEDIN_'] = true; | ||
79 | |||
80 | $data = hook_addlink_toolbar_render_includes($data); | ||
81 | $this->assertEquals($str, $data[$str]); | ||
82 | $this->assertArrayNotHasKey('css_files', $data); | ||
83 | } | ||
84 | |||
85 | /** | ||
86 | * Test render_includes hook. | ||
87 | * Should not affect css files while logged out. | ||
88 | */ | ||
89 | function testAddlinkIncludesLoggedOut() | ||
90 | { | ||
91 | $str = 'stuff'; | ||
92 | $data = array($str => $str); | ||
93 | $data['_PAGE_'] = Router::$PAGE_LINKLIST; | ||
94 | $data['_LOGGEDIN_'] = false; | ||
95 | |||
96 | $data = hook_addlink_toolbar_render_includes($data); | ||
97 | $this->assertEquals($str, $data[$str]); | ||
98 | $this->assertArrayNotHasKey('css_files', $data); | ||
99 | } | ||
100 | } | ||