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