2 namespace Shaarli\Plugin\Isso
;
5 use Shaarli\Bookmark\Bookmark
;
6 use Shaarli\Config\ConfigManager
;
7 use Shaarli\Plugin\PluginManager
;
9 require_once 'plugins/isso/isso.php';
12 * Class PluginIssoTest
14 * Test the Isso plugin (comment system).
16 class PluginIssoTest
extends \PHPUnit\Framework\TestCase
21 public function setUp()
23 PluginManager
::$PLUGINS_PATH = 'plugins';
27 * Test Isso init without errors.
29 public function testIssoInitNoError()
31 $conf = new ConfigManager('');
32 $conf->set('plugins.ISSO_SERVER', 'value');
33 $errors = isso_init($conf);
34 $this->assertEmpty($errors);
38 * Test Isso init with errors.
40 public function testIssoInitError()
42 $conf = new ConfigManager('');
43 $errors = isso_init($conf);
44 $this->assertNotEmpty($errors);
48 * Test render_linklist hook with valid settings to display the comment form.
50 public function testIssoDisplayed()
52 $conf = new ConfigManager('');
53 $conf->set('plugins.ISSO_SERVER', 'value');
55 $str = 'http://randomstr.com/test';
56 $date = '20161118_100001';
63 'created' => DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, $date),
68 $data = hook_isso_render_linklist($data, $conf);
70 // data shouldn't be altered
71 $this->assertEquals($str, $data['title']);
72 $this->assertEquals($str, $data['links'][0]['url']);
75 $this->assertEquals(1, count($data['plugin_end_zone']));
76 $this->assertNotFalse(strpos(
77 $data['plugin_end_zone'][0],
78 'data-isso-id="'. $data['links'][0]['id'] .'"'
80 $this->assertNotFalse(strpos(
81 $data['plugin_end_zone'][0],
82 'data-title="'. $data['links'][0]['id'] .'"'
84 $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js'));
88 * Test isso plugin when multiple bookmarks are displayed (shouldn't be displayed).
90 public function testIssoMultipleLinks()
92 $conf = new ConfigManager('');
93 $conf->set('plugins.ISSO_SERVER', 'value');
95 $str = 'http://randomstr.com/test';
96 $date1 = '20161118_100001';
97 $date2 = '20161118_100002';
104 'shorturl' => $short1 = 'abcd',
105 'created' => DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, $date1),
110 'shorturl' => $short2 = 'efgh',
111 'created' => DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, $date2),
116 $processed = hook_isso_render_linklist($data, $conf);
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]);
123 * Test isso plugin when using search (shouldn't be displayed).
125 public function testIssoNotDisplayedWhenSearch()
127 $conf = new ConfigManager('');
128 $conf->set('plugins.ISSO_SERVER', 'value');
130 $str = 'http://randomstr.com/test';
131 $date = '20161118_100001';
138 'shorturl' => $short1 = 'abcd',
139 'created' => DateTime
::createFromFormat(Bookmark
::LINK_DATE_FORMAT
, $date),
142 'search_term' => $str
145 $processed = hook_isso_render_linklist($data, $conf);
147 // link_plugin should be added for the icon
148 $this->assertContains('<a href="?'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]);
152 * Test isso plugin without server configuration (shouldn't be displayed).
154 public function testIssoWithoutConf()
157 $conf = new ConfigManager('');
158 $processed = hook_isso_render_linklist($data, $conf);
159 $this->assertEquals($data, $processed);