]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - tests/plugins/PluginArchiveorgTest.php
CHANGELOG.md: improve formatting, fix typos
[github/shaarli/Shaarli.git] / tests / plugins / PluginArchiveorgTest.php
1 <?php
2
3 /**
4 * PluginArchiveorgTest.php
5 */
6
7 require_once 'plugins/archiveorg/archiveorg.php';
8
9 /**
10 * Class PluginArchiveorgTest
11 * Unit test for the archiveorg plugin
12 */
13 class PluginArchiveorgTest 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 on external links.
25 */
26 function testArchiveorgLinklistOnExternalLinks()
27 {
28 $str = 'http://randomstr.com/test';
29
30 $data = array(
31 'title' => $str,
32 'links' => array(
33 array(
34 'url' => $str,
35 'private' => 0,
36 'real_url' => $str
37 )
38 )
39 );
40
41 $data = hook_archiveorg_render_linklist($data);
42
43 $link = $data['links'][0];
44 // data shouldn't be altered
45 $this->assertEquals($str, $data['title']);
46 $this->assertEquals($str, $link['url']);
47
48 // plugin data
49 $this->assertEquals(1, count($link['link_plugin']));
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
140 }
141
142 }