2015-11-08 12:00:06 +01:00
|
|
|
<?php
|
2018-12-04 23:17:23 +01:00
|
|
|
namespace Shaarli\Plugin\Wallabag;
|
|
|
|
|
2017-03-03 23:06:12 +01:00
|
|
|
use Shaarli\Config\ConfigManager;
|
2018-12-04 00:26:50 +01:00
|
|
|
use Shaarli\Plugin\PluginManager;
|
2015-11-08 12:00:06 +01:00
|
|
|
|
|
|
|
require_once 'plugins/wallabag/wallabag.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class PluginWallabagTest
|
|
|
|
* Unit test for the Wallabag plugin
|
|
|
|
*/
|
2020-09-29 14:41:40 +02:00
|
|
|
class PluginWallabagTest extends \Shaarli\TestCase
|
2015-11-08 12:00:06 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Reset plugin path
|
|
|
|
*/
|
2020-09-26 15:08:39 +02:00
|
|
|
protected function setUp(): void
|
2015-11-08 12:00:06 +01:00
|
|
|
{
|
|
|
|
PluginManager::$PLUGINS_PATH = 'plugins';
|
|
|
|
}
|
|
|
|
|
2016-10-14 13:22:58 +02:00
|
|
|
/**
|
|
|
|
* Test wallabag init without errors.
|
|
|
|
*/
|
2017-01-05 19:33:06 +01:00
|
|
|
public function testWallabagInitNoError()
|
2016-10-14 13:22:58 +02:00
|
|
|
{
|
|
|
|
$conf = new ConfigManager('');
|
|
|
|
$conf->set('plugins.WALLABAG_URL', 'value');
|
|
|
|
$errors = wallabag_init($conf);
|
|
|
|
$this->assertEmpty($errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wallabag init with errors.
|
|
|
|
*/
|
2017-01-05 19:33:06 +01:00
|
|
|
public function testWallabagInitError()
|
2016-10-14 13:22:58 +02:00
|
|
|
{
|
|
|
|
$conf = new ConfigManager('');
|
|
|
|
$errors = wallabag_init($conf);
|
|
|
|
$this->assertNotEmpty($errors);
|
|
|
|
}
|
|
|
|
|
2015-11-08 12:00:06 +01:00
|
|
|
/**
|
|
|
|
* Test render_linklist hook.
|
|
|
|
*/
|
2017-01-05 19:33:06 +01:00
|
|
|
public function testWallabagLinklist()
|
2015-11-08 12:00:06 +01:00
|
|
|
{
|
2016-06-09 20:04:32 +02:00
|
|
|
$conf = new ConfigManager('');
|
2016-05-29 14:41:30 +02:00
|
|
|
$conf->set('plugins.WALLABAG_URL', 'value');
|
2015-11-08 12:00:06 +01:00
|
|
|
$str = 'http://randomstr.com/test';
|
2020-10-24 16:25:06 +02:00
|
|
|
$data = [
|
2015-11-08 12:00:06 +01:00
|
|
|
'title' => $str,
|
2020-10-24 16:25:06 +02:00
|
|
|
'links' => [
|
|
|
|
[
|
2015-11-08 12:00:06 +01:00
|
|
|
'url' => $str,
|
2020-10-24 16:25:06 +02:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'_LOGGEDIN_' => true,
|
|
|
|
];
|
2015-11-08 12:00:06 +01:00
|
|
|
|
2016-06-09 20:04:32 +02:00
|
|
|
$data = hook_wallabag_render_linklist($data, $conf);
|
2015-11-08 12:00:06 +01:00
|
|
|
$link = $data['links'][0];
|
|
|
|
// data shouldn't be altered
|
|
|
|
$this->assertEquals($str, $data['title']);
|
|
|
|
$this->assertEquals($str, $link['url']);
|
|
|
|
|
|
|
|
// plugin data
|
|
|
|
$this->assertEquals(1, count($link['link_plugin']));
|
2015-12-22 10:20:27 +01:00
|
|
|
$this->assertNotFalse(strpos($link['link_plugin'][0], urlencode($str)));
|
2016-05-29 14:41:30 +02:00
|
|
|
$this->assertNotFalse(strpos($link['link_plugin'][0], $conf->get('plugins.WALLABAG_URL')));
|
2015-11-08 12:00:06 +01:00
|
|
|
}
|
2020-10-24 16:25:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test render_linklist hook while logged out: no change.
|
|
|
|
*/
|
|
|
|
public function testWallabagLinklistLoggedOut(): void
|
|
|
|
{
|
|
|
|
$conf = new ConfigManager('');
|
|
|
|
$str = 'http://randomstr.com/test';
|
|
|
|
$data = [
|
|
|
|
'title' => $str,
|
|
|
|
'links' => [
|
|
|
|
[
|
|
|
|
'url' => $str,
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'_LOGGEDIN_' => false,
|
|
|
|
];
|
|
|
|
|
|
|
|
$result = hook_wallabag_render_linklist($data, $conf);
|
|
|
|
|
|
|
|
static::assertSame($data, $result);
|
|
|
|
}
|
2015-11-08 12:00:06 +01:00
|
|
|
}
|