4 * PluginArchiveorgTest.php
7 require_once 'plugins/archiveorg/archiveorg.php';
10 * Class PluginArchiveorgTest
11 * Unit test for the archiveorg plugin
13 class PluginArchiveorgTest
extends PHPUnit_Framework_TestCase
20 PluginManager
::$PLUGINS_PATH = 'plugins';
24 * Test render_linklist hook on external links.
26 function testArchiveorgLinklistOnExternalLinks()
28 $str = 'http://randomstr.com/test';
41 $data = hook_archiveorg_render_linklist($data);
43 $link = $data['links'][0];
44 // data shouldn't be altered
45 $this->assertEquals($str, $data['title']);
46 $this->assertEquals($str, $link['url']);
49 $this->assertEquals(1, count($link['link_plugin']));
50 $this->assertNotFalse(strpos($link['link_plugin'][0], $str));
55 * Test render_linklist hook on internal links.
57 function testArchiveorgLinklistOnInternalLinks()
59 $internalLink1 = 'http://shaarli.shaarli/?qvMAqg';
60 $internalLinkRealURL1 = '?qvMAqg';
62 $internalLink2 = 'http://shaarli.shaarli/?2_7zww';
63 $internalLinkRealURL2 = '?2_7zww';
65 $internalLink3 = 'http://shaarli.shaarli/?z7u-_Q';
66 $internalLinkRealURL3 = '?z7u-_Q';
69 'title' => $internalLink1,
72 'url' => $internalLink1,
74 'real_url' => $internalLinkRealURL1
77 'url' => $internalLink1,
79 'real_url' => $internalLinkRealURL1
82 'url' => $internalLink2,
84 'real_url' => $internalLinkRealURL2
87 'url' => $internalLink2,
89 'real_url' => $internalLinkRealURL2
92 'url' => $internalLink3,
94 'real_url' => $internalLinkRealURL3
97 'url' => $internalLink3,
99 'real_url' => $internalLinkRealURL3
105 $data = hook_archiveorg_render_linklist($data);
107 // Case n°1: first link type, public
108 $link = $data['links'][0];
110 $this->assertEquals(1, count($link['link_plugin']));
111 $this->assertNotFalse(strpos($link['link_plugin'][0], $internalLink1));
113 // Case n°2: first link type, private
114 $link = $data['links'][1];
116 $this->assertArrayNotHasKey('link_plugin', $link);
118 // Case n°3: second link type, public
119 $link = $data['links'][2];
121 $this->assertEquals(1, count($link['link_plugin']));
122 $this->assertNotFalse(strpos($link['link_plugin'][0], $internalLink2));
124 // Case n°4: second link type, private
125 $link = $data['links'][3];
127 $this->assertArrayNotHasKey('link_plugin', $link);
129 // Case n°5: third link type, public
130 $link = $data['links'][4];
132 $this->assertEquals(1, count($link['link_plugin']));
133 $this->assertNotFalse(strpos($link['link_plugin'][0], $internalLink3));
135 // Case n°6: third link type, private
136 $link = $data['links'][5];
138 $this->assertArrayNotHasKey('link_plugin', $link);