Skip to content

Commit

Permalink
Remove old $ID changes and add tests
Browse files Browse the repository at this point in the history
These changes to $ID became unnecessary a long time ago and can now
safely be removed. There was a pull request by selfthinker which is
implemented with this change: #8

This closes #8
  • Loading branch information
micgro42 committed Aug 18, 2016
1 parent 254be9b commit 9876597
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 12 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
@@ -0,0 +1,16 @@
# Config file for travis-ci.org

language: php
php:
- "7.0"
- "5.6"
- "5.5"
- "5.4"
- "5.3"
env:
matrix:
- DOKUWIKI=master
- DOKUWIKI=stable
before_install: wget https://raw.github.com/splitbrain/dokuwiki-travis/master/travis.sh
install: sh travis.sh
script: cd _test && phpunit --stderr --group plugin_navi
97 changes: 97 additions & 0 deletions _test/basicList.test.php
@@ -0,0 +1,97 @@
<?php

/**
* Tests for functionality of the navi plugin
*
* @group plugin_navi
* @group plugins
*
*/
class basic_plugin_navi_test extends DokuWikiTest {

protected $pluginsEnabled = array('navi');

public function setUp() {
parent::setUp();
}

public function tearDown() {
parent::tearDown();
}

public function test_controlpage_simple() {
// arrange
$controlpage = " * [[a]]\n * [[b]]\n * [[c]]";
saveWikiText('controlpage', $controlpage, '');
saveWikiText('navi', '{{navi>controlpage}}', '');

// act
$info = array();
$actualHTML = p_render('xhtml', p_get_instructions('{{navi>controlpage}}'), $info);

// assert
$expectedHTML = '<ul>
<li class="level1 "><div class="li"><a href="/./doku.php?id=a" class="wikilink2" title="a" rel="nofollow">a</a></div>
</li>
<li class="level1 close"><div class="li"><a href="/./doku.php?id=b" class="wikilink2" title="b" rel="nofollow">b</a></div>
</li>
</ul>
';
$this->assertEquals($expectedHTML, $actualHTML);

}

public function test_controlpage_complex() {
// arrange
$controlpage = "
* [[en:products:a:start|BasePage]]
* [[en:products:b:d:start|2nd-level Page with hidden child]]
* [[en:products:c:projects|hidden 3rd-level page]]
* [[en:products:b:archive:start|2nd-level pape]]
* [[en:products:c:start|current 2nd-level page with visible child]]
* [[en:products:d:start|visible 3rd-level page]]
";
saveWikiText('controlpage', $controlpage, '');
saveWikiText('navi', '{{navi>controlpage}}', '');
global $ID, $INFO;

// act
$info = array();
$ID = 'en:products:c:start';
$INFO['id'] = 'en:products:c:start';
$actualHTML = p_render('xhtml', p_get_instructions('{{navi>controlpage}}'), $info);

$pq = phpQuery::newDocumentXHTML($actualHTML);

$actualPages = array();
foreach ($pq->find('a') as $page) {
$actualPages[] = $page->getAttribute('title');
}

$actualLiOpen = array();
foreach ($pq->find('li.open > div > a, li.open > div > span > a') as $page) {
$actualLiOpen[] = $page->getAttribute('title');
}

$actualLiClose = array();
foreach ($pq->find('li.close > div > a, li.close > div > span > a') as $page) {
$actualLiClose[] = $page->getAttribute('title');
}

$this->assertEquals(array(
0 => 'en:products:a:start',
1 => 'en:products:b:d:start',
2 => 'en:products:b:archive:start',
3 => 'en:products:c:start',
4 => 'en:products:d:start',
), $actualPages, 'the correct pages in the correct order');
$this->assertEquals(array(
0 => 'en:products:a:start',
1 => 'en:products:c:start',
), $actualLiOpen, 'the pages which have have children and are open should have the "open" class');
$this->assertEquals(array(
0 => 'en:products:b:d:start',
), $actualLiClose, 'the pages which have have children, but are closed should have the "close" class');

}
}
12 changes: 0 additions & 12 deletions syntax.php
Expand Up @@ -97,7 +97,6 @@ function handle($match, $state, $pos, Doku_Handler $handler){
*/
function render($format, Doku_Renderer $R, $data) {
global $INFO;
global $ID;
$fn = $data[0];
$opt = $data[2];
$data = $data[1];
Expand All @@ -113,7 +112,6 @@ function render($format, Doku_Renderer $R, $data) {
if(isset($data[$INFO['id']])){
$parent = (array) $data[$INFO['id']]['parents']; // get the "path" of the page we're on currently
array_push($parent,$INFO['id']);
$current = $INFO['id'];
}elseif($opt == 'ns'){
$ns = $INFO['id'];

Expand All @@ -126,15 +124,13 @@ function render($format, Doku_Renderer $R, $data) {
// got a start page
$parent = (array) $data[$try]['parents'];
array_push($parent,$try);
$current = $try;
break;
}else{
// search for the first page matching the namespace
foreach($data as $key => $junk){
if(getNS($key) == $ns){
$parent = (array) $data[$key]['parents'];
array_push($parent,$key);
$current = $key;
break 2;
}
}
Expand All @@ -143,10 +139,6 @@ function render($format, Doku_Renderer $R, $data) {
}while($ns);
}

// we need the top ID for the renderer
$oldid = $ID;
$ID = $INFO['id'];

// create a correctly nested list (or so I hope)
$open = false;
$lvl = 1;
Expand Down Expand Up @@ -178,8 +170,6 @@ function render($format, Doku_Renderer $R, $data) {
// skip every non readable page
if(auth_quickaclcheck(cleanID($info['page'])) < AUTH_READ) continue;

$ID = $oldid;

if($info['lvl'] == $lvl){
if($open) $R->listitem_close();
$R->listitem_open($lvl.' '.$menuitem);
Expand All @@ -201,9 +191,7 @@ function render($format, Doku_Renderer $R, $data) {
}

$R->listcontent_open();
if(($format == 'xhtml') && ($info['page'] == $current)) $R->doc .= '<span class="current">';
$R->internallink(':'.$info['page'],$info['title']);
if(($format == 'xhtml') && ($info['page'] == $current)) $R->doc .= '</span>';
$R->listcontent_close();
}
while($lvl > 0){
Expand Down

0 comments on commit 9876597

Please sign in to comment.