2015-11-07 16:13:08 +01:00
|
|
|
<?php
|
2021-04-05 09:39:34 +02:00
|
|
|
|
2018-12-04 23:17:23 +01:00
|
|
|
namespace Shaarli\Plugin\Qrcode;
|
|
|
|
|
2015-11-07 16:13:08 +01:00
|
|
|
/**
|
2017-01-05 19:33:06 +01:00
|
|
|
* PluginQrcodeTest.php
|
2015-11-07 16:13:08 +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-07 16:13:08 +01:00
|
|
|
require_once 'plugins/qrcode/qrcode.php';
|
|
|
|
|
|
|
|
/**
|
2017-01-05 19:33:06 +01:00
|
|
|
* Class PluginQrcodeTest
|
2015-11-07 16:13:08 +01:00
|
|
|
* Unit test for the QR-Code plugin
|
|
|
|
*/
|
2020-09-29 14:41:40 +02:00
|
|
|
class PluginQrcodeTest extends \Shaarli\TestCase
|
2015-11-07 16:13:08 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Reset plugin path
|
|
|
|
*/
|
2020-09-26 15:08:39 +02:00
|
|
|
protected function setUp(): void
|
2018-10-13 00:35:47 +02:00
|
|
|
{
|
2015-11-07 16:13:08 +01:00
|
|
|
PluginManager::$PLUGINS_PATH = 'plugins';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test render_linklist hook.
|
|
|
|
*/
|
2017-01-05 19:33:06 +01:00
|
|
|
public function testQrcodeLinklist()
|
2015-11-07 16:13:08 +01:00
|
|
|
{
|
|
|
|
$str = 'http://randomstr.com/test';
|
2021-04-05 09:39:34 +02:00
|
|
|
$data = [
|
2015-11-07 16:13:08 +01:00
|
|
|
'title' => $str,
|
2021-04-05 09:39:34 +02:00
|
|
|
'links' => [
|
|
|
|
[
|
2015-12-22 10:24:31 +01:00
|
|
|
'url' => $str,
|
2021-04-05 09:39:34 +02:00
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
2015-11-07 16:13:08 +01:00
|
|
|
|
|
|
|
$data = hook_qrcode_render_linklist($data);
|
|
|
|
$link = $data['links'][0];
|
|
|
|
// data shouldn't be altered
|
|
|
|
$this->assertEquals($str, $data['title']);
|
2015-12-22 10:24:31 +01:00
|
|
|
$this->assertEquals($str, $link['url']);
|
2015-11-07 16:13:08 +01:00
|
|
|
|
|
|
|
// plugin data
|
|
|
|
$this->assertEquals(1, count($link['link_plugin']));
|
|
|
|
$this->assertNotFalse(strpos($link['link_plugin'][0], $str));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test render_footer hook.
|
|
|
|
*/
|
2017-01-05 19:33:06 +01:00
|
|
|
public function testQrcodeFooter()
|
2015-11-07 16:13:08 +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-07 16:13:08 +01:00
|
|
|
|
|
|
|
$data = hook_qrcode_render_footer($data);
|
|
|
|
$this->assertEquals($str, $data[$str]);
|
|
|
|
$this->assertEquals(1, count($data['js_files']));
|
|
|
|
|
2021-04-05 09:39:34 +02:00
|
|
|
$data = [$str => $str];
|
2015-11-07 16:13:08 +01:00
|
|
|
$data['_PAGE_'] = $str;
|
|
|
|
$this->assertEquals($str, $data[$str]);
|
|
|
|
$this->assertArrayNotHasKey('js_files', $data);
|
|
|
|
}
|
|
|
|
}
|