]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
unit tests for readityourself plugin + remove hard error 280/head
authorArthurHoaro <arthur@hoa.ro>
Sun, 8 Nov 2015 11:16:55 +0000 (12:16 +0100)
committerArthurHoaro <arthur@hoa.ro>
Sun, 8 Nov 2015 11:42:29 +0000 (12:42 +0100)
plugins/readityourself/readityourself.php
tests/plugins/PluginReadityourselfTest.php [new file with mode: 0644]

index 7bad906d6aac1b47d81e527d8194c09f7780dbe2..ee7579c0810e7fc54b775eb3dc866827f7a93cac 100644 (file)
@@ -1,5 +1,9 @@
 <?php
 
+/**
+ * Plugin readityourself
+ */
+
 // If we're talking about https://github.com/memiks/readityourself
 // it seems kinda dead.
 // Not tested.
@@ -10,20 +14,24 @@ if (is_file(PluginManager::$PLUGINS_PATH . '/readityourself/config.php')) {
 }
 
 if (!isset($GLOBALS['plugins']['READITYOUSELF_URL'])) {
-    header('Content-Type: text/plain; charset=utf-8');
-    echo 'ReadItYourself plugin error: '. PHP_EOL;
-    echo '  Please copy "plugins/readityourself/config.php.dist" to config.php and configure your readityourself URL.'. PHP_EOL;
-    echo '  You can also define "$GLOBALS[\'plugins\'][\'READITYOUSELF_URL\']" in your global Shaarli config.php file.';
-    exit;
+    $GLOBALS['plugins']['errors'][] = 'Wallabag plugin error: '.
+        'Please define "$GLOBALS[\'plugins\'][\'WALLABAG_URL\']" '.
+        'in "plugins/wallabag/config.php" or in your Shaarli config.php file.';
 }
 
 /**
  * Add readityourself icon to link_plugin when rendering linklist.
  *
- * @param $data - linklist data.
+ * @param mixed $data - linklist data.
+ *
  * @return mixed - linklist data with readityourself plugin.
  */
-function hook_readityourself_render_linklist($data) {
+function hook_readityourself_render_linklist($data)
+{
+    if (!isset($GLOBALS['plugins']['READITYOUSELF_URL'])) {
+        return $data;
+    }
+
     $readityourself_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/readityourself/readityourself.html');
 
     foreach ($data['links'] as &$value) {
diff --git a/tests/plugins/PluginReadityourselfTest.php b/tests/plugins/PluginReadityourselfTest.php
new file mode 100644 (file)
index 0000000..8bf17bf
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+
+/**
+ * PluginReadityourselfTest.php.php
+ */
+
+require_once 'plugins/readityourself/readityourself.php';
+
+/**
+ * Class PluginWallabagTest
+ * Unit test for the Wallabag plugin
+ */
+class PluginReadityourselfTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * Reset plugin path
+     */
+    function setUp()
+    {
+        PluginManager::$PLUGINS_PATH = 'plugins';
+    }
+
+    /**
+     * Test render_linklist hook.
+     */
+    function testReadityourselfLinklist()
+    {
+        $GLOBALS['plugins']['READITYOUSELF_URL'] = 'value';
+        $str = 'http://randomstr.com/test';
+        $data = array(
+            'title' => $str,
+            'links' => array(
+                array(
+                    'url' => $str,
+                )
+            )
+        );
+
+        $data = hook_readityourself_render_linklist($data);
+        $link = $data['links'][0];
+        // data shouldn't be altered
+        $this->assertEquals($str, $data['title']);
+        $this->assertEquals($str, $link['url']);
+
+        // plugin data
+        $this->assertEquals(1, count($link['link_plugin']));
+        $this->assertNotFalse(strpos($link['link_plugin'][0], $str));
+    }
+
+    /**
+     * Test without config: nothing should happened.
+     */
+    function testReadityourselfLinklistWithoutConfig()
+    {
+        unset($GLOBALS['plugins']['READITYOUSELF_URL']);
+        $str = 'http://randomstr.com/test';
+        $data = array(
+            'title' => $str,
+            'links' => array(
+                array(
+                    'url' => $str,
+                )
+            )
+        );
+
+        $data = hook_readityourself_render_linklist($data);
+        $link = $data['links'][0];
+        // data shouldn't be altered
+        $this->assertEquals($str, $data['title']);
+        $this->assertEquals($str, $link['url']);
+
+        // plugin data
+        $this->assertArrayNotHasKey('link_plugin', $link);
+    }
+}