diff options
author | ArthurHoaro <arthur@hoa.ro> | 2015-11-08 12:00:06 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2015-11-08 12:44:29 +0100 |
commit | 1696f6aa07734c7502702cf810c9fdc93532ef56 (patch) | |
tree | 5b7e15538778d7824676a45d14afd436c98cd375 | |
parent | 263d1f649574083be4b8826a57688a85d48d4d15 (diff) | |
download | Shaarli-1696f6aa07734c7502702cf810c9fdc93532ef56.tar.gz Shaarli-1696f6aa07734c7502702cf810c9fdc93532ef56.tar.zst Shaarli-1696f6aa07734c7502702cf810c9fdc93532ef56.zip |
unit tests for the wallabag plugin
+ removed exit error if the config is not found
+ coding style
-rw-r--r-- | plugins/wallabag/wallabag.php | 22 | ||||
-rw-r--r-- | tests/plugins/PluginWallabagTest.php | 49 |
2 files changed, 64 insertions, 7 deletions
diff --git a/plugins/wallabag/wallabag.php b/plugins/wallabag/wallabag.php index db8151c9..024a3d2b 100644 --- a/plugins/wallabag/wallabag.php +++ b/plugins/wallabag/wallabag.php | |||
@@ -1,25 +1,33 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | /** | ||
4 | * Plugin Wallabag. | ||
5 | */ | ||
6 | |||
3 | // don't raise unnecessary warnings | 7 | // don't raise unnecessary warnings |
4 | if (is_file(PluginManager::$PLUGINS_PATH . '/wallabag/config.php')) { | 8 | if (is_file(PluginManager::$PLUGINS_PATH . '/wallabag/config.php')) { |
5 | include PluginManager::$PLUGINS_PATH . '/wallabag/config.php'; | 9 | include PluginManager::$PLUGINS_PATH . '/wallabag/config.php'; |
6 | } | 10 | } |
7 | 11 | ||
8 | if (!isset($GLOBALS['plugins']['WALLABAG_URL'])) { | 12 | if (!isset($GLOBALS['plugins']['WALLABAG_URL'])) { |
9 | header('Content-Type: text/plain; charset=utf-8'); | 13 | $GLOBALS['plugins']['errors'][] = 'Wallabag plugin error: '. |
10 | echo 'Wallabag plugin error: '. PHP_EOL; | 14 | 'Please define "$GLOBALS[\'plugins\'][\'WALLABAG_URL\']" '. |
11 | echo ' Please copy "plugins/wallabag/config.php.dist" to config.php and configure your Wallabag URL.'. PHP_EOL; | 15 | 'in "plugins/wallabag/config.php" or in your Shaarli config.php file.'; |
12 | echo ' You can also define "$GLOBALS[\'plugins\'][\'WALLABAG_URL\']" in your global Shaarli config.php file.'; | ||
13 | exit; | ||
14 | } | 16 | } |
15 | 17 | ||
16 | /** | 18 | /** |
17 | * Add wallabag icon to link_plugin when rendering linklist. | 19 | * Add wallabag icon to link_plugin when rendering linklist. |
18 | * | 20 | * |
19 | * @param $data - linklist data. | 21 | * @param mixed $data - linklist data. |
22 | * | ||
20 | * @return mixed - linklist data with wallabag plugin. | 23 | * @return mixed - linklist data with wallabag plugin. |
21 | */ | 24 | */ |
22 | function hook_wallabag_render_linklist($data) { | 25 | function hook_wallabag_render_linklist($data) |
26 | { | ||
27 | if (!isset($GLOBALS['plugins']['WALLABAG_URL'])) { | ||
28 | return $data; | ||
29 | } | ||
30 | |||
23 | $wallabag_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/wallabag/wallabag.html'); | 31 | $wallabag_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/wallabag/wallabag.html'); |
24 | 32 | ||
25 | foreach ($data['links'] as &$value) { | 33 | foreach ($data['links'] as &$value) { |
diff --git a/tests/plugins/PluginWallabagTest.php b/tests/plugins/PluginWallabagTest.php new file mode 100644 index 00000000..7cc83f4f --- /dev/null +++ b/tests/plugins/PluginWallabagTest.php | |||
@@ -0,0 +1,49 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * PluginWallabagTest.php.php | ||
5 | */ | ||
6 | |||
7 | require_once 'plugins/wallabag/wallabag.php'; | ||
8 | |||
9 | /** | ||
10 | * Class PluginWallabagTest | ||
11 | * Unit test for the Wallabag plugin | ||
12 | */ | ||
13 | class PluginWallabagTest 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 testWallabagLinklist() | ||
27 | { | ||
28 | $GLOBALS['plugins']['WALLABAG_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_wallabag_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 | } | ||