1<?php
2
3/**
4 * Tests for functionality of the navi plugin
5 *
6 * @group plugin_navi
7 * @group plugins
8 *
9 */
10class basic_plugin_navi_test extends DokuWikiTest
11{
12
13    protected $pluginsEnabled = array('navi');
14
15    public function setUp()
16    {
17        parent::setUp();
18    }
19
20    public function tearDown()
21    {
22        parent::tearDown();
23    }
24
25    public function test_controlpage_simple()
26    {
27        // arrange
28        $controlpage = "  * [[a]]\n  * [[b]]\n    * [[c]]";
29        saveWikiText('controlpage', $controlpage, '');
30        saveWikiText('navi', '{{navi>controlpage}}', '');
31
32        // act
33        $info = array();
34        $actualHTML = p_render('xhtml', p_get_instructions('{{navi>controlpage}}'), $info);
35
36        // assert
37        $expectedHTML = '<div class="plugin__navi "><ul>
38<li class="level1 "><div class="li"><a href="/./doku.php?id=a" class="wikilink2" title="a" rel="nofollow" data-wiki-id="a">a</a></div>
39</li>
40<li class="level1 close"><div class="li"><a href="/./doku.php?id=b" class="wikilink2" title="b" rel="nofollow" data-wiki-id="b">b</a></div>
41</li>
42</ul>
43</div>';
44        $this->assertEquals($expectedHTML, $actualHTML);
45
46    }
47
48    public function test_controlpage_complex()
49    {
50        // arrange
51        $controlpage = "
52  * [[en:products:a:start|BasePage]]
53    * [[en:products:b:d:start|2nd-level Page with hidden child]]
54      * [[en:products:c:projects|hidden 3rd-level page]]
55    * [[en:products:b:archive:start|2nd-level pape]]
56    * [[en:products:c:start|current 2nd-level page with visible child]]
57      * [[en:products:d:start|visible 3rd-level page]]
58";
59        saveWikiText('controlpage', $controlpage, '');
60        saveWikiText('navi', '{{navi>controlpage}}', '');
61        global $ID, $INFO;
62
63        // act
64        $info = array();
65        $ID = 'en:products:c:start';
66        $INFO['id'] = 'en:products:c:start';
67        $actualHTML = p_render('xhtml', p_get_instructions('{{navi>controlpage}}'), $info);
68
69        $pq = phpQuery::newDocumentXHTML($actualHTML);
70
71        $actualPages = array();
72        foreach ($pq->find('a') as $page) {
73            $actualPages[] = $page->getAttribute('title');
74        }
75
76        $actualLiOpen = array();
77        foreach ($pq->find('li.open > div > a, li.open > div > span > a') as $page) {
78            $actualLiOpen[] = $page->getAttribute('title');
79        }
80
81        $actualLiClose = array();
82        foreach ($pq->find('li.close > div > a, li.close > div > span > a') as $page) {
83            $actualLiClose[] = $page->getAttribute('title');
84        }
85
86        $this->assertEquals(array(
87            0 => 'en:products:a:start',
88            1 => 'en:products:b:d:start',
89            2 => 'en:products:b:archive:start',
90            3 => 'en:products:c:start',
91            4 => 'en:products:d:start',
92        ), $actualPages, 'the correct pages in the correct order');
93        $this->assertEquals(array(
94            0 => 'en:products:a:start',
95            1 => 'en:products:c:start',
96        ), $actualLiOpen, 'the pages which have have children and are open should have the "open" class');
97        $this->assertEquals(array(
98            0 => 'en:products:b:d:start',
99        ), $actualLiClose, 'the pages which have have children, but are closed should have the "close" class');
100
101    }
102}
103