xref: /plugin/simplenavi/_test/SimplenaviTest.php (revision d8ce5486268fd1c02234429a87c5de7aaa6425c7)
1*d8ce5486SAndreas Gohr<?php
2*d8ce5486SAndreas Gohr
3*d8ce5486SAndreas Gohrnamespace dokuwiki\plugin\simplenavi\test;
4*d8ce5486SAndreas Gohr
5*d8ce5486SAndreas Gohruse DokuWikiTest;
6*d8ce5486SAndreas Gohruse TestRequest;
7*d8ce5486SAndreas Gohr
8*d8ce5486SAndreas Gohr/**
9*d8ce5486SAndreas Gohr * General tests for the simplenavi plugin
10*d8ce5486SAndreas Gohr *
11*d8ce5486SAndreas Gohr * @author  Michael Große <grosse@cosmocode.de>
12*d8ce5486SAndreas Gohr *
13*d8ce5486SAndreas Gohr * @group plugin_simplenavi
14*d8ce5486SAndreas Gohr * @group plugins
15*d8ce5486SAndreas Gohr */
16*d8ce5486SAndreas Gohrclass SimplenaviTest extends DokuWikiTest
17*d8ce5486SAndreas Gohr{
18*d8ce5486SAndreas Gohr
19*d8ce5486SAndreas Gohr    protected $pluginsEnabled = array('simplenavi');
20*d8ce5486SAndreas Gohr
21*d8ce5486SAndreas Gohr    public function setUp(): void
22*d8ce5486SAndreas Gohr    {
23*d8ce5486SAndreas Gohr        parent::setUp();
24*d8ce5486SAndreas Gohr        saveWikiText('sidebar', '{{simplenavi>}}', 'create test sidebar');
25*d8ce5486SAndreas Gohr        saveWikiText('namespace1:foo', 'bar', 'foobar');
26*d8ce5486SAndreas Gohr        saveWikiText('namespace2:foo', 'bar', 'foobar');
27*d8ce5486SAndreas Gohr        saveWikiText('namespace12:foo', 'bar', 'foobar');
28*d8ce5486SAndreas Gohr        saveWikiText('namespace123:foo', 'bar', 'foobar');
29*d8ce5486SAndreas Gohr        saveWikiText('namespace21:foo', 'bar', 'foobar');
30*d8ce5486SAndreas Gohr
31*d8ce5486SAndreas Gohr    }
32*d8ce5486SAndreas Gohr
33*d8ce5486SAndreas Gohr    /**
34*d8ce5486SAndreas Gohr     * @covers syntax_plugin_simplenavi
35*d8ce5486SAndreas Gohr     */
36*d8ce5486SAndreas Gohr    public function testOutputNatural()
37*d8ce5486SAndreas Gohr    {
38*d8ce5486SAndreas Gohr        global $ID, $conf;
39*d8ce5486SAndreas Gohr        $conf['plugin']['simplenavi']['sort'] = 'natural';
40*d8ce5486SAndreas Gohr
41*d8ce5486SAndreas Gohr        $ID = 'wiki:start';
42*d8ce5486SAndreas Gohr        $request = new TestRequest();
43*d8ce5486SAndreas Gohr        $input = [
44*d8ce5486SAndreas Gohr            'id' => 'namespace1:foo',
45*d8ce5486SAndreas Gohr        ];
46*d8ce5486SAndreas Gohr        saveWikiText('wiki:start', 'some text', 'Test init');
47*d8ce5486SAndreas Gohr        $response = $request->post($input);
48*d8ce5486SAndreas Gohr        $naviBegin = strpos($response->getContent(), '<!-- ********** ASIDE ********** -->') + 36;
49*d8ce5486SAndreas Gohr        $naviEnd = strpos($response->getContent(), '<!-- /aside -->');
50*d8ce5486SAndreas Gohr        $navi = substr($response->getContent(), $naviBegin, $naviEnd - $naviBegin);
51*d8ce5486SAndreas Gohr        $navilines = explode("\n", $navi);
52*d8ce5486SAndreas Gohr        $listlines = [];
53*d8ce5486SAndreas Gohr        foreach ($navilines as $line) {
54*d8ce5486SAndreas Gohr            if (substr($line, 0, 4) != '<li ') continue;
55*d8ce5486SAndreas Gohr            if (strpos($line, 'namespace') === false) continue;
56*d8ce5486SAndreas Gohr            $listlines[] = $line;
57*d8ce5486SAndreas Gohr        }
58*d8ce5486SAndreas Gohr
59*d8ce5486SAndreas Gohr        $this->assertTrue(
60*d8ce5486SAndreas Gohr            strpos($listlines[0], 'href="/./doku.php?id=namespace1:start"') !== false,
61*d8ce5486SAndreas Gohr            'namespace1 should be before other namespaces and espacially before its subpages and namespaces'
62*d8ce5486SAndreas Gohr        );
63*d8ce5486SAndreas Gohr        $this->assertTrue(
64*d8ce5486SAndreas Gohr            strpos($listlines[1], 'href="/./doku.php?id=namespace1:foo"') !== false,
65*d8ce5486SAndreas Gohr            'level2 should follow open level1'
66*d8ce5486SAndreas Gohr        );
67*d8ce5486SAndreas Gohr        $this->assertTrue(
68*d8ce5486SAndreas Gohr            strpos($listlines[2], 'href="/./doku.php?id=namespace2:start"') !== false,
69*d8ce5486SAndreas Gohr            'namespace2 should be after namespace1 and its pages.'
70*d8ce5486SAndreas Gohr        );
71*d8ce5486SAndreas Gohr        $this->assertTrue(
72*d8ce5486SAndreas Gohr            strpos($listlines[3], 'href="/./doku.php?id=namespace12:start"') !== false,
73*d8ce5486SAndreas Gohr            'namespace12 should be after namespace2.'
74*d8ce5486SAndreas Gohr        );
75*d8ce5486SAndreas Gohr        $this->assertTrue(
76*d8ce5486SAndreas Gohr            strpos($listlines[4], 'href="/./doku.php?id=namespace21:start"') !== false,
77*d8ce5486SAndreas Gohr            'namespace21 should be after namespace12.'
78*d8ce5486SAndreas Gohr        );
79*d8ce5486SAndreas Gohr        $this->assertTrue(
80*d8ce5486SAndreas Gohr            strpos($listlines[5], 'href="/./doku.php?id=namespace123:start"') !== false,
81*d8ce5486SAndreas Gohr            'namespace123 should be after namespace21.'
82*d8ce5486SAndreas Gohr        );
83*d8ce5486SAndreas Gohr    }
84*d8ce5486SAndreas Gohr
85*d8ce5486SAndreas Gohr    /**
86*d8ce5486SAndreas Gohr     * @covers syntax_plugin_simplenavi
87*d8ce5486SAndreas Gohr     */
88*d8ce5486SAndreas Gohr    public function testOutputAscii()
89*d8ce5486SAndreas Gohr    {
90*d8ce5486SAndreas Gohr        global $ID, $conf;
91*d8ce5486SAndreas Gohr        $conf['plugin']['simplenavi']['sort'] = 'ascii';
92*d8ce5486SAndreas Gohr
93*d8ce5486SAndreas Gohr        $ID = 'wiki:start';
94*d8ce5486SAndreas Gohr        $request = new TestRequest();
95*d8ce5486SAndreas Gohr        $input = [
96*d8ce5486SAndreas Gohr            'id' => 'namespace1:foo',
97*d8ce5486SAndreas Gohr        ];
98*d8ce5486SAndreas Gohr        saveWikiText('wiki:start', 'some text', 'Test init');
99*d8ce5486SAndreas Gohr        $response = $request->post($input);
100*d8ce5486SAndreas Gohr        $naviBegin = strpos($response->getContent(), '<!-- ********** ASIDE ********** -->') + 36;
101*d8ce5486SAndreas Gohr        $naviEnd = strpos($response->getContent(), '<!-- /aside -->');
102*d8ce5486SAndreas Gohr        $navi = substr($response->getContent(), $naviBegin, $naviEnd - $naviBegin);
103*d8ce5486SAndreas Gohr        $navilines = explode("\n", $navi);
104*d8ce5486SAndreas Gohr        $listlines = [];
105*d8ce5486SAndreas Gohr        foreach ($navilines as $line) {
106*d8ce5486SAndreas Gohr            if (substr($line, 0, 4) != '<li ') continue;
107*d8ce5486SAndreas Gohr            if (strpos($line, 'namespace') === false) continue;
108*d8ce5486SAndreas Gohr            $listlines[] = $line;
109*d8ce5486SAndreas Gohr        }
110*d8ce5486SAndreas Gohr
111*d8ce5486SAndreas Gohr        $this->assertTrue(
112*d8ce5486SAndreas Gohr            strpos($listlines[0], 'href="/./doku.php?id=namespace1:start"') !== false,
113*d8ce5486SAndreas Gohr            'namespace1 should be before other namespaces and espacially before its subpages and namespaces'
114*d8ce5486SAndreas Gohr        );
115*d8ce5486SAndreas Gohr        $this->assertTrue(
116*d8ce5486SAndreas Gohr            strpos($listlines[1], 'href="/./doku.php?id=namespace1:foo"') !== false,
117*d8ce5486SAndreas Gohr            'level2 should follow open level1.'
118*d8ce5486SAndreas Gohr        );
119*d8ce5486SAndreas Gohr        $this->assertTrue(
120*d8ce5486SAndreas Gohr            strpos($listlines[2], 'href="/./doku.php?id=namespace12:start"') !== false,
121*d8ce5486SAndreas Gohr            'namespace12 should be after namespace1 and its pages.'
122*d8ce5486SAndreas Gohr        );
123*d8ce5486SAndreas Gohr        $this->assertTrue(
124*d8ce5486SAndreas Gohr            strpos($listlines[3], 'href="/./doku.php?id=namespace123:start"') !== false,
125*d8ce5486SAndreas Gohr            'namespace123 should be after namespace12.'
126*d8ce5486SAndreas Gohr        );
127*d8ce5486SAndreas Gohr        $this->assertTrue(strpos(
128*d8ce5486SAndreas Gohr                $listlines[4], 'href="/./doku.php?id=namespace2:start"') !== false,
129*d8ce5486SAndreas Gohr            'namespace2 should be after namespace123.'
130*d8ce5486SAndreas Gohr        );
131*d8ce5486SAndreas Gohr        $this->assertTrue(
132*d8ce5486SAndreas Gohr            strpos($listlines[5], 'href="/./doku.php?id=namespace21:start"') !== false,
133*d8ce5486SAndreas Gohr            'namespace21 should be after namespace2.'
134*d8ce5486SAndreas Gohr        );
135*d8ce5486SAndreas Gohr    }
136*d8ce5486SAndreas Gohr
137*d8ce5486SAndreas Gohr}
138*d8ce5486SAndreas Gohr
139*d8ce5486SAndreas Gohr
140*d8ce5486SAndreas Gohr
141