2016-10-03 09:43:49 +02:00
|
|
|
<?php
|
2021-04-05 09:39:34 +02:00
|
|
|
|
2018-12-04 23:17:23 +01:00
|
|
|
namespace Shaarli\Plugin\Isso;
|
2018-12-03 01:10:39 +01:00
|
|
|
|
2018-12-04 23:17:23 +01:00
|
|
|
use DateTime;
|
2020-01-17 21:34:12 +01:00
|
|
|
use Shaarli\Bookmark\Bookmark;
|
2017-03-03 23:06:12 +01:00
|
|
|
use Shaarli\Config\ConfigManager;
|
2018-12-04 00:26:50 +01:00
|
|
|
use Shaarli\Plugin\PluginManager;
|
2020-09-29 14:41:40 +02:00
|
|
|
use Shaarli\TestCase;
|
2016-10-03 09:43:49 +02:00
|
|
|
|
|
|
|
require_once 'plugins/isso/isso.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class PluginIssoTest
|
|
|
|
*
|
|
|
|
* Test the Isso plugin (comment system).
|
|
|
|
*/
|
2020-09-22 12:44:08 +02:00
|
|
|
class PluginIssoTest extends TestCase
|
2016-10-03 09:43:49 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Reset plugin path
|
|
|
|
*/
|
2020-09-22 12:44:08 +02:00
|
|
|
public function setUp(): void
|
2016-10-03 09:43:49 +02:00
|
|
|
{
|
|
|
|
PluginManager::$PLUGINS_PATH = 'plugins';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test Isso init without errors.
|
|
|
|
*/
|
2020-09-22 12:44:08 +02:00
|
|
|
public function testIssoInitNoError(): void
|
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.
|
|
|
|
*/
|
2020-09-22 12:44:08 +02:00
|
|
|
public function testIssoInitError(): void
|
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.
|
|
|
|
*/
|
2020-09-22 12:44:08 +02:00
|
|
|
public function testIssoDisplayed(): void
|
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';
|
2021-04-05 09:39:34 +02:00
|
|
|
$data = [
|
2016-10-03 09:43:49 +02:00
|
|
|
'title' => $str,
|
2021-04-05 09:39:34 +02:00
|
|
|
'links' => [
|
|
|
|
[
|
2016-11-28 18:24:15 +01:00
|
|
|
'id' => 12,
|
2016-10-03 09:43:49 +02:00
|
|
|
'url' => $str,
|
2020-01-17 21:34:12 +01:00
|
|
|
'created' => DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, $date),
|
2021-04-05 09:39:34 +02:00
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
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],
|
2021-04-05 09:39:34 +02:00
|
|
|
'data-isso-id="' . $data['links'][0]['id'] . '"'
|
2016-11-28 18:24:15 +01:00
|
|
|
));
|
|
|
|
$this->assertNotFalse(strpos(
|
|
|
|
$data['plugin_end_zone'][0],
|
2021-04-05 09:39:34 +02:00
|
|
|
'data-title="' . $data['links'][0]['id'] . '"'
|
2016-11-28 18:24:15 +01:00
|
|
|
));
|
2016-10-03 09:43:49 +02:00
|
|
|
$this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-17 21:34:12 +01:00
|
|
|
* Test isso plugin when multiple bookmarks are displayed (shouldn't be displayed).
|
2016-10-03 09:43:49 +02:00
|
|
|
*/
|
2020-09-22 12:44:08 +02:00
|
|
|
public function testIssoMultipleLinks(): void
|
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';
|
2021-04-05 09:39:34 +02:00
|
|
|
$data = [
|
2016-10-03 09:43:49 +02:00
|
|
|
'title' => $str,
|
2021-04-05 09:39:34 +02:00
|
|
|
'links' => [
|
|
|
|
[
|
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',
|
2020-01-17 21:34:12 +01:00
|
|
|
'created' => DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, $date1),
|
2021-04-05 09:39:34 +02:00
|
|
|
],
|
|
|
|
[
|
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',
|
2020-01-17 21:34:12 +01:00
|
|
|
'created' => DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, $date2),
|
2021-04-05 09:39:34 +02:00
|
|
|
],
|
|
|
|
]
|
|
|
|
];
|
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
|
2021-04-05 11:00:28 +02:00
|
|
|
$this->assertContainsPolyfill(
|
|
|
|
'<a href="/shaare/' . $short1 . '#isso-thread">',
|
|
|
|
$processed['links'][0]['link_plugin'][0]
|
|
|
|
);
|
|
|
|
$this->assertContainsPolyfill(
|
|
|
|
'<a href="/shaare/' . $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).
|
|
|
|
*/
|
2020-09-22 12:44:08 +02:00
|
|
|
public function testIssoNotDisplayedWhenSearch(): void
|
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';
|
2021-04-05 09:39:34 +02:00
|
|
|
$data = [
|
2016-10-03 09:43:49 +02:00
|
|
|
'title' => $str,
|
2021-04-05 09:39:34 +02:00
|
|
|
'links' => [
|
|
|
|
[
|
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',
|
2020-01-17 21:34:12 +01:00
|
|
|
'created' => DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, $date),
|
2021-04-05 09:39:34 +02:00
|
|
|
]
|
|
|
|
],
|
2016-10-03 09:43:49 +02:00
|
|
|
'search_term' => $str
|
2021-04-05 09:39:34 +02:00
|
|
|
];
|
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
|
2021-04-05 11:00:28 +02:00
|
|
|
$this->assertContainsPolyfill(
|
|
|
|
'<a href="/shaare/' . $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).
|
|
|
|
*/
|
2020-09-22 12:44:08 +02:00
|
|
|
public function testIssoWithoutConf(): void
|
2016-10-03 09:43:49 +02:00
|
|
|
{
|
|
|
|
$data = 'abc';
|
|
|
|
$conf = new ConfigManager('');
|
|
|
|
$processed = hook_isso_render_linklist($data, $conf);
|
|
|
|
$this->assertEquals($data, $processed);
|
|
|
|
}
|
|
|
|
}
|