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