Adding indexmenu version 2024-01-05 (ed06f21).
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
92cc8375f2
commit
f339727d60
766 changed files with 83299 additions and 0 deletions
35
plugins/55/indexmenu/_test/ActionTest.php
Normal file
35
plugins/55/indexmenu/_test/ActionTest.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Test namespace includes
|
||||
*
|
||||
* @group plugin_indexmenu
|
||||
* @group plugins
|
||||
*/
|
||||
class ActionTest extends DokuWikiTest
|
||||
{
|
||||
/**
|
||||
* Setup - enable and load the include plugin and create the test pages
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->pluginsEnabled[] = 'indexmenu';
|
||||
parent::setUp(); // this enables the include plugin
|
||||
// $this->helper = plugin_load('helper', 'include');
|
||||
|
||||
// global $conf;
|
||||
// $conf['hidepages'] = 'inclhidden:hidden';
|
||||
|
||||
// for testing hidden pages
|
||||
saveWikiText('ns2:bpage', "======H1======\nText", 'Sort different naturally/title/page');
|
||||
saveWikiText('ns2:apage', "======H3======\nText", 'Sort different naturally/title/page');
|
||||
saveWikiText('ns2:cpage', "======H2======\nText", 'Sort different naturally/title/page');
|
||||
|
||||
// pages on different levels
|
||||
saveWikiText('ns1:ns1:apage', 'Page on level 1', 'Created page on level 1');
|
||||
saveWikiText('ns1:lvl2:lvl3:lvl4:apage', 'Page on level 4', 'Created page on level 4');
|
||||
saveWikiText('ns1:ns2:apage', 'Page on level 2', 'Created page on level 2');
|
||||
saveWikiText('ns1:ns0:bpage', 'Page on level 2', 'Created page on level 2');
|
||||
}
|
||||
|
||||
}
|
345
plugins/55/indexmenu/_test/AjaxRequestsTest.php
Normal file
345
plugins/55/indexmenu/_test/AjaxRequestsTest.php
Normal file
|
@ -0,0 +1,345 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Test sorting
|
||||
*
|
||||
* Principle copied from _test/tests/lib/exe/ajax_requests.test.php
|
||||
*
|
||||
* @group ajax
|
||||
* @group plugin_indexmenu
|
||||
* @group plugins
|
||||
*/
|
||||
class AjaxRequestsTest extends DokuWikiTest
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->pluginsEnabled[] = 'indexmenu';
|
||||
parent::setUp(); // this enables the indexmenu plugin
|
||||
|
||||
//needed for 'tsort' to use First headings, sets title during search, otherwise as fallback page name used.
|
||||
global $conf;
|
||||
$conf['useheading'] = 'navigation';
|
||||
|
||||
|
||||
// for testing sorting pages
|
||||
saveWikiText('ns2:cpage', "======Bb======\nText", 'Sort different page/title/creation date');
|
||||
sleep(1); // ensure different timestamps for 'dsort'
|
||||
saveWikiText('ns2:bpage', "======Aa======\nText", 'Sort different page/title/creation date');
|
||||
sleep(1);
|
||||
saveWikiText('ns2:apage', "======Cc======\nText", 'Sort different page/title/creation date');
|
||||
|
||||
//ensures title is added to metadata of page
|
||||
idx_addPage('ns2:cpage');
|
||||
idx_addPage('ns2:bpage');
|
||||
idx_addPage('ns2:apage');
|
||||
|
||||
// pages on different levels
|
||||
saveWikiText('ns1:ns2:apage', "======Bb======\nPage on level 2", 'Created page on level 2');
|
||||
saveWikiText('ns1:ns1:apage', "======Ee======\nPage on level 2", 'Created page on level 2');
|
||||
saveWikiText('ns1:ns1:lvl3:lvl4:apage', "======Cc======\nPage on levl 4", 'Page on level 4');
|
||||
saveWikiText('ns1:ns1:start', "======Aa======\nPage on level 2", 'Startpage on level 2');
|
||||
saveWikiText('ns1:ns0:bpage', "======Aa2======\nPage on level 2", 'Created page on level 2');
|
||||
saveWikiText('ns1:apage', "======Dd======\nPage on level 1", 'Created page on level 1');
|
||||
|
||||
//ensures title is added to metadata
|
||||
idx_addPage('ns1:ns1:apage');
|
||||
idx_addPage('ns1:ns1:lvl3:lvl4:apage');
|
||||
idx_addPage('ns1:ns1:start');
|
||||
idx_addPage('ns1:ns2:apage');
|
||||
idx_addPage('ns1:ns0:bpage');
|
||||
idx_addPage('ns1:apage');
|
||||
}
|
||||
|
||||
/**
|
||||
* DataProvider for the builtin Ajax calls
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function indexmenuCalls()
|
||||
{
|
||||
return [
|
||||
// Call, POST parameters, result function
|
||||
[
|
||||
'indexmenu',
|
||||
AjaxRequestsTest::prepareParams(['level' => 1]),
|
||||
'expectedResultWiki'
|
||||
],
|
||||
[
|
||||
'indexmenu',
|
||||
AjaxRequestsTest::prepareParams(['ns' => 'ns2', 'level' => 1]),
|
||||
'expectedResultNs2PageSort'
|
||||
],
|
||||
[
|
||||
'indexmenu',
|
||||
AjaxRequestsTest::prepareParams(['ns' => 'ns2', 'level' => 1, 'sort' => 't']),
|
||||
'expectedResultNs2TitleSort'
|
||||
],
|
||||
[
|
||||
'indexmenu',
|
||||
AjaxRequestsTest::prepareParams(['ns' => 'ns2', 'level' => 1, 'sort' => 'd']),
|
||||
'expectedResultNs2CreationDateSort'
|
||||
],
|
||||
[
|
||||
'indexmenu',
|
||||
AjaxRequestsTest::prepareParams(['ns' => 'ns1', 'level' => 1, 'sort' => 't']),
|
||||
'expectedResultNs1TitleSort'
|
||||
],
|
||||
[
|
||||
'indexmenu',
|
||||
AjaxRequestsTest::prepareParams(['ns' => 'ns1', 'level' => 1, 'sort' => 't', 'nsort' => 1]),
|
||||
'expectedResultNs1TitleSortNamespaceSort'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider indexmenuCalls
|
||||
*
|
||||
* @param string $call
|
||||
* @param array $post
|
||||
* @param $expectedResult
|
||||
*/
|
||||
public function testBasicSorting($call, $post, $expectedResult)
|
||||
{
|
||||
$request = new TestRequest();
|
||||
$response = $request->post(['call' => $call] + $post, '/lib/exe/ajax.php');
|
||||
// $this->assertNotEquals("AJAX call '$call' unknown!\n", $response->getContent());
|
||||
|
||||
//var_export(json_decode($response->getContent()), true); // print as PHP array
|
||||
|
||||
$actualArray = json_decode($response->getContent(), true);
|
||||
unset($actualArray['debug']);
|
||||
unset($actualArray['sort']);
|
||||
unset($actualArray['opts']);
|
||||
|
||||
$this->assertEquals($this->$expectedResult(), $actualArray);
|
||||
|
||||
// $regexp: null, or regexp pattern to match
|
||||
// example: '/^<div class="odd type_d/'
|
||||
// if (!empty($regexp)) {
|
||||
// $this->assertRegExp($regexp, $response->getContent());
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
public function test_params()
|
||||
{
|
||||
// print_r(AjaxRequestsTest::prepareParams(['level' => 2]));
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public static function prepareParams($params = [])
|
||||
{
|
||||
$defaults = [
|
||||
'ns' => 'wiki',
|
||||
'req' => 'fancytree',
|
||||
'level' => 1,
|
||||
'nons' => 0,
|
||||
'nopg' => 0,
|
||||
'max' => 0,
|
||||
'skipns' => ['/^board:(first|second|third|fourth|fifth)$/'],
|
||||
'skipfile' => ['/(:start$)/'],
|
||||
'sort' => 0,
|
||||
'msort' => 0,
|
||||
'rsort' => 0,
|
||||
'nsort' => 0,
|
||||
'hsort' => 0,
|
||||
'init' => 1
|
||||
];
|
||||
$return = [];
|
||||
foreach ($defaults as $key => $default) {
|
||||
$return[$key] = $params[$key] ?? $default;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function expectedResultWiki()
|
||||
{
|
||||
return [
|
||||
'children' => [
|
||||
0 => [
|
||||
'title' => 'dokuwiki',
|
||||
'key' => 'wiki:dokuwiki',
|
||||
'hns' => false,
|
||||
'url' => '/./doku.php?id=wiki:dokuwiki'
|
||||
],
|
||||
1 => [
|
||||
'title' => 'syntax',
|
||||
'key' => 'wiki:syntax',
|
||||
'hns' => false,
|
||||
'url' => '/./doku.php?id=wiki:syntax'
|
||||
]
|
||||
]];
|
||||
}
|
||||
|
||||
public function expectedResultNs1()
|
||||
{
|
||||
return [
|
||||
'children' => [
|
||||
0 => [
|
||||
'title' => 'dokuwiki',
|
||||
'key' => 'wiki:dokuwiki',
|
||||
'hns' => false,
|
||||
'url' => '/./doku.php?id=wiki:dokuwiki'
|
||||
],
|
||||
1 => [
|
||||
'title' => 'syntax',
|
||||
'key' => 'wiki:syntax',
|
||||
'hns' => false,
|
||||
'url' => '/./doku.php?id=wiki:syntax'
|
||||
]
|
||||
]];
|
||||
}
|
||||
|
||||
public function expectedResultNs2PageSort()
|
||||
{
|
||||
return [
|
||||
'children' => [
|
||||
0 => [
|
||||
'title' => 'Cc',
|
||||
'key' => 'ns2:apage',
|
||||
'hns' => false,
|
||||
'url' => '/./doku.php?id=ns2:apage'
|
||||
],
|
||||
1 => [
|
||||
'title' => 'Aa',
|
||||
'key' => 'ns2:bpage',
|
||||
'hns' => false,
|
||||
'url' => '/./doku.php?id=ns2:bpage'
|
||||
],
|
||||
2 => [
|
||||
'title' => 'Bb',
|
||||
'key' => 'ns2:cpage',
|
||||
'hns' => false,
|
||||
'url' => '/./doku.php?id=ns2:cpage'
|
||||
]
|
||||
]];
|
||||
}
|
||||
|
||||
public function expectedResultNs2TitleSort()
|
||||
{
|
||||
return [
|
||||
'children' => [
|
||||
0 => [
|
||||
'title' => 'Aa',
|
||||
'key' => 'ns2:bpage',
|
||||
'hns' => false,
|
||||
'url' => '/./doku.php?id=ns2:bpage'
|
||||
],
|
||||
1 => [
|
||||
'title' => 'Bb',
|
||||
'key' => 'ns2:cpage',
|
||||
'hns' => false,
|
||||
'url' => '/./doku.php?id=ns2:cpage'
|
||||
],
|
||||
2 => [
|
||||
'title' => 'Cc',
|
||||
'key' => 'ns2:apage',
|
||||
'hns' => false,
|
||||
'url' => '/./doku.php?id=ns2:apage'
|
||||
]
|
||||
]];
|
||||
}
|
||||
|
||||
public function expectedResultNs2CreationDateSort()
|
||||
{
|
||||
return [
|
||||
'children' => [
|
||||
0 => [
|
||||
'title' => 'Bb',
|
||||
'key' => 'ns2:cpage',
|
||||
'hns' => false,
|
||||
'url' => '/./doku.php?id=ns2:cpage'
|
||||
],
|
||||
1 => [
|
||||
'title' => 'Aa',
|
||||
'key' => 'ns2:bpage',
|
||||
'hns' => false,
|
||||
'url' => '/./doku.php?id=ns2:bpage'
|
||||
],
|
||||
2 => [
|
||||
'title' => 'Cc',
|
||||
'key' => 'ns2:apage',
|
||||
'hns' => false,
|
||||
'url' => '/./doku.php?id=ns2:apage'
|
||||
]
|
||||
]];
|
||||
}
|
||||
|
||||
public function expectedResultNs1TitleSort()
|
||||
{
|
||||
return [
|
||||
'children' => [
|
||||
0 => [
|
||||
'title' => 'ns0',
|
||||
'key' => 'ns1:ns0:',
|
||||
'hns' => false,
|
||||
'folder' => true,
|
||||
'lazy' => true,
|
||||
'url' => false
|
||||
],
|
||||
1 => [
|
||||
'title' => 'Aa',
|
||||
'key' => 'ns1:ns1:',
|
||||
'hns' => 'ns1:ns1:start',
|
||||
'folder' => true,
|
||||
'lazy' => true,
|
||||
'url' => '/./doku.php?id=ns1:ns1:start'
|
||||
],
|
||||
2 => [
|
||||
'title' => 'ns2',
|
||||
'key' => 'ns1:ns2:',
|
||||
'hns' => false,
|
||||
'folder' => true,
|
||||
'lazy' => true,
|
||||
'url' => false
|
||||
],
|
||||
3 => [
|
||||
'title' => 'Dd',
|
||||
'key' => 'ns1:apage',
|
||||
'hns' => false,
|
||||
'url' => '/./doku.php?id=ns1:apage'
|
||||
]
|
||||
]];
|
||||
}
|
||||
|
||||
public function expectedResultNs1TitleSortNamespaceSort()
|
||||
{
|
||||
// 'nsort' let the sort explicitly use the namespace name as sort key.
|
||||
// 'nsort' + 'tsort' works only for nsort if head pages are used.
|
||||
return [
|
||||
'children' => [
|
||||
0 => [
|
||||
'title' => 'Aa',
|
||||
'key' => 'ns1:ns1:',
|
||||
'hns' => 'ns1:ns1:start',
|
||||
'folder' => true,
|
||||
'lazy' => true,
|
||||
'url' => '/./doku.php?id=ns1:ns1:start'
|
||||
],
|
||||
1 => [
|
||||
'title' => 'Dd',
|
||||
'key' => 'ns1:apage',
|
||||
'hns' => false,
|
||||
'url' => '/./doku.php?id=ns1:apage'
|
||||
],
|
||||
2 => [
|
||||
'title' => 'ns0',
|
||||
'key' => 'ns1:ns0:',
|
||||
'hns' => false,
|
||||
'folder' => true,
|
||||
'lazy' => true,
|
||||
'url' => false
|
||||
],
|
||||
3 => [
|
||||
'title' => 'ns2',
|
||||
'key' => 'ns1:ns2:',
|
||||
'hns' => false,
|
||||
'folder' => true,
|
||||
'lazy' => true,
|
||||
'url' => false
|
||||
]
|
||||
]];
|
||||
}
|
||||
}
|
86
plugins/55/indexmenu/_test/GeneralTest.php
Normal file
86
plugins/55/indexmenu/_test/GeneralTest.php
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\indexmenu\test;
|
||||
|
||||
use DokuWikiTest;
|
||||
|
||||
/**
|
||||
* General tests for the indexmenu plugin
|
||||
*
|
||||
* @group plugin_indexmenu
|
||||
* @group plugins
|
||||
*/
|
||||
class GeneralTest extends DokuWikiTest
|
||||
{
|
||||
|
||||
/**
|
||||
* Simple test to make sure the plugin.info.txt is in correct format
|
||||
*/
|
||||
public function testPluginInfo(): void
|
||||
{
|
||||
$file = __DIR__ . '/../plugin.info.txt';
|
||||
$this->assertFileExists($file);
|
||||
|
||||
$info = confToHash($file);
|
||||
|
||||
$this->assertArrayHasKey('base', $info);
|
||||
$this->assertArrayHasKey('author', $info);
|
||||
$this->assertArrayHasKey('email', $info);
|
||||
$this->assertArrayHasKey('date', $info);
|
||||
$this->assertArrayHasKey('name', $info);
|
||||
$this->assertArrayHasKey('desc', $info);
|
||||
$this->assertArrayHasKey('url', $info);
|
||||
|
||||
$this->assertEquals('indexmenu', $info['base']);
|
||||
$this->assertRegExp('/^https?:\/\//', $info['url']);
|
||||
$this->assertTrue(mail_isvalid($info['email']));
|
||||
$this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
|
||||
$this->assertTrue(false !== strtotime($info['date']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to ensure that every conf['...'] entry in conf/default.php has a corresponding meta['...'] entry in
|
||||
* conf/metadata.php.
|
||||
*/
|
||||
public function testPluginConf(): void
|
||||
{
|
||||
$conf_file = __DIR__ . '/../conf/default.php';
|
||||
$meta_file = __DIR__ . '/../conf/metadata.php';
|
||||
|
||||
if (!file_exists($conf_file) && !file_exists($meta_file)) {
|
||||
self::markTestSkipped('No config files exist -> skipping test');
|
||||
}
|
||||
|
||||
if (file_exists($conf_file)) {
|
||||
include($conf_file);
|
||||
}
|
||||
if (file_exists($meta_file)) {
|
||||
include($meta_file);
|
||||
}
|
||||
|
||||
$this->assertEquals(
|
||||
gettype($conf),
|
||||
gettype($meta),
|
||||
'Both ' . DOKU_PLUGIN . 'indexmenu/conf/default.php and ' . DOKU_PLUGIN . 'indexmenu/conf/metadata.php have to exist and contain the same keys.'
|
||||
);
|
||||
|
||||
if ($conf !== null && $meta !== null) {
|
||||
foreach ($conf as $key => $value) {
|
||||
$this->assertArrayHasKey(
|
||||
$key,
|
||||
$meta,
|
||||
'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'indexmenu/conf/metadata.php'
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($meta as $key => $value) {
|
||||
$this->assertArrayHasKey(
|
||||
$key,
|
||||
$conf,
|
||||
'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'indexmenu/conf/default.php'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
353
plugins/55/indexmenu/_test/IndexmenuSyntaxTest.php
Normal file
353
plugins/55/indexmenu/_test/IndexmenuSyntaxTest.php
Normal file
|
@ -0,0 +1,353 @@
|
|||
<?php
|
||||
|
||||
use DOMWrap\Document;
|
||||
|
||||
require_once DOKU_INC . 'inc/parser/xhtml.php';
|
||||
|
||||
/**
|
||||
* @group plugin_indexmenu
|
||||
*/
|
||||
class IndexmenuSyntaxTest extends DokuWikiTest
|
||||
{
|
||||
|
||||
public function setup(): void
|
||||
{
|
||||
// global $conf;
|
||||
$this->pluginsEnabled[] = 'indexmenu';
|
||||
parent::setup();
|
||||
|
||||
//$conf['plugin']['indexmenu']['headpage'] = '';
|
||||
//$conf['plugin']['indexmenu']['hide_headpage'] = false;
|
||||
|
||||
//saveWikiText('titleonly:sub:test', "====== Title ====== \n content", 'created');
|
||||
//saveWikiText('test', "====== Title ====== \n content", 'created');
|
||||
//idx_addPage('titleonly:sub:test');
|
||||
//idx_addPage('test');
|
||||
}
|
||||
|
||||
// public function __construct() {
|
||||
//// $this->exampleIndex = "{{indexmenu>:}}";
|
||||
//
|
||||
// parent::__construct();
|
||||
// }
|
||||
|
||||
/**
|
||||
* Create from list of values the output array of handle()
|
||||
*
|
||||
* @param array $values
|
||||
* @return array aligned similar to output of handle()
|
||||
*/
|
||||
private function createData($values)
|
||||
{
|
||||
|
||||
[
|
||||
$ns, $theme, $identifier, $nocookie, $navbar, $noscroll, $maxjs, $notoc, $jsajax, $context, $nomenu,
|
||||
$sort, $msort, $rsort, $nsort, $level, $nons, $nopg, $subnss, $max, $maxAjax, $js, $skipns, $skipfile,
|
||||
$skipnscombined, $skipfilecombined, $hsort, $headpage, $hide_headpage, $jsVersion
|
||||
] = $values;
|
||||
|
||||
return [
|
||||
$ns,
|
||||
[
|
||||
'theme' => $theme,
|
||||
'identifier' => $identifier,
|
||||
'nocookie' => $nocookie,
|
||||
'navbar' => $navbar,
|
||||
'noscroll' => $noscroll,
|
||||
'maxJs' => $maxjs,
|
||||
'notoc' => $notoc,
|
||||
'jsAjax' => $jsajax,
|
||||
'context' => $context,
|
||||
'nomenu' => $nomenu,
|
||||
],
|
||||
[
|
||||
'sort' => $sort,
|
||||
'msort' => $msort,
|
||||
'rsort' => $rsort,
|
||||
'nsort' => $nsort,
|
||||
'hsort' => $hsort,
|
||||
],
|
||||
[
|
||||
'level' => $level,
|
||||
'nons' => $nons,
|
||||
'nopg' => $nopg,
|
||||
'subnss' => $subnss,
|
||||
'max' => $max,
|
||||
'js' => $js,
|
||||
'skipns' => $skipns,
|
||||
'skipfile' => $skipfile,
|
||||
'skipnscombined' => $skipnscombined,
|
||||
'skipfilecombined' => $skipfilecombined,
|
||||
'headpage' => $headpage,
|
||||
'hide_headpage' => $hide_headpage,
|
||||
'maxajax' => $maxAjax,
|
||||
'navbar' => $navbar,
|
||||
'theme' => $theme
|
||||
],
|
||||
$jsVersion
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public static function someSyntaxes()
|
||||
{
|
||||
return [
|
||||
//root ns (empty is not recognized..)
|
||||
// [syntax, data]
|
||||
[
|
||||
"{{indexmenu>:}}",
|
||||
[
|
||||
'', 'default', 'random', false, false, false, 1, false, '', false, false,
|
||||
0, false, false, false, -1, false, false, [], 0, 1, false, '', '', [''], [''], false,
|
||||
":start:,:same:,:inside:", 1, 1
|
||||
]
|
||||
],
|
||||
//root ns, #levels=1, js renderer
|
||||
[
|
||||
"{{indexmenu>#1|js}}",
|
||||
[
|
||||
'', 'default', 'random', false, false, false, 1, false, '', false, false,
|
||||
0, false, false, false, 1, false, false, [], 0, 1, true, '', '', [''], [''], false,
|
||||
":start:,:same:,:inside:", 1, 1
|
||||
]
|
||||
],
|
||||
//root ns, #levels=2, all not js specific options (nocookie is from context)
|
||||
[
|
||||
"{{indexmenu>#2 test#6|navbar context tsort dsort msort hsort rsort nsort nons nopg}}",
|
||||
[
|
||||
'', 'default', 'random', true, true, false, 1, false, '&sort=t&msort=indexmenu_n&rsort=1&nsort=1&hsort=1&nopg=1', true, false,
|
||||
't', 'indexmenu_n', true, true, 2, true, true, [['test', 6]], 0, 1, false, '', '', [''], [''], true,
|
||||
":start:,:same:,:inside:", 1, 1
|
||||
]
|
||||
],
|
||||
//root ns, #levels=2, js renderer, all not js specific options
|
||||
[
|
||||
"{{indexmenu>#2 test#6|navbar js#bj_ubuntu.png context tsort dsort msort hsort rsort nsort nons nopg}}",
|
||||
[
|
||||
'', 'bj_ubuntu.png', 'random', true, true, false, 1, false, '&sort=t&msort=indexmenu_n&rsort=1&nsort=1&hsort=1&nopg=1', true, false,
|
||||
't', 'indexmenu_n', true, true, 2, true, true, [['test', 6]], 0, 1, true, '', '', [''], [''], true,
|
||||
":start:,:same:,:inside:", 1, 1
|
||||
]
|
||||
],
|
||||
//root ns, #levels=1, all options
|
||||
[
|
||||
"{{indexmenu>#1|navbar context nocookie noscroll notoc nomenu dsort msort#date:modified hsort rsort nsort nons nopg max#2#4 maxjs#3 id#54321}}",
|
||||
[
|
||||
'', 'default', 'random', true, true, true, 1, true, '&sort=d&msort=date modified&rsort=1&nsort=1&hsort=1&nopg=1', true, true,
|
||||
'd', 'date modified', true, true, 1, true, true, [], 0, 1, false, '', '', [''], [''], true,
|
||||
":start:,:same:,:inside:", 1, 1
|
||||
]
|
||||
],
|
||||
//root ns, #levels=1, js renderer, all options
|
||||
[
|
||||
"{{indexmenu>#1|js#bj_ubuntu.png navbar context nocookie noscroll notoc nomenu dsort msort#date:modified hsort rsort nsort nons nopg max#2#4 maxjs#3 id#54321}}",
|
||||
[
|
||||
'', 'bj_ubuntu.png', 54321, true, true, true, 3, true, '&sort=d&msort=date modified&rsort=1&nsort=1&hsort=1&nopg=1&max=4', true, true,
|
||||
'd', 'date modified', true, true, 1, true, true, [], 2, 4, true, '', '', [''], [''], true,
|
||||
":start:,:same:,:inside:", 1, 1
|
||||
]
|
||||
],
|
||||
//root ns, #levels=1, skipfile and ns
|
||||
|
||||
[
|
||||
"{{indexmenu>#1 test|skipfile+/(^myusers:spaces$|privatens:userss)/ skipns=/(^myusers:spaces$|privatens:users)/ id#ns}}",
|
||||
[
|
||||
'', 'default', 'random', false, false, false, 1, false, '&skipns=%3D/%28%5Emyusers%3Aspaces%24%7Cprivatens%3Ausers%29/&skipfile=%2B/%28%5Emyusers%3Aspaces%24%7Cprivatens%3Auserss%29/', false, false,
|
||||
0, false, false, false, 1, false, false, [['test', -1]], 0, 1, false, '=/(^myusers:spaces$|privatens:users)/',
|
||||
'+/(^myusers:spaces$|privatens:userss)/', ['/(^myusers:spaces$|privatens:users)/'], ['', '/(^myusers:spaces$|privatens:userss)/'], false,
|
||||
":start:,:same:,:inside:", 1, 1
|
||||
]
|
||||
],
|
||||
//root ns, #levels=1, js renderer, skipfile and ns
|
||||
[
|
||||
"{{indexmenu>#1 test|js skipfile=/(^myusers:spaces$|privatens:userss)/ skipns+/(^myusers:spaces$|privatens:userssss)/ id#ns}}",
|
||||
[
|
||||
'', 'default', 0, false, false, false, 1, false, '&skipns=%2B/%28%5Emyusers%3Aspaces%24%7Cprivatens%3Auserssss%29/&skipfile=%3D/%28%5Emyusers%3Aspaces%24%7Cprivatens%3Auserss%29/', false, false,
|
||||
0, false, false, false, 1, false, false, [['test', -1]], 0, 1, true, '+/(^myusers:spaces$|privatens:userssss)/',
|
||||
'=/(^myusers:spaces$|privatens:userss)/', ['', '/(^myusers:spaces$|privatens:userssss)/'], ['/(^myusers:spaces$|privatens:userss)/'], false,
|
||||
":start:,:same:,:inside:", 1, 1
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the syntax to options
|
||||
* expect: different combinations with or without js option, covers recognizing all syntax options
|
||||
*
|
||||
* @dataProvider someSyntaxes
|
||||
*/
|
||||
public function testHandle($syntax, $changedData)
|
||||
{
|
||||
$plugin = new syntax_plugin_indexmenu_indexmenu();
|
||||
|
||||
$null = new Doku_Handler();
|
||||
$result = $plugin->handle($syntax, 0, 40, $null);
|
||||
|
||||
//copy unique generated number, which is about 23 characters
|
||||
$len_id = strlen($result[1]['identifier']);
|
||||
if (!is_numeric($changedData[2]) && ($len_id > 18 && $len_id <= 23)) {
|
||||
$changedData[2] = $result[1]['identifier'];
|
||||
}
|
||||
$data = $this->createData($changedData);
|
||||
|
||||
$this->assertEquals($data, $result, 'Data array corrupted');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Data provider
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public static function differentNSs()
|
||||
{
|
||||
$pageInRoot = 'page';
|
||||
$pageInLvl1 = 'ns:page';
|
||||
$pageInLvl2 = 'ns1:ns2:page';
|
||||
return [
|
||||
//indexmenu on page at root level
|
||||
['{{indexmenu>|}}', '', [], $pageInRoot],
|
||||
['{{indexmenu>#1}}', '', [], $pageInRoot],
|
||||
['{{indexmenu>:}}', '', [], $pageInRoot],
|
||||
['{{indexmenu>.}}', '', [], $pageInRoot],
|
||||
['{{indexmenu>.:}}', '', [], $pageInRoot],
|
||||
['{{indexmenu>..}}', '', [], $pageInRoot],
|
||||
['{{indexmenu>..:}}', '', [], $pageInRoot],
|
||||
['{{indexmenu>myns}}', 'myns', [], $pageInRoot],
|
||||
['{{indexmenu>:myns}}', 'myns', [], $pageInRoot],
|
||||
['{{indexmenu>.myns}}', 'myns', [], $pageInRoot],
|
||||
['{{indexmenu>.:myns}}', 'myns', [], $pageInRoot],
|
||||
['{{indexmenu>..myns}}', 'myns', [], $pageInRoot],
|
||||
['{{indexmenu>..:myns}}', 'myns', [], $pageInRoot],
|
||||
|
||||
//indexmenu on page in a namespace
|
||||
['{{indexmenu>|}}', '', [], $pageInLvl1],
|
||||
['{{indexmenu>#1}}', '', [], $pageInLvl1],
|
||||
['{{indexmenu>:}}', '', [], $pageInLvl1],
|
||||
['{{indexmenu>.}}', 'ns', [], $pageInLvl1],
|
||||
['{{indexmenu>.:}}', 'ns', [], $pageInLvl1],
|
||||
['{{indexmenu>..}}', '', [], $pageInLvl1],
|
||||
['{{indexmenu>..:}}', '', [], $pageInLvl1],
|
||||
['{{indexmenu>myns}}', 'myns', [], $pageInLvl1], //was ns:myns
|
||||
['{{indexmenu>:myns}}', 'myns', [], $pageInLvl1],
|
||||
['{{indexmenu>.myns}}', 'ns:myns', [], $pageInLvl1],
|
||||
['{{indexmenu>.:myns}}', 'ns:myns', [], $pageInLvl1],
|
||||
['{{indexmenu>..myns}}', 'myns', [], $pageInLvl1],
|
||||
['{{indexmenu>..:myns}}', 'myns', [], $pageInLvl1],
|
||||
['{{indexmenu>myns:myns}}', 'myns:myns', [], $pageInLvl2],
|
||||
|
||||
//indexmenu on page in a namespace
|
||||
['{{indexmenu>|}}', '', [], $pageInLvl2],
|
||||
['{{indexmenu>#1}}', '', [], $pageInLvl2],
|
||||
['{{indexmenu>:}}', '', [], $pageInLvl2],
|
||||
['{{indexmenu>.}}', 'ns1:ns2', [], $pageInLvl2],
|
||||
['{{indexmenu>.:}}', 'ns1:ns2', [], $pageInLvl2],
|
||||
['{{indexmenu>..}}', '', [], $pageInLvl2], //strange indexmenu specific exception! TODO remove?
|
||||
['{{indexmenu>..:}}', 'ns1', [], $pageInLvl2],
|
||||
['{{indexmenu>myns}}', 'myns', [], $pageInLvl2], //was ns1:ns2:myns
|
||||
['{{indexmenu>:myns}}', 'myns', [], $pageInLvl2],
|
||||
['{{indexmenu>.myns}}', 'ns1:ns2:myns', [], $pageInLvl2],
|
||||
['{{indexmenu>.:myns}}', 'ns1:ns2:myns', [], $pageInLvl2],
|
||||
['{{indexmenu>..myns}}', 'ns1:myns', [], $pageInLvl2],
|
||||
['{{indexmenu>..:myns}}', 'ns1:myns', [], $pageInLvl2],
|
||||
['{{indexmenu>myns:myns}}', 'myns:myns', [], $pageInLvl2],
|
||||
|
||||
['{{indexmenu>..:..:myns}}', 'ns1:myns', [], 'ns1:ns2:ns3:page'],
|
||||
['{{indexmenu>0}}', '0', [], 'ns1:page'], //was ns1:0
|
||||
|
||||
//indexmenu on page at root level and subns
|
||||
['{{indexmenu> #1|}}', '', [], $pageInLvl2], //no subns, spaces before are removed
|
||||
['{{indexmenu>#1 #1}}', '', [['', 1]], $pageInLvl2],
|
||||
['{{indexmenu>: :}}', '', [['', -1]], $pageInLvl2],
|
||||
['{{indexmenu>. .}}', 'ns1:ns2', [['ns1:ns2', -1]], $pageInLvl2],
|
||||
['{{indexmenu>.: .:}}', 'ns1:ns2', [['ns1:ns2', -1]], $pageInLvl2],
|
||||
['{{indexmenu>.. ..}}', '', [['', -1]], $pageInLvl2],
|
||||
['{{indexmenu>..: ..:}}', 'ns1', [['ns1', -1]], $pageInLvl2],
|
||||
['{{indexmenu>myns myns}}', 'myns', [['myns', -1]], $pageInLvl2], //was ns1:ns2:myns
|
||||
['{{indexmenu>:myns :myns}}', 'myns', [['myns', -1]], $pageInLvl2],
|
||||
['{{indexmenu>.myns .myns}}', 'ns1:ns2:myns', [['ns1:ns2:myns', -1]], $pageInLvl2],
|
||||
['{{indexmenu>.:myns .:myns}}', 'ns1:ns2:myns', [['ns1:ns2:myns', -1]], $pageInLvl2],
|
||||
['{{indexmenu>..myns ..myns}}', 'ns1:myns', [['ns1:myns', -1]], $pageInLvl2],
|
||||
['{{indexmenu>..:myns ..myns}}', 'ns1:myns', [['ns1:myns', -1]], $pageInLvl2],
|
||||
['{{indexmenu>myns:myns myns:myns}}', 'myns:myns', [['myns:myns', -1]], $pageInLvl2],
|
||||
|
||||
//indexmenu on page in a namespace
|
||||
['{{indexmenu>|}}', '', [], $pageInLvl2],
|
||||
['{{indexmenu>#1}}', '', [], $pageInLvl2],
|
||||
['{{indexmenu>:}}', '', [], $pageInLvl2],
|
||||
['{{indexmenu>.}}', 'ns1:ns2', [], $pageInLvl2],
|
||||
['{{indexmenu>.:}}', 'ns1:ns2', [], $pageInLvl2],
|
||||
['{{indexmenu>..}}', '', [], $pageInLvl2], //strange indexmenu specific exception! TODO remove?
|
||||
['{{indexmenu>..:}}', 'ns1', [], $pageInLvl2],
|
||||
['{{indexmenu>myns:}}', 'myns', [], $pageInLvl2], //was ns1:ns2:myns
|
||||
['{{indexmenu>:myns:}}', 'myns', [], $pageInLvl2],
|
||||
['{{indexmenu>.myns:}}', 'ns1:ns2:myns', [], $pageInLvl2],
|
||||
['{{indexmenu>.:myns:}}', 'ns1:ns2:myns', [], $pageInLvl2],
|
||||
['{{indexmenu>..myns:}}', 'ns1:myns', [], $pageInLvl2],
|
||||
['{{indexmenu>..:myns:}}', 'ns1:myns', [], $pageInLvl2],
|
||||
['{{indexmenu>myns:myns:}}', 'myns:myns', [], $pageInLvl2],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the syntax to options
|
||||
* expect: different combinations with or without js option, covers recognizing all syntax options
|
||||
*
|
||||
* @dataProvider differentNSs
|
||||
*/
|
||||
public function testResolving($syntax, $expectedNs, $expectedSubNss, $pageWithIndexmenu)
|
||||
{
|
||||
global $ID;
|
||||
$ID = $pageWithIndexmenu;
|
||||
|
||||
$plugin = new syntax_plugin_indexmenu_indexmenu();
|
||||
|
||||
$null = new Doku_Handler();
|
||||
$result = $plugin->handle($syntax, 0, 40, $null);
|
||||
|
||||
$this->assertEquals($expectedNs, $result[0], 'check resolved ns');
|
||||
$this->assertEquals($expectedSubNss, $result[3]['subnss'], 'check resolved subNSs');
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendering for nonexisting namespace
|
||||
* expect: no paragraph due to no message set
|
||||
* expect: one paragraph, since message set
|
||||
* expect: contains namespace which replaced {{ns}}
|
||||
* expect: message contained rendered italic syntax
|
||||
*/
|
||||
public function testRenderEmptymsg()
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$noexistns = 'nonexisting:namespace';
|
||||
$emptyindexsyntax = "{{indexmenu>$noexistns}}";
|
||||
|
||||
$xhtml = new Doku_Renderer_xhtml();
|
||||
$plugin = new syntax_plugin_indexmenu_indexmenu();
|
||||
|
||||
$null = new Doku_Handler();
|
||||
$result = $plugin->handle($emptyindexsyntax, 0, 10, $null);
|
||||
|
||||
//no empty message
|
||||
$plugin->render('xhtml', $xhtml, $result);
|
||||
|
||||
$doc = (new Document())->html($xhtml->doc);
|
||||
$this->assertEquals(0, $doc->find('p')->count());
|
||||
|
||||
// Fill in empty message
|
||||
$conf['plugin']['indexmenu']['empty_msg'] = 'This namespace is //empty//: {{ns}}';
|
||||
$plugin->render('xhtml', $xhtml, $result);
|
||||
$doc = (new Document())->html($xhtml->doc);
|
||||
|
||||
$this->assertEquals(1, $doc->find('p')->count());
|
||||
// $this->assertEquals(1, $doc->find("p:contains($noexistns)")->count());
|
||||
$this->assertEquals(1, $doc->find("p em")->count());
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue