2 namespace Shaarli\Plugin\Isso
;
5 use Shaarli\Bookmark\Bookmark
;
6 use Shaarli\Config\ConfigManager
;
7 use Shaarli\Plugin\PluginManager
;
10 require_once 'plugins/isso/isso.php';
13 * Class PluginIssoTest
15 * Test the Isso plugin (comment system).
17 class PluginIssoTest
extends TestCase
22 public function setUp(): void
24 PluginManager
::$PLUGINS_PATH = 'plugins';
28 * Test Isso init without errors.
30 public function testIssoInitNoError(): void
32 $conf = new ConfigManager('');
33 $conf->set('plugins.ISSO_SERVER', 'value');
34 $errors = isso_init($conf);
35 $this->assertEmpty($errors);
39 * Test Isso init with errors.
41 public function testIssoInitError(): void
43 $conf = new ConfigManager('');
44 $errors = isso_init($conf);
45 $this->assertNotEmpty($errors);
49 * Test render_linklist hook with valid settings to display the comment form.
51 public function testIssoDisplayed(): void
53 $conf = new ConfigManager('');
54 $conf->set('plugins.ISSO_SERVER', 'value');
56 $str = 'http://randomstr.com/test';
57 $date = '20161118_100001';
64 'created' => DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, $date),
69 $data = hook_isso_render_linklist($data, $conf);
71 // data shouldn't be altered
72 $this->assertEquals($str, $data['title']);
73 $this->assertEquals($str, $data['links'][0]['url']);
76 $this->assertEquals(1, count($data['plugin_end_zone']));
77 $this->assertNotFalse(strpos(
78 $data['plugin_end_zone'][0],
79 'data-isso-id="'. $data['links'][0]['id'] .'"'
81 $this->assertNotFalse(strpos(
82 $data['plugin_end_zone'][0],
83 'data-title="'. $data['links'][0]['id'] .'"'
85 $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js'));
89 * Test isso plugin when multiple bookmarks are displayed (shouldn't be displayed).
91 public function testIssoMultipleLinks(): void
93 $conf = new ConfigManager('');
94 $conf->set('plugins.ISSO_SERVER', 'value');
96 $str = 'http://randomstr.com/test';
97 $date1 = '20161118_100001';
98 $date2 = '20161118_100002';
105 'shorturl' => $short1 = 'abcd',
106 'created' => DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, $date1),
111 'shorturl' => $short2 = 'efgh',
112 'created' => DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, $date2),
117 $processed = hook_isso_render_linklist($data, $conf);
118 // link_plugin should be added for the icon
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]);
124 * Test isso plugin when using search (shouldn't be displayed).
126 public function testIssoNotDisplayedWhenSearch(): void
128 $conf = new ConfigManager('');
129 $conf->set('plugins.ISSO_SERVER', 'value');
131 $str = 'http://randomstr.com/test';
132 $date = '20161118_100001';
139 'shorturl' => $short1 = 'abcd',
140 'created' => DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, $date),
143 'search_term' => $str
146 $processed = hook_isso_render_linklist($data, $conf);
148 // link_plugin should be added for the icon
149 $this->assertContainsPolyfill('<a href="/shaare/'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]);
153 * Test isso plugin without server configuration (shouldn't be displayed).
155 public function testIssoWithoutConf(): void
158 $conf = new ConfigManager('');
159 $processed = hook_isso_render_linklist($data, $conf);
160 $this->assertEquals($data, $processed);