]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Archive.org plugin: do not propose archival of private notes 654/head
authorTeromene <teromene@teromene.fr>
Tue, 11 Oct 2016 15:37:42 +0000 (16:37 +0100)
committerTeromene <teromene@teromene.fr>
Thu, 13 Oct 2016 15:37:43 +0000 (16:37 +0100)
Fixes #637

plugins/archiveorg/archiveorg.php
tests/plugins/PluginArchiveorgTest.php

index 7d172584c45ee9d87aa6169d2cdc186bc82c9059..03d13d0efb2db403c0d2bef225f66546cee18ae3 100644 (file)
@@ -17,6 +17,9 @@ function hook_archiveorg_render_linklist($data)
     $archive_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/archiveorg/archiveorg.html');
 
     foreach ($data['links'] as &$value) {
+        if($value['private'] && preg_match('/^\?[a-zA-Z0-9-_@]{6}($|&|#)/', $value['real_url'])) {
+            continue;
+        }
         $archive = sprintf($archive_html, $value['url']);
         $value['link_plugin'][] = $archive;
     }
index dbc52bc89ad16a138b1ea746106fa67841d2dfb4..4daa4c9d63deb491ca702cdadfa893f56f4122b4 100644 (file)
@@ -7,8 +7,8 @@
 require_once 'plugins/archiveorg/archiveorg.php';
 
 /**
- * Class PlugQrcodeTest
- * Unit test for the QR-Code plugin
+ * Class PluginArchiveorgTest
+ * Unit test for the archiveorg plugin
  */
 class PluginArchiveorgTest extends PHPUnit_Framework_TestCase
 {
@@ -21,21 +21,25 @@ class PluginArchiveorgTest extends PHPUnit_Framework_TestCase
     }
 
     /**
-     * Test render_linklist hook.
+     * Test render_linklist hook on external links.
      */
-    function testArchiveorgLinklist()
+    function testArchiveorgLinklistOnExternalLinks()
     {
         $str = 'http://randomstr.com/test';
+
         $data = array(
             'title' => $str,
             'links' => array(
                 array(
                     'url' => $str,
+                    'private' => 0,
+                    'real_url' => $str
                 )
             )
         );
 
         $data = hook_archiveorg_render_linklist($data);
+
         $link = $data['links'][0];
         // data shouldn't be altered
         $this->assertEquals($str, $data['title']);
@@ -44,5 +48,95 @@ class PluginArchiveorgTest extends PHPUnit_Framework_TestCase
         // plugin data
         $this->assertEquals(1, count($link['link_plugin']));
         $this->assertNotFalse(strpos($link['link_plugin'][0], $str));
+
+    }
+
+    /**
+     * Test render_linklist hook on internal links.
+     */
+    function testArchiveorgLinklistOnInternalLinks()
+    {
+        $internalLink1 = 'http://shaarli.shaarli/?qvMAqg';
+        $internalLinkRealURL1 = '?qvMAqg';
+
+        $internalLink2 = 'http://shaarli.shaarli/?2_7zww';
+        $internalLinkRealURL2 = '?2_7zww';
+
+        $internalLink3 = 'http://shaarli.shaarli/?z7u-_Q';
+        $internalLinkRealURL3 = '?z7u-_Q';
+
+        $data = array(
+            'title' => $internalLink1,
+            'links' => array(
+                array(
+                    'url' => $internalLink1,
+                    'private' => 0,
+                    'real_url' => $internalLinkRealURL1
+                ),
+                array(
+                    'url' => $internalLink1,
+                    'private' => 1,
+                    'real_url' => $internalLinkRealURL1
+                ),
+                array(
+                    'url' => $internalLink2,
+                    'private' => 0,
+                    'real_url' => $internalLinkRealURL2
+                ),
+                array(
+                    'url' => $internalLink2,
+                    'private' => 1,
+                    'real_url' => $internalLinkRealURL2
+                ),
+                array(
+                    'url' => $internalLink3,
+                    'private' => 0,
+                    'real_url' => $internalLinkRealURL3
+                ),
+                array(
+                    'url' => $internalLink3,
+                    'private' => 1,
+                    'real_url' => $internalLinkRealURL3
+                )
+            )
+        );
+
+
+        $data = hook_archiveorg_render_linklist($data);
+
+        // Case n°1: first link type, public
+        $link = $data['links'][0];
+
+        $this->assertEquals(1, count($link['link_plugin']));
+        $this->assertNotFalse(strpos($link['link_plugin'][0], $internalLink1));
+
+        // Case n°2: first link type, private
+        $link = $data['links'][1];
+
+        $this->assertArrayNotHasKey('link_plugin', $link);
+
+        // Case n°3: second link type, public
+        $link = $data['links'][2];
+
+        $this->assertEquals(1, count($link['link_plugin']));
+        $this->assertNotFalse(strpos($link['link_plugin'][0], $internalLink2));
+
+        // Case n°4: second link type, private
+        $link = $data['links'][3];
+
+        $this->assertArrayNotHasKey('link_plugin', $link);
+
+        // Case n°5: third link type, public
+        $link = $data['links'][4];
+
+        $this->assertEquals(1, count($link['link_plugin']));
+        $this->assertNotFalse(strpos($link['link_plugin'][0], $internalLink3));
+
+        // Case n°6: third link type, private
+        $link = $data['links'][5];
+
+        $this->assertArrayNotHasKey('link_plugin', $link);
+
     }
+    
 }