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