]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - tests/plugins/PluginArchiveorgTest.php
fix translation string
[github/shaarli/Shaarli.git] / tests / plugins / PluginArchiveorgTest.php
CommitLineData
9a364c28
A
1<?php
2
3/**
4 * PluginArchiveorgTest.php
5 */
6
7require_once 'plugins/archiveorg/archiveorg.php';
8
9/**
5e148f8a
T
10 * Class PluginArchiveorgTest
11 * Unit test for the archiveorg plugin
9a364c28
A
12 */
13class PluginArchiveorgTest extends PHPUnit_Framework_TestCase
14{
15 /**
16 * Reset plugin path
17 */
93b1fe54 18 public function setUp()
9a364c28
A
19 {
20 PluginManager::$PLUGINS_PATH = 'plugins';
21 }
22
23 /**
5e148f8a 24 * Test render_linklist hook on external links.
9a364c28 25 */
93b1fe54 26 public function testArchiveorgLinklistOnExternalLinks()
9a364c28
A
27 {
28 $str = 'http://randomstr.com/test';
5e148f8a 29
9a364c28
A
30 $data = array(
31 'title' => $str,
32 'links' => array(
33 array(
34 'url' => $str,
5e148f8a
T
35 'private' => 0,
36 'real_url' => $str
9a364c28
A
37 )
38 )
39 );
40
41 $data = hook_archiveorg_render_linklist($data);
5e148f8a 42
9a364c28
A
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));
5e148f8a
T
51 }
52
53 /**
54 * Test render_linklist hook on internal links.
55 */
93b1fe54 56 public function testArchiveorgLinklistOnInternalLinks()
5e148f8a
T
57 {
58 $internalLink1 = 'http://shaarli.shaarli/?qvMAqg';
59 $internalLinkRealURL1 = '?qvMAqg';
60
61 $internalLink2 = 'http://shaarli.shaarli/?2_7zww';
62 $internalLinkRealURL2 = '?2_7zww';
63
64 $internalLink3 = 'http://shaarli.shaarli/?z7u-_Q';
65 $internalLinkRealURL3 = '?z7u-_Q';
66
67 $data = array(
68 'title' => $internalLink1,
69 'links' => array(
70 array(
71 'url' => $internalLink1,
72 'private' => 0,
73 'real_url' => $internalLinkRealURL1
74 ),
75 array(
76 'url' => $internalLink1,
77 'private' => 1,
78 'real_url' => $internalLinkRealURL1
79 ),
80 array(
81 'url' => $internalLink2,
82 'private' => 0,
83 'real_url' => $internalLinkRealURL2
84 ),
85 array(
86 'url' => $internalLink2,
87 'private' => 1,
88 'real_url' => $internalLinkRealURL2
89 ),
90 array(
91 'url' => $internalLink3,
92 'private' => 0,
93 'real_url' => $internalLinkRealURL3
94 ),
95 array(
96 'url' => $internalLink3,
97 'private' => 1,
98 'real_url' => $internalLinkRealURL3
99 )
100 )
101 );
102
5e148f8a
T
103 $data = hook_archiveorg_render_linklist($data);
104
105 // Case n°1: first link type, public
106 $link = $data['links'][0];
107
108 $this->assertEquals(1, count($link['link_plugin']));
109 $this->assertNotFalse(strpos($link['link_plugin'][0], $internalLink1));
110
111 // Case n°2: first link type, private
112 $link = $data['links'][1];
113
114 $this->assertArrayNotHasKey('link_plugin', $link);
115
116 // Case n°3: second link type, public
117 $link = $data['links'][2];
118
119 $this->assertEquals(1, count($link['link_plugin']));
120 $this->assertNotFalse(strpos($link['link_plugin'][0], $internalLink2));
121
122 // Case n°4: second link type, private
123 $link = $data['links'][3];
124
125 $this->assertArrayNotHasKey('link_plugin', $link);
126
127 // Case n°5: third link type, public
128 $link = $data['links'][4];
129
130 $this->assertEquals(1, count($link['link_plugin']));
131 $this->assertNotFalse(strpos($link['link_plugin'][0], $internalLink3));
132
133 // Case n°6: third link type, private
134 $link = $data['links'][5];
135
136 $this->assertArrayNotHasKey('link_plugin', $link);
9a364c28
A
137 }
138}