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