2015-11-08 12:40:14 +01:00
|
|
|
<?php
|
2021-04-05 09:39:34 +02:00
|
|
|
|
2018-12-04 23:17:23 +01:00
|
|
|
namespace Shaarli\Plugin\Addlink;
|
2015-11-08 12:40:14 +01:00
|
|
|
|
2018-12-04 00:26:50 +01:00
|
|
|
use Shaarli\Plugin\PluginManager;
|
2020-07-06 08:04:35 +02:00
|
|
|
use Shaarli\Render\TemplatePage;
|
2018-12-04 00:02:17 +01:00
|
|
|
|
2015-11-08 12:40:14 +01:00
|
|
|
require_once 'plugins/addlink_toolbar/addlink_toolbar.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit test for the Addlink toolbar plugin
|
|
|
|
*/
|
2020-09-29 14:41:40 +02:00
|
|
|
class PluginAddlinkTest extends \Shaarli\TestCase
|
2015-11-08 12:40:14 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Reset plugin path.
|
|
|
|
*/
|
2020-09-26 15:08:39 +02:00
|
|
|
protected function setUp(): void
|
2015-11-08 12:40:14 +01:00
|
|
|
{
|
|
|
|
PluginManager::$PLUGINS_PATH = 'plugins';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test render_header hook while logged in.
|
|
|
|
*/
|
2017-01-05 19:33:06 +01:00
|
|
|
public function testAddlinkHeaderLoggedIn()
|
2015-11-08 12:40:14 +01:00
|
|
|
{
|
|
|
|
$str = 'stuff';
|
2021-04-05 09:39:34 +02:00
|
|
|
$data = [$str => $str];
|
2020-07-06 08:04:35 +02:00
|
|
|
$data['_PAGE_'] = TemplatePage::LINKLIST;
|
2015-11-08 12:40:14 +01:00
|
|
|
$data['_LOGGEDIN_'] = true;
|
2020-07-26 14:43:10 +02:00
|
|
|
$data['_BASE_PATH_'] = '/subfolder';
|
2015-11-08 12:40:14 +01:00
|
|
|
|
|
|
|
$data = hook_addlink_toolbar_render_header($data);
|
|
|
|
$this->assertEquals($str, $data[$str]);
|
|
|
|
$this->assertEquals(1, count($data['fields_toolbar']));
|
|
|
|
|
2021-04-05 09:39:34 +02:00
|
|
|
$data = [$str => $str];
|
2015-11-08 12:40:14 +01:00
|
|
|
$data['_PAGE_'] = $str;
|
|
|
|
$data['_LOGGEDIN_'] = true;
|
2020-07-26 14:43:10 +02:00
|
|
|
$data['_BASE_PATH_'] = '/subfolder';
|
|
|
|
|
2015-11-08 12:40:14 +01:00
|
|
|
$data = hook_addlink_toolbar_render_header($data);
|
|
|
|
$this->assertEquals($str, $data[$str]);
|
|
|
|
$this->assertArrayNotHasKey('fields_toolbar', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test render_header hook while logged out.
|
|
|
|
*/
|
2017-01-05 19:33:06 +01:00
|
|
|
public function testAddlinkHeaderLoggedOut()
|
2015-11-08 12:40:14 +01:00
|
|
|
{
|
|
|
|
$str = 'stuff';
|
2021-04-05 09:39:34 +02:00
|
|
|
$data = [$str => $str];
|
2020-07-06 08:04:35 +02:00
|
|
|
$data['_PAGE_'] = TemplatePage::LINKLIST;
|
2015-11-08 12:40:14 +01:00
|
|
|
$data['_LOGGEDIN_'] = false;
|
2020-07-26 14:43:10 +02:00
|
|
|
$data['_BASE_PATH_'] = '/subfolder';
|
2015-11-08 12:40:14 +01:00
|
|
|
|
|
|
|
$data = hook_addlink_toolbar_render_header($data);
|
|
|
|
$this->assertEquals($str, $data[$str]);
|
|
|
|
$this->assertArrayNotHasKey('fields_toolbar', $data);
|
|
|
|
}
|
|
|
|
}
|