]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | use Shaarli\Bookmark\LinkDB; | |
4 | use Shaarli\Config\ConfigManager; | |
5 | ||
6 | require_once 'plugins/isso/isso.php'; | |
7 | ||
8 | /** | |
9 | * Class PluginIssoTest | |
10 | * | |
11 | * Test the Isso plugin (comment system). | |
12 | */ | |
13 | class PluginIssoTest extends PHPUnit_Framework_TestCase | |
14 | { | |
15 | /** | |
16 | * Reset plugin path | |
17 | */ | |
18 | public function setUp() | |
19 | { | |
20 | PluginManager::$PLUGINS_PATH = 'plugins'; | |
21 | } | |
22 | ||
23 | /** | |
24 | * Test Isso init without errors. | |
25 | */ | |
26 | public function testIssoInitNoError() | |
27 | { | |
28 | $conf = new ConfigManager(''); | |
29 | $conf->set('plugins.ISSO_SERVER', 'value'); | |
30 | $errors = isso_init($conf); | |
31 | $this->assertEmpty($errors); | |
32 | } | |
33 | ||
34 | /** | |
35 | * Test Isso init with errors. | |
36 | */ | |
37 | public function testIssoInitError() | |
38 | { | |
39 | $conf = new ConfigManager(''); | |
40 | $errors = isso_init($conf); | |
41 | $this->assertNotEmpty($errors); | |
42 | } | |
43 | ||
44 | /** | |
45 | * Test render_linklist hook with valid settings to display the comment form. | |
46 | */ | |
47 | public function testIssoDisplayed() | |
48 | { | |
49 | $conf = new ConfigManager(''); | |
50 | $conf->set('plugins.ISSO_SERVER', 'value'); | |
51 | ||
52 | $str = 'http://randomstr.com/test'; | |
53 | $date = '20161118_100001'; | |
54 | $data = array( | |
55 | 'title' => $str, | |
56 | 'links' => array( | |
57 | array( | |
58 | 'id' => 12, | |
59 | 'url' => $str, | |
60 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date), | |
61 | ) | |
62 | ) | |
63 | ); | |
64 | ||
65 | $data = hook_isso_render_linklist($data, $conf); | |
66 | ||
67 | // data shouldn't be altered | |
68 | $this->assertEquals($str, $data['title']); | |
69 | $this->assertEquals($str, $data['links'][0]['url']); | |
70 | ||
71 | // plugin data | |
72 | $this->assertEquals(1, count($data['plugin_end_zone'])); | |
73 | $this->assertNotFalse(strpos( | |
74 | $data['plugin_end_zone'][0], | |
75 | 'data-isso-id="'. $data['links'][0]['id'] .'"' | |
76 | )); | |
77 | $this->assertNotFalse(strpos( | |
78 | $data['plugin_end_zone'][0], | |
79 | 'data-title="'. $data['links'][0]['id'] .'"' | |
80 | )); | |
81 | $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js')); | |
82 | } | |
83 | ||
84 | /** | |
85 | * Test isso plugin when multiple links are displayed (shouldn't be displayed). | |
86 | */ | |
87 | public function testIssoMultipleLinks() | |
88 | { | |
89 | $conf = new ConfigManager(''); | |
90 | $conf->set('plugins.ISSO_SERVER', 'value'); | |
91 | ||
92 | $str = 'http://randomstr.com/test'; | |
93 | $date1 = '20161118_100001'; | |
94 | $date2 = '20161118_100002'; | |
95 | $data = array( | |
96 | 'title' => $str, | |
97 | 'links' => array( | |
98 | array( | |
99 | 'id' => 12, | |
100 | 'url' => $str, | |
101 | 'shorturl' => $short1 = 'abcd', | |
102 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date1), | |
103 | ), | |
104 | array( | |
105 | 'id' => 13, | |
106 | 'url' => $str . '2', | |
107 | 'shorturl' => $short2 = 'efgh', | |
108 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date2), | |
109 | ), | |
110 | ) | |
111 | ); | |
112 | ||
113 | $processed = hook_isso_render_linklist($data, $conf); | |
114 | // link_plugin should be added for the icon | |
115 | $this->assertContains('<a href="?'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]); | |
116 | $this->assertContains('<a href="?'. $short2 .'#isso-thread">', $processed['links'][1]['link_plugin'][0]); | |
117 | } | |
118 | ||
119 | /** | |
120 | * Test isso plugin when using search (shouldn't be displayed). | |
121 | */ | |
122 | public function testIssoNotDisplayedWhenSearch() | |
123 | { | |
124 | $conf = new ConfigManager(''); | |
125 | $conf->set('plugins.ISSO_SERVER', 'value'); | |
126 | ||
127 | $str = 'http://randomstr.com/test'; | |
128 | $date = '20161118_100001'; | |
129 | $data = array( | |
130 | 'title' => $str, | |
131 | 'links' => array( | |
132 | array( | |
133 | 'id' => 12, | |
134 | 'url' => $str, | |
135 | 'shorturl' => $short1 = 'abcd', | |
136 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date), | |
137 | ) | |
138 | ), | |
139 | 'search_term' => $str | |
140 | ); | |
141 | ||
142 | $processed = hook_isso_render_linklist($data, $conf); | |
143 | ||
144 | // link_plugin should be added for the icon | |
145 | $this->assertContains('<a href="?'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]); | |
146 | } | |
147 | ||
148 | /** | |
149 | * Test isso plugin without server configuration (shouldn't be displayed). | |
150 | */ | |
151 | public function testIssoWithoutConf() | |
152 | { | |
153 | $data = 'abc'; | |
154 | $conf = new ConfigManager(''); | |
155 | $processed = hook_isso_render_linklist($data, $conf); | |
156 | $this->assertEquals($data, $processed); | |
157 | } | |
158 | } |