2016-10-03 09:43:49 +02:00
|
|
|
<?php
|
2018-12-03 01:10:39 +01:00
|
|
|
|
|
|
|
use Shaarli\Bookmark\LinkDB;
|
2017-03-03 23:06:12 +01:00
|
|
|
use Shaarli\Config\ConfigManager;
|
2018-12-04 00:26:50 +01:00
|
|
|
use Shaarli\Plugin\PluginManager;
|
2016-10-03 09:43:49 +02:00
|
|
|
|
|
|
|
require_once 'plugins/isso/isso.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class PluginIssoTest
|
|
|
|
*
|
|
|
|
* Test the Isso plugin (comment system).
|
|
|
|
*/
|
|
|
|
class PluginIssoTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Reset plugin path
|
|
|
|
*/
|
2017-01-05 19:33:06 +01:00
|
|
|
public function setUp()
|
2016-10-03 09:43:49 +02:00
|
|
|
{
|
|
|
|
PluginManager::$PLUGINS_PATH = 'plugins';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test Isso init without errors.
|
|
|
|
*/
|
2018-08-14 13:39:31 +02:00
|
|
|
public function testIssoInitNoError()
|
2016-10-03 09:43:49 +02:00
|
|
|
{
|
|
|
|
$conf = new ConfigManager('');
|
|
|
|
$conf->set('plugins.ISSO_SERVER', 'value');
|
|
|
|
$errors = isso_init($conf);
|
|
|
|
$this->assertEmpty($errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test Isso init with errors.
|
|
|
|
*/
|
2018-08-14 13:39:31 +02:00
|
|
|
public function testIssoInitError()
|
2016-10-03 09:43:49 +02:00
|
|
|
{
|
|
|
|
$conf = new ConfigManager('');
|
|
|
|
$errors = isso_init($conf);
|
|
|
|
$this->assertNotEmpty($errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test render_linklist hook with valid settings to display the comment form.
|
|
|
|
*/
|
2017-01-05 19:33:06 +01:00
|
|
|
public function testIssoDisplayed()
|
2016-10-03 09:43:49 +02:00
|
|
|
{
|
|
|
|
$conf = new ConfigManager('');
|
|
|
|
$conf->set('plugins.ISSO_SERVER', 'value');
|
|
|
|
|
|
|
|
$str = 'http://randomstr.com/test';
|
2016-11-28 16:17:25 +01:00
|
|
|
$date = '20161118_100001';
|
2016-10-03 09:43:49 +02:00
|
|
|
$data = array(
|
|
|
|
'title' => $str,
|
|
|
|
'links' => array(
|
|
|
|
array(
|
2016-11-28 18:24:15 +01:00
|
|
|
'id' => 12,
|
2016-10-03 09:43:49 +02:00
|
|
|
'url' => $str,
|
2016-11-28 18:24:15 +01:00
|
|
|
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date),
|
2016-10-03 09:43:49 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$data = hook_isso_render_linklist($data, $conf);
|
|
|
|
|
|
|
|
// data shouldn't be altered
|
|
|
|
$this->assertEquals($str, $data['title']);
|
|
|
|
$this->assertEquals($str, $data['links'][0]['url']);
|
|
|
|
|
|
|
|
// plugin data
|
|
|
|
$this->assertEquals(1, count($data['plugin_end_zone']));
|
2016-11-28 18:24:15 +01:00
|
|
|
$this->assertNotFalse(strpos(
|
|
|
|
$data['plugin_end_zone'][0],
|
|
|
|
'data-isso-id="'. $data['links'][0]['id'] .'"'
|
|
|
|
));
|
|
|
|
$this->assertNotFalse(strpos(
|
|
|
|
$data['plugin_end_zone'][0],
|
|
|
|
'data-title="'. $data['links'][0]['id'] .'"'
|
|
|
|
));
|
2016-10-03 09:43:49 +02:00
|
|
|
$this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test isso plugin when multiple links are displayed (shouldn't be displayed).
|
|
|
|
*/
|
2017-01-05 19:33:06 +01:00
|
|
|
public function testIssoMultipleLinks()
|
2016-10-03 09:43:49 +02:00
|
|
|
{
|
|
|
|
$conf = new ConfigManager('');
|
|
|
|
$conf->set('plugins.ISSO_SERVER', 'value');
|
|
|
|
|
|
|
|
$str = 'http://randomstr.com/test';
|
2016-11-28 16:17:25 +01:00
|
|
|
$date1 = '20161118_100001';
|
|
|
|
$date2 = '20161118_100002';
|
2016-10-03 09:43:49 +02:00
|
|
|
$data = array(
|
|
|
|
'title' => $str,
|
|
|
|
'links' => array(
|
|
|
|
array(
|
2016-11-28 18:24:15 +01:00
|
|
|
'id' => 12,
|
2016-10-03 09:43:49 +02:00
|
|
|
'url' => $str,
|
2018-08-14 13:39:31 +02:00
|
|
|
'shorturl' => $short1 = 'abcd',
|
2016-11-28 18:24:15 +01:00
|
|
|
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date1),
|
2016-10-03 09:43:49 +02:00
|
|
|
),
|
|
|
|
array(
|
2016-11-28 18:24:15 +01:00
|
|
|
'id' => 13,
|
2016-10-03 09:43:49 +02:00
|
|
|
'url' => $str . '2',
|
2018-08-14 13:39:31 +02:00
|
|
|
'shorturl' => $short2 = 'efgh',
|
2016-11-28 18:24:15 +01:00
|
|
|
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date2),
|
2016-10-03 09:43:49 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$processed = hook_isso_render_linklist($data, $conf);
|
2018-08-14 13:39:31 +02:00
|
|
|
// link_plugin should be added for the icon
|
|
|
|
$this->assertContains('<a href="?'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]);
|
|
|
|
$this->assertContains('<a href="?'. $short2 .'#isso-thread">', $processed['links'][1]['link_plugin'][0]);
|
2016-10-03 09:43:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test isso plugin when using search (shouldn't be displayed).
|
|
|
|
*/
|
2017-01-05 19:33:06 +01:00
|
|
|
public function testIssoNotDisplayedWhenSearch()
|
2016-10-03 09:43:49 +02:00
|
|
|
{
|
|
|
|
$conf = new ConfigManager('');
|
|
|
|
$conf->set('plugins.ISSO_SERVER', 'value');
|
|
|
|
|
|
|
|
$str = 'http://randomstr.com/test';
|
2016-11-28 16:17:25 +01:00
|
|
|
$date = '20161118_100001';
|
2016-10-03 09:43:49 +02:00
|
|
|
$data = array(
|
|
|
|
'title' => $str,
|
|
|
|
'links' => array(
|
|
|
|
array(
|
2016-11-28 18:24:15 +01:00
|
|
|
'id' => 12,
|
2016-10-03 09:43:49 +02:00
|
|
|
'url' => $str,
|
2018-08-14 13:39:31 +02:00
|
|
|
'shorturl' => $short1 = 'abcd',
|
2016-11-28 18:24:15 +01:00
|
|
|
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date),
|
2016-10-03 09:43:49 +02:00
|
|
|
)
|
|
|
|
),
|
|
|
|
'search_term' => $str
|
|
|
|
);
|
|
|
|
|
|
|
|
$processed = hook_isso_render_linklist($data, $conf);
|
|
|
|
|
2018-08-14 13:39:31 +02:00
|
|
|
// link_plugin should be added for the icon
|
|
|
|
$this->assertContains('<a href="?'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]);
|
2016-10-03 09:43:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test isso plugin without server configuration (shouldn't be displayed).
|
|
|
|
*/
|
2017-01-05 19:33:06 +01:00
|
|
|
public function testIssoWithoutConf()
|
2016-10-03 09:43:49 +02:00
|
|
|
{
|
|
|
|
$data = 'abc';
|
|
|
|
$conf = new ConfigManager('');
|
|
|
|
$processed = hook_isso_render_linklist($data, $conf);
|
|
|
|
$this->assertEquals($data, $processed);
|
|
|
|
}
|
|
|
|
}
|