1<?php
2
3/**
4 * Tests for functionality of the navi plugin
5 *
6 * @group plugin_navi
7 * @group plugins
8 *
9 */
10class external_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_with_external_link()
26    {
27        // arrange
28        $controlpage = "
29  * [[en:products:a:start|BasePage]]
30    * [[en:products:b:d:start|2nd-level Page with hidden child]]
31      * [[en:products:c:projects|hidden 3rd-level page]]
32    * [[en:products:b:archive:start|2nd-level pape]]
33    * [[en:products:c:start|current 2nd-level page with visible child]]
34      * [[https://www.example.org|Example Page]]
35";
36        saveWikiText('controlpage', $controlpage, '');
37        saveWikiText('navi', '{{navi>controlpage}}', '');
38        global $ID, $INFO;
39
40        // act
41        $info = array();
42        $ID = 'en:products:c:start';
43        $INFO['id'] = 'en:products:c:start';
44        $actualHTML = p_render('xhtml', p_get_instructions('{{navi>controlpage}}'), $info);
45//        print_r($actualHTML);
46
47        $pq = phpQuery::newDocumentXHTML($actualHTML);
48
49        $actualPages = array();
50        foreach ($pq->find('a') as $page) {
51            $actualPages[] = $page->getAttribute('title');
52        }
53
54        $actualLiOpen = array();
55        foreach ($pq->find('li.open > div > a, li.open > div > span > a') as $page) {
56            $actualLiOpen[] = $page->getAttribute('title');
57        }
58
59        $actualLiClose = array();
60        foreach ($pq->find('li.close > div > a, li.close > div > span > a') as $page) {
61            $actualLiClose[] = $page->getAttribute('title');
62        }
63
64        $this->assertEquals(array(
65            0 => 'en:products:a:start',
66            1 => 'en:products:b:d:start',
67            2 => 'en:products:b:archive:start',
68            3 => 'en:products:c:start',
69            4 => 'https://www.example.org',
70        ), $actualPages, 'the correct pages in the correct order');
71        $this->assertEquals(array(
72            0 => 'en:products:a:start',
73            1 => 'en:products:c:start',
74        ), $actualLiOpen, 'the pages which have have children and are open should have the "open" class');
75        $this->assertEquals(array(
76            0 => 'en:products:b:d:start',
77        ), $actualLiClose, 'the pages which have have children, but are closed should have the "close" class');
78
79    }
80}
81