3 use Shaarli\Bookmark\LinkDB
;
4 use Shaarli\Config\ConfigManager
;
5 use Shaarli\Plugin\PluginManager
;
7 require_once 'plugins/isso/isso.php';
10 * Class PluginIssoTest
12 * Test the Isso plugin (comment system).
14 class PluginIssoTest
extends PHPUnit_Framework_TestCase
19 public function setUp()
21 PluginManager
::$PLUGINS_PATH = 'plugins';
25 * Test Isso init without errors.
27 public function testIssoInitNoError()
29 $conf = new ConfigManager('');
30 $conf->set('plugins.ISSO_SERVER', 'value');
31 $errors = isso_init($conf);
32 $this->assertEmpty($errors);
36 * Test Isso init with errors.
38 public function testIssoInitError()
40 $conf = new ConfigManager('');
41 $errors = isso_init($conf);
42 $this->assertNotEmpty($errors);
46 * Test render_linklist hook with valid settings to display the comment form.
48 public function testIssoDisplayed()
50 $conf = new ConfigManager('');
51 $conf->set('plugins.ISSO_SERVER', 'value');
53 $str = 'http://randomstr.com/test';
54 $date = '20161118_100001';
61 'created' => DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, $date),
66 $data = hook_isso_render_linklist($data, $conf);
68 // data shouldn't be altered
69 $this->assertEquals($str, $data['title']);
70 $this->assertEquals($str, $data['links'][0]['url']);
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'] .'"'
78 $this->assertNotFalse(strpos(
79 $data['plugin_end_zone'][0],
80 'data-title="'. $data['links'][0]['id'] .'"'
82 $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js'));
86 * Test isso plugin when multiple links are displayed (shouldn't be displayed).
88 public function testIssoMultipleLinks()
90 $conf = new ConfigManager('');
91 $conf->set('plugins.ISSO_SERVER', 'value');
93 $str = 'http://randomstr.com/test';
94 $date1 = '20161118_100001';
95 $date2 = '20161118_100002';
102 'shorturl' => $short1 = 'abcd',
103 'created' => DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, $date1),
108 'shorturl' => $short2 = 'efgh',
109 'created' => DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, $date2),
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]);
121 * Test isso plugin when using search (shouldn't be displayed).
123 public function testIssoNotDisplayedWhenSearch()
125 $conf = new ConfigManager('');
126 $conf->set('plugins.ISSO_SERVER', 'value');
128 $str = 'http://randomstr.com/test';
129 $date = '20161118_100001';
136 'shorturl' => $short1 = 'abcd',
137 'created' => DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, $date),
140 'search_term' => $str
143 $processed = hook_isso_render_linklist($data, $conf);
145 // link_plugin should be added for the icon
146 $this->assertContains('<a href="?'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]);
150 * Test isso plugin without server configuration (shouldn't be displayed).
152 public function testIssoWithoutConf()
155 $conf = new ConfigManager('');
156 $processed = hook_isso_render_linklist($data, $conf);
157 $this->assertEquals($data, $processed);