3 use Shaarli\Bookmark\LinkDB
;
4 use Shaarli\Config\ConfigManager
;
6 require_once 'plugins/isso/isso.php';
11 * Test the Isso plugin (comment system).
13 class PluginIssoTest
extends PHPUnit_Framework_TestCase
18 public function setUp()
20 PluginManager
::$PLUGINS_PATH = 'plugins';
24 * Test Isso init without errors.
26 public function testIssoInitNoError()
28 $conf = new ConfigManager('');
29 $conf->set('plugins.ISSO_SERVER', 'value');
30 $errors = isso_init($conf);
31 $this->assertEmpty($errors);
35 * Test Isso init with errors.
37 public function testIssoInitError()
39 $conf = new ConfigManager('');
40 $errors = isso_init($conf);
41 $this->assertNotEmpty($errors);
45 * Test render_linklist hook with valid settings to display the comment form.
47 public function testIssoDisplayed()
49 $conf = new ConfigManager('');
50 $conf->set('plugins.ISSO_SERVER', 'value');
52 $str = 'http://randomstr.com/test';
53 $date = '20161118_100001';
60 'created' => DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, $date),
65 $data = hook_isso_render_linklist($data, $conf);
67 // data shouldn't be altered
68 $this->assertEquals($str, $data['title']);
69 $this->assertEquals($str, $data['links'][0]['url']);
72 $this->assertEquals(1, count($data['plugin_end_zone']));
73 $this->assertNotFalse(strpos(
74 $data['plugin_end_zone'][0],
75 'data-isso-id="'. $data['links'][0]['id'] .'"'
77 $this->assertNotFalse(strpos(
78 $data['plugin_end_zone'][0],
79 'data-title="'. $data['links'][0]['id'] .'"'
81 $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js'));
85 * Test isso plugin when multiple links are displayed (shouldn't be displayed).
87 public function testIssoMultipleLinks()
89 $conf = new ConfigManager('');
90 $conf->set('plugins.ISSO_SERVER', 'value');
92 $str = 'http://randomstr.com/test';
93 $date1 = '20161118_100001';
94 $date2 = '20161118_100002';
101 'shorturl' => $short1 = 'abcd',
102 'created' => DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, $date1),
107 'shorturl' => $short2 = 'efgh',
108 'created' => DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, $date2),
113 $processed = hook_isso_render_linklist($data, $conf);
114 // link_plugin should be added for the icon
115 $this->assertContains('<a href="?'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]);
116 $this->assertContains('<a href="?'. $short2 .'#isso-thread">', $processed['links'][1]['link_plugin'][0]);
120 * Test isso plugin when using search (shouldn't be displayed).
122 public function testIssoNotDisplayedWhenSearch()
124 $conf = new ConfigManager('');
125 $conf->set('plugins.ISSO_SERVER', 'value');
127 $str = 'http://randomstr.com/test';
128 $date = '20161118_100001';
135 'shorturl' => $short1 = 'abcd',
136 'created' => DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, $date),
139 'search_term' => $str
142 $processed = hook_isso_render_linklist($data, $conf);
144 // link_plugin should be added for the icon
145 $this->assertContains('<a href="?'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]);
149 * Test isso plugin without server configuration (shouldn't be displayed).
151 public function testIssoWithoutConf()
154 $conf = new ConfigManager('');
155 $processed = hook_isso_render_linklist($data, $conf);
156 $this->assertEquals($data, $processed);