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