aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--plugins/readityourself/readityourself.php22
-rw-r--r--tests/plugins/PluginReadityourselfTest.php75
2 files changed, 90 insertions, 7 deletions
diff --git a/plugins/readityourself/readityourself.php b/plugins/readityourself/readityourself.php
index 7bad906d..ee7579c0 100644
--- a/plugins/readityourself/readityourself.php
+++ b/plugins/readityourself/readityourself.php
@@ -1,5 +1,9 @@
1<?php 1<?php
2 2
3/**
4 * Plugin readityourself
5 */
6
3// If we're talking about https://github.com/memiks/readityourself 7// If we're talking about https://github.com/memiks/readityourself
4// it seems kinda dead. 8// it seems kinda dead.
5// Not tested. 9// Not tested.
@@ -10,20 +14,24 @@ if (is_file(PluginManager::$PLUGINS_PATH . '/readityourself/config.php')) {
10} 14}
11 15
12if (!isset($GLOBALS['plugins']['READITYOUSELF_URL'])) { 16if (!isset($GLOBALS['plugins']['READITYOUSELF_URL'])) {
13 header('Content-Type: text/plain; charset=utf-8'); 17 $GLOBALS['plugins']['errors'][] = 'Wallabag plugin error: '.
14 echo 'ReadItYourself plugin error: '. PHP_EOL; 18 'Please define "$GLOBALS[\'plugins\'][\'WALLABAG_URL\']" '.
15 echo ' Please copy "plugins/readityourself/config.php.dist" to config.php and configure your readityourself URL.'. PHP_EOL; 19 'in "plugins/wallabag/config.php" or in your Shaarli config.php file.';
16 echo ' You can also define "$GLOBALS[\'plugins\'][\'READITYOUSELF_URL\']" in your global Shaarli config.php file.';
17 exit;
18} 20}
19 21
20/** 22/**
21 * Add readityourself icon to link_plugin when rendering linklist. 23 * Add readityourself icon to link_plugin when rendering linklist.
22 * 24 *
23 * @param $data - linklist data. 25 * @param mixed $data - linklist data.
26 *
24 * @return mixed - linklist data with readityourself plugin. 27 * @return mixed - linklist data with readityourself plugin.
25 */ 28 */
26function hook_readityourself_render_linklist($data) { 29function hook_readityourself_render_linklist($data)
30{
31 if (!isset($GLOBALS['plugins']['READITYOUSELF_URL'])) {
32 return $data;
33 }
34
27 $readityourself_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/readityourself/readityourself.html'); 35 $readityourself_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/readityourself/readityourself.html');
28 36
29 foreach ($data['links'] as &$value) { 37 foreach ($data['links'] as &$value) {
diff --git a/tests/plugins/PluginReadityourselfTest.php b/tests/plugins/PluginReadityourselfTest.php
new file mode 100644
index 00000000..8bf17bf1
--- /dev/null
+++ b/tests/plugins/PluginReadityourselfTest.php
@@ -0,0 +1,75 @@
1<?php
2
3/**
4 * PluginReadityourselfTest.php.php
5 */
6
7require_once 'plugins/readityourself/readityourself.php';
8
9/**
10 * Class PluginWallabagTest
11 * Unit test for the Wallabag plugin
12 */
13class PluginReadityourselfTest extends PHPUnit_Framework_TestCase
14{
15 /**
16 * Reset plugin path
17 */
18 function setUp()
19 {
20 PluginManager::$PLUGINS_PATH = 'plugins';
21 }
22
23 /**
24 * Test render_linklist hook.
25 */
26 function testReadityourselfLinklist()
27 {
28 $GLOBALS['plugins']['READITYOUSELF_URL'] = 'value';
29 $str = 'http://randomstr.com/test';
30 $data = array(
31 'title' => $str,
32 'links' => array(
33 array(
34 'url' => $str,
35 )
36 )
37 );
38
39 $data = hook_readityourself_render_linklist($data);
40 $link = $data['links'][0];
41 // data shouldn't be altered
42 $this->assertEquals($str, $data['title']);
43 $this->assertEquals($str, $link['url']);
44
45 // plugin data
46 $this->assertEquals(1, count($link['link_plugin']));
47 $this->assertNotFalse(strpos($link['link_plugin'][0], $str));
48 }
49
50 /**
51 * Test without config: nothing should happened.
52 */
53 function testReadityourselfLinklistWithoutConfig()
54 {
55 unset($GLOBALS['plugins']['READITYOUSELF_URL']);
56 $str = 'http://randomstr.com/test';
57 $data = array(
58 'title' => $str,
59 'links' => array(
60 array(
61 'url' => $str,
62 )
63 )
64 );
65
66 $data = hook_readityourself_render_linklist($data);
67 $link = $data['links'][0];
68 // data shouldn't be altered
69 $this->assertEquals($str, $data['title']);
70 $this->assertEquals($str, $link['url']);
71
72 // plugin data
73 $this->assertArrayNotHasKey('link_plugin', $link);
74 }
75}