1<?php
2
3namespace dokuwiki\plugin\navi\test;
4
5use DokuWikiTest;
6use phpQuery;
7
8
9/**
10 * Tests for functionality of the navi plugin
11 *
12 * @group plugin_navi
13 * @group plugins
14 *
15 */
16class ExternalLinksTest extends DokuWikiTest
17{
18
19    protected $pluginsEnabled = ['navi'];
20
21    public function test_controlpage_with_external_link()
22    {
23        // arrange
24        $controlpage = "
25  * [[en:products:a:start|BasePage]]
26    * [[en:products:b:d:start|2nd-level Page with hidden child]]
27      * [[en:products:c:projects|hidden 3rd-level page]]
28    * [[en:products:b:archive:start|2nd-level pape]]
29    * [[en:products:c:start|current 2nd-level page with visible child]]
30      * [[https://www.example.org|Example Page]]
31";
32        saveWikiText('controlpage', $controlpage, '');
33        saveWikiText('navi', '{{navi>controlpage}}', '');
34        global $ID, $INFO;
35
36        // act
37        $info = [];
38        $ID = 'en:products:c:start';
39        $INFO['id'] = 'en:products:c:start';
40        $actualHTML = p_render('xhtml', p_get_instructions('{{navi>controlpage}}'), $info);
41
42        if(class_exists('DOMWrap\Document')) {
43            $pq = (new \DOMWrap\Document())->html($actualHTML);
44        } else {
45            // deprecated
46            $pq = \phpQuery::newDocumentHTML($actualHTML);
47        }
48
49        $actualPages = [];
50        foreach ($pq->find('a') as $page) {
51            $actualPages[] = $page->getAttribute('title');
52        }
53
54        $actualLiOpen = [];
55        foreach ($pq->find('li.open > div > a, li.open > div > span > a') as $page) {
56            $actualLiOpen[] = $page->getAttribute('title');
57        }
58
59        $actualLiClose = [];
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([
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([
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([
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