xref: /plugin/simplenavi/_test/SimplenaviTest.php (revision e58e2f72dd917848130cf0286238cd1317212579)
1d8ce5486SAndreas Gohr<?php
2d8ce5486SAndreas Gohr
3d8ce5486SAndreas Gohrnamespace dokuwiki\plugin\simplenavi\test;
4d8ce5486SAndreas Gohr
5d8ce5486SAndreas Gohruse DokuWikiTest;
6d8ce5486SAndreas Gohruse TestRequest;
7d8ce5486SAndreas Gohr
8d8ce5486SAndreas Gohr/**
9d8ce5486SAndreas Gohr * General tests for the simplenavi plugin
10d8ce5486SAndreas Gohr *
11d8ce5486SAndreas Gohr * @author  Michael Große <grosse@cosmocode.de>
12d8ce5486SAndreas Gohr *
13d8ce5486SAndreas Gohr * @group plugin_simplenavi
14d8ce5486SAndreas Gohr * @group plugins
15d8ce5486SAndreas Gohr */
16d8ce5486SAndreas Gohrclass SimplenaviTest extends DokuWikiTest
17d8ce5486SAndreas Gohr{
18d8ce5486SAndreas Gohr
19d8ce5486SAndreas Gohr    protected $pluginsEnabled = array('simplenavi');
20d8ce5486SAndreas Gohr
21d8ce5486SAndreas Gohr    public function setUp(): void
22d8ce5486SAndreas Gohr    {
23d8ce5486SAndreas Gohr        parent::setUp();
24d8ce5486SAndreas Gohr        saveWikiText('sidebar', '{{simplenavi>}}', 'create test sidebar');
25e75a33bfSAndreas Gohr
26e75a33bfSAndreas Gohr        $pages = [
27*e58e2f72SAndreas Gohr            ['foo', 'Foo Page'],
28e75a33bfSAndreas Gohr            ['namespace1:start', 'ZZZ Namespace 1 Start'],
29e75a33bfSAndreas Gohr            ['namespace2:foo', 'Namespace 2 Foo'],
30e75a33bfSAndreas Gohr            ['namespace2', 'Namespace 2 Start'],
31e75a33bfSAndreas Gohr            ['namespace12:foo', 'Namespace 12 Foo'],
32e75a33bfSAndreas Gohr            ['namespace12:start', 'Namespace 12 Start'],
33e75a33bfSAndreas Gohr            ['namespace123:namespace123', 'AAA Namespace 123 Start'],
34e75a33bfSAndreas Gohr            ['namespace123:foo', 'Namespace 123 Foo'],
35e75a33bfSAndreas Gohr            ['namespace123:deep:start', 'Namespace 123 Deep Start'],
36e75a33bfSAndreas Gohr            ['namespace123:deep:foo', 'Namespace 123 Deep Foo'],
37e75a33bfSAndreas Gohr            ['namespace21:foo', 'Namespace 21 Foo'],
38e75a33bfSAndreas Gohr            ['namespace21:start', 'Namespace 21 Start'],
39e75a33bfSAndreas Gohr        ];
40e75a33bfSAndreas Gohr
41e75a33bfSAndreas Gohr        foreach ($pages as $page) {
42e75a33bfSAndreas Gohr            saveWikiText('simplenavi:' . $page[0], '====== ' . $page[1] . ' ======', 'create test page');
43e75a33bfSAndreas Gohr        }
44e75a33bfSAndreas Gohr
45e75a33bfSAndreas Gohr    }
46e75a33bfSAndreas Gohr
47e75a33bfSAndreas Gohr    public function dataProvider() {
48e75a33bfSAndreas Gohr
49e75a33bfSAndreas Gohr        yield [
50e75a33bfSAndreas Gohr            'set' => 'by ID, all branches closed',
51e75a33bfSAndreas Gohr            'titlesort' => false,
52e75a33bfSAndreas Gohr            'natsort' => false,
53*e58e2f72SAndreas Gohr            'nsfirst' => false,
54*e58e2f72SAndreas Gohr            'current' => 'simplenavi:page',
55e75a33bfSAndreas Gohr            'expect' => [
56*e58e2f72SAndreas Gohr                'simplenavi:foo',
57e75a33bfSAndreas Gohr                'simplenavi:namespace1:start',
58e75a33bfSAndreas Gohr                'simplenavi:namespace12:start',
59e75a33bfSAndreas Gohr                'simplenavi:namespace123:namespace123',
60e75a33bfSAndreas Gohr                'simplenavi:namespace2',
61e75a33bfSAndreas Gohr                'simplenavi:namespace21:start',
62e75a33bfSAndreas Gohr            ]
63e75a33bfSAndreas Gohr        ];
64e75a33bfSAndreas Gohr
65e75a33bfSAndreas Gohr        yield [
66e75a33bfSAndreas Gohr            'set' => 'by ID, Natural Sort, all branches closed',
67e75a33bfSAndreas Gohr            'titlesort' => false,
68e75a33bfSAndreas Gohr            'natsort' => true,
69*e58e2f72SAndreas Gohr            'nsfirst' => false,
70*e58e2f72SAndreas Gohr            'current' => 'simplenavi:page',
71e75a33bfSAndreas Gohr            'expect' => [
72*e58e2f72SAndreas Gohr                'simplenavi:foo',
73e75a33bfSAndreas Gohr                'simplenavi:namespace1:start',
74e75a33bfSAndreas Gohr                'simplenavi:namespace2',
75e75a33bfSAndreas Gohr                'simplenavi:namespace12:start',
76e75a33bfSAndreas Gohr                'simplenavi:namespace21:start',
77e75a33bfSAndreas Gohr                'simplenavi:namespace123:namespace123',
78e75a33bfSAndreas Gohr            ]
79e75a33bfSAndreas Gohr        ];
80e75a33bfSAndreas Gohr
81e75a33bfSAndreas Gohr        yield [
82e75a33bfSAndreas Gohr            'set' => 'by ID, branch open',
83e75a33bfSAndreas Gohr            'titlesort' => false,
84e75a33bfSAndreas Gohr            'natsort' => false,
85*e58e2f72SAndreas Gohr            'nsfirst' => false,
86e75a33bfSAndreas Gohr            'current' => 'simplenavi:namespace123:deep:foo',
87e75a33bfSAndreas Gohr            'expect' => [
88*e58e2f72SAndreas Gohr                'simplenavi:foo',
89e75a33bfSAndreas Gohr                'simplenavi:namespace1:start',
90e75a33bfSAndreas Gohr                'simplenavi:namespace12:start',
91e75a33bfSAndreas Gohr                'simplenavi:namespace123:namespace123',
92e75a33bfSAndreas Gohr                'simplenavi:namespace123:deep:start',
93e75a33bfSAndreas Gohr                'simplenavi:namespace123:deep:foo',
94e75a33bfSAndreas Gohr                'simplenavi:namespace123:foo',
95e75a33bfSAndreas Gohr                'simplenavi:namespace2',
96e75a33bfSAndreas Gohr                'simplenavi:namespace21:start',
97e75a33bfSAndreas Gohr            ]
98e75a33bfSAndreas Gohr        ];
99e75a33bfSAndreas Gohr
100e75a33bfSAndreas Gohr        yield [
101e75a33bfSAndreas Gohr            'set' => 'by ID, Natural Sort, branch open',
102e75a33bfSAndreas Gohr            'titlesort' => false,
103e75a33bfSAndreas Gohr            'natsort' => true,
104*e58e2f72SAndreas Gohr            'nsfirst' => false,
105e75a33bfSAndreas Gohr            'current' => 'simplenavi:namespace123:deep:foo',
106e75a33bfSAndreas Gohr            'expect' => [
107*e58e2f72SAndreas Gohr                'simplenavi:foo',
108e75a33bfSAndreas Gohr                'simplenavi:namespace1:start',
109e75a33bfSAndreas Gohr                'simplenavi:namespace2',
110e75a33bfSAndreas Gohr                'simplenavi:namespace12:start',
111e75a33bfSAndreas Gohr                'simplenavi:namespace21:start',
112e75a33bfSAndreas Gohr                'simplenavi:namespace123:namespace123',
113e75a33bfSAndreas Gohr                'simplenavi:namespace123:deep:start',
114e75a33bfSAndreas Gohr                'simplenavi:namespace123:deep:foo',
115e75a33bfSAndreas Gohr                'simplenavi:namespace123:foo',
116e75a33bfSAndreas Gohr            ]
117e75a33bfSAndreas Gohr        ];
118e75a33bfSAndreas Gohr
119e75a33bfSAndreas Gohr        yield [
120*e58e2f72SAndreas Gohr            'set' => 'by ID, Natural Sort, NS first, branch open',
121*e58e2f72SAndreas Gohr            'titlesort' => false,
122*e58e2f72SAndreas Gohr            'natsort' => true,
123*e58e2f72SAndreas Gohr            'nsfirst' => true,
124*e58e2f72SAndreas Gohr            'current' => 'simplenavi:namespace123:deep:foo',
125*e58e2f72SAndreas Gohr            'expect' => [
126*e58e2f72SAndreas Gohr                'simplenavi:namespace1:start',
127*e58e2f72SAndreas Gohr                'simplenavi:namespace2',
128*e58e2f72SAndreas Gohr                'simplenavi:namespace12:start',
129*e58e2f72SAndreas Gohr                'simplenavi:namespace21:start',
130*e58e2f72SAndreas Gohr                'simplenavi:namespace123:namespace123',
131*e58e2f72SAndreas Gohr                'simplenavi:namespace123:deep:start',
132*e58e2f72SAndreas Gohr                'simplenavi:namespace123:deep:foo',
133*e58e2f72SAndreas Gohr                'simplenavi:namespace123:foo',
134*e58e2f72SAndreas Gohr                'simplenavi:foo',
135*e58e2f72SAndreas Gohr            ]
136*e58e2f72SAndreas Gohr        ];
137*e58e2f72SAndreas Gohr
138*e58e2f72SAndreas Gohr        yield [
139e75a33bfSAndreas Gohr            'set' => 'by Title, all branches closed',
140e75a33bfSAndreas Gohr            'titlesort' => true,
141e75a33bfSAndreas Gohr            'natsort' => false,
142*e58e2f72SAndreas Gohr            'nsfirst' => false,
143*e58e2f72SAndreas Gohr            'current' => 'simplenavi:page',
144e75a33bfSAndreas Gohr            'expect' => [
145e75a33bfSAndreas Gohr                'simplenavi:namespace123:namespace123',
146*e58e2f72SAndreas Gohr                'simplenavi:foo',
147e75a33bfSAndreas Gohr                'simplenavi:namespace12:start',
148e75a33bfSAndreas Gohr                'simplenavi:namespace2',
149e75a33bfSAndreas Gohr                'simplenavi:namespace21:start',
150e75a33bfSAndreas Gohr                'simplenavi:namespace1:start',
151e75a33bfSAndreas Gohr            ]
152e75a33bfSAndreas Gohr        ];
153e75a33bfSAndreas Gohr
154e75a33bfSAndreas Gohr        yield [
155e75a33bfSAndreas Gohr            'set' => 'by Title, Natural Search, all branches closed',
156e75a33bfSAndreas Gohr            'titlesort' => true,
157e75a33bfSAndreas Gohr            'natsort' => true,
158*e58e2f72SAndreas Gohr            'nsfirst' => false,
159*e58e2f72SAndreas Gohr            'current' => 'simplenavi:page',
160e75a33bfSAndreas Gohr            'expect' => [
161e75a33bfSAndreas Gohr                'simplenavi:namespace123:namespace123',
162*e58e2f72SAndreas Gohr                'simplenavi:foo',
163e75a33bfSAndreas Gohr                'simplenavi:namespace2',
164e75a33bfSAndreas Gohr                'simplenavi:namespace12:start',
165e75a33bfSAndreas Gohr                'simplenavi:namespace21:start',
166e75a33bfSAndreas Gohr                'simplenavi:namespace1:start',
167e75a33bfSAndreas Gohr            ]
168e75a33bfSAndreas Gohr        ];
169e75a33bfSAndreas Gohr
170e75a33bfSAndreas Gohr        yield [
171e75a33bfSAndreas Gohr            'set' => 'by Title, branch open',
172e75a33bfSAndreas Gohr            'titlesort' => true,
173e75a33bfSAndreas Gohr            'natsort' => false,
174*e58e2f72SAndreas Gohr            'nsfirst' => false,
175e75a33bfSAndreas Gohr            'current' => 'simplenavi:namespace123:deep:foo',
176e75a33bfSAndreas Gohr            'expect' => [
177e75a33bfSAndreas Gohr                'simplenavi:namespace123:namespace123',
178e75a33bfSAndreas Gohr                'simplenavi:namespace123:deep:start',
179e75a33bfSAndreas Gohr                'simplenavi:namespace123:deep:foo',
180e75a33bfSAndreas Gohr                'simplenavi:namespace123:foo',
181*e58e2f72SAndreas Gohr                'simplenavi:foo',
182e75a33bfSAndreas Gohr                'simplenavi:namespace12:start',
183e75a33bfSAndreas Gohr                'simplenavi:namespace2',
184e75a33bfSAndreas Gohr                'simplenavi:namespace21:start',
185e75a33bfSAndreas Gohr                'simplenavi:namespace1:start',
186e75a33bfSAndreas Gohr            ]
187e75a33bfSAndreas Gohr        ];
188e75a33bfSAndreas Gohr
189e75a33bfSAndreas Gohr        yield [
190e75a33bfSAndreas Gohr            'set' => 'by Title, Natural Sort, branch open',
191e75a33bfSAndreas Gohr            'titlesort' => true,
192e75a33bfSAndreas Gohr            'natsort' => true,
193*e58e2f72SAndreas Gohr            'nsfirst' => false,
194*e58e2f72SAndreas Gohr            'current' => 'simplenavi:namespace123:deep:foo',
195*e58e2f72SAndreas Gohr            'expect' => [
196*e58e2f72SAndreas Gohr                'simplenavi:namespace123:namespace123',
197*e58e2f72SAndreas Gohr                'simplenavi:namespace123:deep:start',
198*e58e2f72SAndreas Gohr                'simplenavi:namespace123:deep:foo',
199*e58e2f72SAndreas Gohr                'simplenavi:namespace123:foo',
200*e58e2f72SAndreas Gohr                'simplenavi:foo',
201*e58e2f72SAndreas Gohr                'simplenavi:namespace2',
202*e58e2f72SAndreas Gohr                'simplenavi:namespace12:start',
203*e58e2f72SAndreas Gohr                'simplenavi:namespace21:start',
204*e58e2f72SAndreas Gohr                'simplenavi:namespace1:start',
205*e58e2f72SAndreas Gohr            ]
206*e58e2f72SAndreas Gohr        ];
207*e58e2f72SAndreas Gohr
208*e58e2f72SAndreas Gohr        yield [
209*e58e2f72SAndreas Gohr            'set' => 'by Title, Natural Sort, NS first, branch open',
210*e58e2f72SAndreas Gohr            'titlesort' => true,
211*e58e2f72SAndreas Gohr            'natsort' => true,
212*e58e2f72SAndreas Gohr            'nsfirst' => true,
213e75a33bfSAndreas Gohr            'current' => 'simplenavi:namespace123:deep:foo',
214e75a33bfSAndreas Gohr            'expect' => [
215e75a33bfSAndreas Gohr                'simplenavi:namespace123:namespace123',
216e75a33bfSAndreas Gohr                'simplenavi:namespace123:deep:start',
217e75a33bfSAndreas Gohr                'simplenavi:namespace123:deep:foo',
218e75a33bfSAndreas Gohr                'simplenavi:namespace123:foo',
219e75a33bfSAndreas Gohr                'simplenavi:namespace2',
220e75a33bfSAndreas Gohr                'simplenavi:namespace12:start',
221e75a33bfSAndreas Gohr                'simplenavi:namespace21:start',
222e75a33bfSAndreas Gohr                'simplenavi:namespace1:start',
223*e58e2f72SAndreas Gohr                'simplenavi:foo',
224e75a33bfSAndreas Gohr            ]
225e75a33bfSAndreas Gohr        ];
226d8ce5486SAndreas Gohr    }
227d8ce5486SAndreas Gohr
228d8ce5486SAndreas Gohr    /**
229e75a33bfSAndreas Gohr     * @dataProvider dataProvider
230d8ce5486SAndreas Gohr     */
231*e58e2f72SAndreas Gohr    public function testSorting($set, $titlesort, $natsort, $nsfirst, $current, $expect)
232d8ce5486SAndreas Gohr    {
233e75a33bfSAndreas Gohr        $simpleNavi = new \syntax_plugin_simplenavi();
234*e58e2f72SAndreas Gohr        $items = $simpleNavi->getSortedItems('simplenavi', $current, $titlesort, $natsort, $nsfirst);
235e75a33bfSAndreas Gohr        $this->assertSame($expect, array_column($items, 'id'), $set);
236d8ce5486SAndreas Gohr    }
237d8ce5486SAndreas Gohr
238d8ce5486SAndreas Gohr}
239d8ce5486SAndreas Gohr
240d8ce5486SAndreas Gohr
241d8ce5486SAndreas Gohr
242