]>
Commit | Line | Data |
---|---|---|
bf26e7eb | 1 | <?php |
f24896b2 V |
2 | |
3 | use Shaarli\Bookmark\LinkDB; | |
3c66e564 | 4 | use Shaarli\Config\ConfigManager; |
bf26e7eb A |
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 | */ | |
93b1fe54 | 18 | public function setUp() |
bf26e7eb A |
19 | { |
20 | PluginManager::$PLUGINS_PATH = 'plugins'; | |
21 | } | |
22 | ||
23 | /** | |
24 | * Test Isso init without errors. | |
25 | */ | |
0e54e105 | 26 | public function testIssoInitNoError() |
bf26e7eb A |
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 | */ | |
0e54e105 | 37 | public function testIssoInitError() |
bf26e7eb A |
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 | */ | |
93b1fe54 | 47 | public function testIssoDisplayed() |
bf26e7eb A |
48 | { |
49 | $conf = new ConfigManager(''); | |
50 | $conf->set('plugins.ISSO_SERVER', 'value'); | |
51 | ||
52 | $str = 'http://randomstr.com/test'; | |
c3dfd899 | 53 | $date = '20161118_100001'; |
bf26e7eb A |
54 | $data = array( |
55 | 'title' => $str, | |
56 | 'links' => array( | |
57 | array( | |
d592daea | 58 | 'id' => 12, |
bf26e7eb | 59 | 'url' => $str, |
d592daea | 60 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date), |
bf26e7eb A |
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'])); | |
d592daea A |
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 | )); | |
bf26e7eb A |
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 | */ | |
93b1fe54 | 87 | public function testIssoMultipleLinks() |
bf26e7eb A |
88 | { |
89 | $conf = new ConfigManager(''); | |
90 | $conf->set('plugins.ISSO_SERVER', 'value'); | |
91 | ||
92 | $str = 'http://randomstr.com/test'; | |
c3dfd899 A |
93 | $date1 = '20161118_100001'; |
94 | $date2 = '20161118_100002'; | |
bf26e7eb A |
95 | $data = array( |
96 | 'title' => $str, | |
97 | 'links' => array( | |
98 | array( | |
d592daea | 99 | 'id' => 12, |
bf26e7eb | 100 | 'url' => $str, |
0e54e105 | 101 | 'shorturl' => $short1 = 'abcd', |
d592daea | 102 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date1), |
bf26e7eb A |
103 | ), |
104 | array( | |
d592daea | 105 | 'id' => 13, |
bf26e7eb | 106 | 'url' => $str . '2', |
0e54e105 | 107 | 'shorturl' => $short2 = 'efgh', |
d592daea | 108 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date2), |
bf26e7eb A |
109 | ), |
110 | ) | |
111 | ); | |
112 | ||
113 | $processed = hook_isso_render_linklist($data, $conf); | |
0e54e105 A |
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]); | |
bf26e7eb A |
117 | } |
118 | ||
119 | /** | |
120 | * Test isso plugin when using search (shouldn't be displayed). | |
121 | */ | |
93b1fe54 | 122 | public function testIssoNotDisplayedWhenSearch() |
bf26e7eb A |
123 | { |
124 | $conf = new ConfigManager(''); | |
125 | $conf->set('plugins.ISSO_SERVER', 'value'); | |
126 | ||
127 | $str = 'http://randomstr.com/test'; | |
c3dfd899 | 128 | $date = '20161118_100001'; |
bf26e7eb A |
129 | $data = array( |
130 | 'title' => $str, | |
131 | 'links' => array( | |
132 | array( | |
d592daea | 133 | 'id' => 12, |
bf26e7eb | 134 | 'url' => $str, |
0e54e105 | 135 | 'shorturl' => $short1 = 'abcd', |
d592daea | 136 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date), |
bf26e7eb A |
137 | ) |
138 | ), | |
139 | 'search_term' => $str | |
140 | ); | |
141 | ||
142 | $processed = hook_isso_render_linklist($data, $conf); | |
143 | ||
0e54e105 A |
144 | // link_plugin should be added for the icon |
145 | $this->assertContains('<a href="?'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]); | |
bf26e7eb A |
146 | } |
147 | ||
148 | /** | |
149 | * Test isso plugin without server configuration (shouldn't be displayed). | |
150 | */ | |
93b1fe54 | 151 | public function testIssoWithoutConf() |
bf26e7eb A |
152 | { |
153 | $data = 'abc'; | |
154 | $conf = new ConfigManager(''); | |
155 | $processed = hook_isso_render_linklist($data, $conf); | |
156 | $this->assertEquals($data, $processed); | |
157 | } | |
158 | } |