diff options
author | VirtualTam <virtualtam+github@flibidi.net> | 2016-10-13 18:12:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-13 18:12:55 +0200 |
commit | f63632a6fb84594b8aeacb387a5cd17b4a841d2c (patch) | |
tree | 86b21f07afcdae003e8740682eb5698f07f3c937 /tests/plugins/PluginArchiveorgTest.php | |
parent | 03542572665bae57705a2f57b0737ed43f4f1415 (diff) | |
parent | 5e148f8a529abf72256ef74ed149d56a5b27bd72 (diff) | |
download | Shaarli-f63632a6fb84594b8aeacb387a5cd17b4a841d2c.tar.gz Shaarli-f63632a6fb84594b8aeacb387a5cd17b4a841d2c.tar.zst Shaarli-f63632a6fb84594b8aeacb387a5cd17b4a841d2c.zip |
Merge pull request #654 from teromene/archive-org-no-internal
Archive.org plugin: do not propose archival of private notes
Fixes #637
Diffstat (limited to 'tests/plugins/PluginArchiveorgTest.php')
-rw-r--r-- | tests/plugins/PluginArchiveorgTest.php | 102 |
1 files changed, 98 insertions, 4 deletions
diff --git a/tests/plugins/PluginArchiveorgTest.php b/tests/plugins/PluginArchiveorgTest.php index dbc52bc8..4daa4c9d 100644 --- a/tests/plugins/PluginArchiveorgTest.php +++ b/tests/plugins/PluginArchiveorgTest.php | |||
@@ -7,8 +7,8 @@ | |||
7 | require_once 'plugins/archiveorg/archiveorg.php'; | 7 | require_once 'plugins/archiveorg/archiveorg.php'; |
8 | 8 | ||
9 | /** | 9 | /** |
10 | * Class PlugQrcodeTest | 10 | * Class PluginArchiveorgTest |
11 | * Unit test for the QR-Code plugin | 11 | * Unit test for the archiveorg plugin |
12 | */ | 12 | */ |
13 | class PluginArchiveorgTest extends PHPUnit_Framework_TestCase | 13 | class PluginArchiveorgTest extends PHPUnit_Framework_TestCase |
14 | { | 14 | { |
@@ -21,21 +21,25 @@ class PluginArchiveorgTest extends PHPUnit_Framework_TestCase | |||
21 | } | 21 | } |
22 | 22 | ||
23 | /** | 23 | /** |
24 | * Test render_linklist hook. | 24 | * Test render_linklist hook on external links. |
25 | */ | 25 | */ |
26 | function testArchiveorgLinklist() | 26 | function testArchiveorgLinklistOnExternalLinks() |
27 | { | 27 | { |
28 | $str = 'http://randomstr.com/test'; | 28 | $str = 'http://randomstr.com/test'; |
29 | |||
29 | $data = array( | 30 | $data = array( |
30 | 'title' => $str, | 31 | 'title' => $str, |
31 | 'links' => array( | 32 | 'links' => array( |
32 | array( | 33 | array( |
33 | 'url' => $str, | 34 | 'url' => $str, |
35 | 'private' => 0, | ||
36 | 'real_url' => $str | ||
34 | ) | 37 | ) |
35 | ) | 38 | ) |
36 | ); | 39 | ); |
37 | 40 | ||
38 | $data = hook_archiveorg_render_linklist($data); | 41 | $data = hook_archiveorg_render_linklist($data); |
42 | |||
39 | $link = $data['links'][0]; | 43 | $link = $data['links'][0]; |
40 | // data shouldn't be altered | 44 | // data shouldn't be altered |
41 | $this->assertEquals($str, $data['title']); | 45 | $this->assertEquals($str, $data['title']); |
@@ -44,5 +48,95 @@ class PluginArchiveorgTest extends PHPUnit_Framework_TestCase | |||
44 | // plugin data | 48 | // plugin data |
45 | $this->assertEquals(1, count($link['link_plugin'])); | 49 | $this->assertEquals(1, count($link['link_plugin'])); |
46 | $this->assertNotFalse(strpos($link['link_plugin'][0], $str)); | 50 | $this->assertNotFalse(strpos($link['link_plugin'][0], $str)); |
51 | |||
52 | } | ||
53 | |||
54 | /** | ||
55 | * Test render_linklist hook on internal links. | ||
56 | */ | ||
57 | function testArchiveorgLinklistOnInternalLinks() | ||
58 | { | ||
59 | $internalLink1 = 'http://shaarli.shaarli/?qvMAqg'; | ||
60 | $internalLinkRealURL1 = '?qvMAqg'; | ||
61 | |||
62 | $internalLink2 = 'http://shaarli.shaarli/?2_7zww'; | ||
63 | $internalLinkRealURL2 = '?2_7zww'; | ||
64 | |||
65 | $internalLink3 = 'http://shaarli.shaarli/?z7u-_Q'; | ||
66 | $internalLinkRealURL3 = '?z7u-_Q'; | ||
67 | |||
68 | $data = array( | ||
69 | 'title' => $internalLink1, | ||
70 | 'links' => array( | ||
71 | array( | ||
72 | 'url' => $internalLink1, | ||
73 | 'private' => 0, | ||
74 | 'real_url' => $internalLinkRealURL1 | ||
75 | ), | ||
76 | array( | ||
77 | 'url' => $internalLink1, | ||
78 | 'private' => 1, | ||
79 | 'real_url' => $internalLinkRealURL1 | ||
80 | ), | ||
81 | array( | ||
82 | 'url' => $internalLink2, | ||
83 | 'private' => 0, | ||
84 | 'real_url' => $internalLinkRealURL2 | ||
85 | ), | ||
86 | array( | ||
87 | 'url' => $internalLink2, | ||
88 | 'private' => 1, | ||
89 | 'real_url' => $internalLinkRealURL2 | ||
90 | ), | ||
91 | array( | ||
92 | 'url' => $internalLink3, | ||
93 | 'private' => 0, | ||
94 | 'real_url' => $internalLinkRealURL3 | ||
95 | ), | ||
96 | array( | ||
97 | 'url' => $internalLink3, | ||
98 | 'private' => 1, | ||
99 | 'real_url' => $internalLinkRealURL3 | ||
100 | ) | ||
101 | ) | ||
102 | ); | ||
103 | |||
104 | |||
105 | $data = hook_archiveorg_render_linklist($data); | ||
106 | |||
107 | // Case n°1: first link type, public | ||
108 | $link = $data['links'][0]; | ||
109 | |||
110 | $this->assertEquals(1, count($link['link_plugin'])); | ||
111 | $this->assertNotFalse(strpos($link['link_plugin'][0], $internalLink1)); | ||
112 | |||
113 | // Case n°2: first link type, private | ||
114 | $link = $data['links'][1]; | ||
115 | |||
116 | $this->assertArrayNotHasKey('link_plugin', $link); | ||
117 | |||
118 | // Case n°3: second link type, public | ||
119 | $link = $data['links'][2]; | ||
120 | |||
121 | $this->assertEquals(1, count($link['link_plugin'])); | ||
122 | $this->assertNotFalse(strpos($link['link_plugin'][0], $internalLink2)); | ||
123 | |||
124 | // Case n°4: second link type, private | ||
125 | $link = $data['links'][3]; | ||
126 | |||
127 | $this->assertArrayNotHasKey('link_plugin', $link); | ||
128 | |||
129 | // Case n°5: third link type, public | ||
130 | $link = $data['links'][4]; | ||
131 | |||
132 | $this->assertEquals(1, count($link['link_plugin'])); | ||
133 | $this->assertNotFalse(strpos($link['link_plugin'][0], $internalLink3)); | ||
134 | |||
135 | // Case n°6: third link type, private | ||
136 | $link = $data['links'][5]; | ||
137 | |||
138 | $this->assertArrayNotHasKey('link_plugin', $link); | ||
139 | |||
47 | } | 140 | } |
141 | |||
48 | } | 142 | } |