|
2 | 2 |
|
3 | 3 | namespace dokuwiki\plugin\simplenavi\test;
|
4 | 4 |
|
| 5 | +use dokuwiki\TreeBuilder\PageTreeBuilder; |
5 | 6 | use DokuWikiTest;
|
6 |
| -use TestRequest; |
7 | 7 |
|
8 | 8 | /**
|
9 | 9 | * General tests for the simplenavi plugin
|
@@ -50,222 +50,161 @@ public function dataProvider()
|
50 | 50 |
|
51 | 51 | yield [
|
52 | 52 | 'set' => 'by ID, all branches closed',
|
53 |
| - 'titlesort' => false, |
54 |
| - 'natsort' => false, |
55 |
| - 'nsfirst' => false, |
| 53 | + 'sort' => 'id', |
| 54 | + 'usetitle' => false, |
56 | 55 | 'home' => false,
|
57 | 56 | 'current' => 'simplenavi:page',
|
58 | 57 | 'expect' => [
|
59 |
| - 'simplenavi:foo', |
60 |
| - 'simplenavi:namespace1:start', |
61 |
| - 'simplenavi:namespace12:start', |
62 |
| - 'simplenavi:namespace123:namespace123', |
63 |
| - 'simplenavi:namespace2', |
64 |
| - 'simplenavi:namespace21:start', |
65 |
| - ] |
66 |
| - ]; |
67 |
| - |
68 |
| - yield [ |
69 |
| - 'set' => 'by ID, Natural Sort, all branches closed', |
70 |
| - 'titlesort' => false, |
71 |
| - 'natsort' => true, |
72 |
| - 'nsfirst' => false, |
73 |
| - 'home' => false, |
74 |
| - 'current' => 'simplenavi:page', |
75 |
| - 'expect' => [ |
76 |
| - 'simplenavi:foo', |
77 |
| - 'simplenavi:namespace1:start', |
78 |
| - 'simplenavi:namespace2', |
79 |
| - 'simplenavi:namespace12:start', |
80 |
| - 'simplenavi:namespace21:start', |
81 |
| - 'simplenavi:namespace123:namespace123', |
| 58 | + '+simplenavi:foo', |
| 59 | + '+simplenavi:namespace1:start', |
| 60 | + '+simplenavi:namespace12:start', |
| 61 | + '+simplenavi:namespace123:namespace123', |
| 62 | + '+simplenavi:namespace2', |
| 63 | + '+simplenavi:namespace21:start', |
82 | 64 | ]
|
83 | 65 | ];
|
84 | 66 |
|
85 | 67 | yield [
|
86 | 68 | 'set' => 'by ID, branch open',
|
87 |
| - 'titlesort' => false, |
88 |
| - 'natsort' => false, |
89 |
| - 'nsfirst' => false, |
| 69 | + 'sort' => 'id', |
| 70 | + 'usetitle' => false, |
90 | 71 | 'home' => false,
|
91 | 72 | 'current' => 'simplenavi:namespace123:deep:foo',
|
92 | 73 | 'expect' => [
|
93 |
| - 'simplenavi:foo', |
94 |
| - 'simplenavi:namespace1:start', |
95 |
| - 'simplenavi:namespace12:start', |
96 |
| - 'simplenavi:namespace123:namespace123', |
97 |
| - 'simplenavi:namespace123:deep:start', |
98 |
| - 'simplenavi:namespace123:deep:foo', |
99 |
| - 'simplenavi:namespace123:foo', |
100 |
| - 'simplenavi:namespace2', |
101 |
| - 'simplenavi:namespace21:start', |
| 74 | + '+simplenavi:foo', |
| 75 | + '+simplenavi:namespace1:start', |
| 76 | + '+simplenavi:namespace12:start', |
| 77 | + '+simplenavi:namespace123:namespace123', |
| 78 | + '++simplenavi:namespace123:deep:start', |
| 79 | + '+++simplenavi:namespace123:deep:foo', |
| 80 | + '++simplenavi:namespace123:foo', |
| 81 | + '+simplenavi:namespace2', |
| 82 | + '+simplenavi:namespace21:start', |
102 | 83 | ]
|
103 | 84 | ];
|
104 | 85 |
|
105 |
| - yield [ |
106 |
| - 'set' => 'by ID, Natural Sort, branch open', |
107 |
| - 'titlesort' => false, |
108 |
| - 'natsort' => true, |
109 |
| - 'nsfirst' => false, |
110 |
| - 'home' => false, |
111 |
| - 'current' => 'simplenavi:namespace123:deep:foo', |
112 |
| - 'expect' => [ |
113 |
| - 'simplenavi:foo', |
114 |
| - 'simplenavi:namespace1:start', |
115 |
| - 'simplenavi:namespace2', |
116 |
| - 'simplenavi:namespace12:start', |
117 |
| - 'simplenavi:namespace21:start', |
118 |
| - 'simplenavi:namespace123:namespace123', |
119 |
| - 'simplenavi:namespace123:deep:start', |
120 |
| - 'simplenavi:namespace123:deep:foo', |
121 |
| - 'simplenavi:namespace123:foo', |
122 |
| - ] |
123 |
| - ]; |
124 |
| - |
125 |
| - yield [ |
126 |
| - 'set' => 'by ID, Natural Sort, NS first, branch open', |
127 |
| - 'titlesort' => false, |
128 |
| - 'natsort' => true, |
129 |
| - 'nsfirst' => true, |
130 |
| - 'home' => false, |
131 |
| - 'current' => 'simplenavi:namespace123:deep:foo', |
132 |
| - 'expect' => [ |
133 |
| - 'simplenavi:namespace1:start', |
134 |
| - 'simplenavi:namespace2', |
135 |
| - 'simplenavi:namespace12:start', |
136 |
| - 'simplenavi:namespace21:start', |
137 |
| - 'simplenavi:namespace123:namespace123', |
138 |
| - 'simplenavi:namespace123:deep:start', |
139 |
| - 'simplenavi:namespace123:deep:foo', |
140 |
| - 'simplenavi:namespace123:foo', |
141 |
| - 'simplenavi:foo', |
142 |
| - ] |
143 |
| - ]; |
144 |
| - |
145 |
| - yield [ |
146 |
| - 'set' => 'by Title, all branches closed', |
147 |
| - 'titlesort' => true, |
148 |
| - 'natsort' => false, |
149 |
| - 'nsfirst' => false, |
150 |
| - 'home' => false, |
151 |
| - 'current' => 'simplenavi:page', |
152 |
| - 'expect' => [ |
153 |
| - 'simplenavi:namespace123:namespace123', |
154 |
| - 'simplenavi:foo', |
155 |
| - 'simplenavi:namespace12:start', |
156 |
| - 'simplenavi:namespace2', |
157 |
| - 'simplenavi:namespace21:start', |
158 |
| - 'simplenavi:namespace1:start', |
159 |
| - ] |
160 |
| - ]; |
161 | 86 |
|
162 | 87 | yield [
|
163 | 88 | 'set' => 'by Title, Natural Search, all branches closed',
|
164 |
| - 'titlesort' => true, |
165 |
| - 'natsort' => true, |
166 |
| - 'nsfirst' => false, |
| 89 | + 'sort' => 'title', |
| 90 | + 'usetitle' => true, |
167 | 91 | 'home' => false,
|
168 | 92 | 'current' => 'simplenavi:page',
|
169 | 93 | 'expect' => [
|
170 |
| - 'simplenavi:namespace123:namespace123', |
171 |
| - 'simplenavi:foo', |
172 |
| - 'simplenavi:namespace2', |
173 |
| - 'simplenavi:namespace12:start', |
174 |
| - 'simplenavi:namespace21:start', |
175 |
| - 'simplenavi:namespace1:start', |
176 |
| - ] |
177 |
| - ]; |
178 |
| - |
179 |
| - yield [ |
180 |
| - 'set' => 'by Title, branch open', |
181 |
| - 'titlesort' => true, |
182 |
| - 'natsort' => false, |
183 |
| - 'nsfirst' => false, |
184 |
| - 'home' => false, |
185 |
| - 'current' => 'simplenavi:namespace123:deep:foo', |
186 |
| - 'expect' => [ |
187 |
| - 'simplenavi:namespace123:namespace123', |
188 |
| - 'simplenavi:namespace123:deep:start', |
189 |
| - 'simplenavi:namespace123:deep:foo', |
190 |
| - 'simplenavi:namespace123:foo', |
191 |
| - 'simplenavi:foo', |
192 |
| - 'simplenavi:namespace12:start', |
193 |
| - 'simplenavi:namespace2', |
194 |
| - 'simplenavi:namespace21:start', |
195 |
| - 'simplenavi:namespace1:start', |
| 94 | + '+simplenavi:namespace123:namespace123', |
| 95 | + '+simplenavi:foo', |
| 96 | + '+simplenavi:namespace2', |
| 97 | + '+simplenavi:namespace12:start', |
| 98 | + '+simplenavi:namespace21:start', |
| 99 | + '+simplenavi:namespace1:start', |
196 | 100 | ]
|
197 | 101 | ];
|
198 | 102 |
|
199 | 103 | yield [
|
200 | 104 | 'set' => 'by Title, Natural Sort, branch open',
|
201 |
| - 'titlesort' => true, |
202 |
| - 'natsort' => true, |
203 |
| - 'nsfirst' => false, |
| 105 | + 'sort' => 'title', |
| 106 | + 'usetitle' => true, |
204 | 107 | 'home' => false,
|
205 | 108 | 'current' => 'simplenavi:namespace123:deep:foo',
|
206 | 109 | 'expect' => [
|
207 |
| - 'simplenavi:namespace123:namespace123', |
208 |
| - 'simplenavi:namespace123:deep:start', |
209 |
| - 'simplenavi:namespace123:deep:foo', |
210 |
| - 'simplenavi:namespace123:foo', |
211 |
| - 'simplenavi:foo', |
212 |
| - 'simplenavi:namespace2', |
213 |
| - 'simplenavi:namespace12:start', |
214 |
| - 'simplenavi:namespace21:start', |
215 |
| - 'simplenavi:namespace1:start', |
| 110 | + '+simplenavi:namespace123:namespace123', |
| 111 | + '++simplenavi:namespace123:deep:start', |
| 112 | + '+++simplenavi:namespace123:deep:foo', |
| 113 | + '++simplenavi:namespace123:foo', |
| 114 | + '+simplenavi:foo', |
| 115 | + '+simplenavi:namespace2', |
| 116 | + '+simplenavi:namespace12:start', |
| 117 | + '+simplenavi:namespace21:start', |
| 118 | + '+simplenavi:namespace1:start', |
216 | 119 | ]
|
217 | 120 | ];
|
218 | 121 |
|
219 | 122 | yield [
|
220 | 123 | 'set' => 'by Title, Natural Sort, NS first, branch open',
|
221 |
| - 'titlesort' => true, |
222 |
| - 'natsort' => true, |
223 |
| - 'nsfirst' => true, |
| 124 | + 'sort' => 'ns_title', |
| 125 | + 'usetitle' => true, |
224 | 126 | 'home' => false,
|
225 | 127 | 'current' => 'simplenavi:namespace123:deep:foo',
|
226 | 128 | 'expect' => [
|
227 |
| - 'simplenavi:namespace123:namespace123', |
228 |
| - 'simplenavi:namespace123:deep:start', |
229 |
| - 'simplenavi:namespace123:deep:foo', |
230 |
| - 'simplenavi:namespace123:foo', |
231 |
| - 'simplenavi:namespace2', |
232 |
| - 'simplenavi:namespace12:start', |
233 |
| - 'simplenavi:namespace21:start', |
234 |
| - 'simplenavi:namespace1:start', |
235 |
| - 'simplenavi:foo', |
| 129 | + '+simplenavi:namespace123:namespace123', |
| 130 | + '++simplenavi:namespace123:deep:start', |
| 131 | + '+++simplenavi:namespace123:deep:foo', |
| 132 | + '++simplenavi:namespace123:foo', |
| 133 | + '+simplenavi:namespace2', |
| 134 | + '+simplenavi:namespace12:start', |
| 135 | + '+simplenavi:namespace21:start', |
| 136 | + '+simplenavi:namespace1:start', |
| 137 | + '+simplenavi:foo', |
236 | 138 | ]
|
237 | 139 | ];
|
238 | 140 |
|
239 | 141 | yield [
|
240 | 142 | 'set' => 'by ID, branch open with home level',
|
241 |
| - 'titlesort' => false, |
242 |
| - 'natsort' => false, |
243 |
| - 'nsfirst' => false, |
| 143 | + 'sort' => 'id', |
| 144 | + 'usetitle' => false, |
244 | 145 | 'home' => true,
|
245 | 146 | 'current' => 'simplenavi:namespace123:deep:foo',
|
246 | 147 | 'expect' => [
|
247 |
| - 'simplenavi:simplenavi', |
248 |
| - 'simplenavi:foo', |
249 |
| - 'simplenavi:namespace1:start', |
250 |
| - 'simplenavi:namespace12:start', |
251 |
| - 'simplenavi:namespace123:namespace123', |
252 |
| - 'simplenavi:namespace123:deep:start', |
253 |
| - 'simplenavi:namespace123:deep:foo', |
254 |
| - 'simplenavi:namespace123:foo', |
255 |
| - 'simplenavi:namespace2', |
256 |
| - 'simplenavi:namespace21:start', |
| 148 | + '+simplenavi:simplenavi', |
| 149 | + '++simplenavi:foo', |
| 150 | + '++simplenavi:namespace1:start', |
| 151 | + '++simplenavi:namespace12:start', |
| 152 | + '++simplenavi:namespace123:namespace123', |
| 153 | + '+++simplenavi:namespace123:deep:start', |
| 154 | + '++++simplenavi:namespace123:deep:foo', |
| 155 | + '+++simplenavi:namespace123:foo', |
| 156 | + '++simplenavi:namespace2', |
| 157 | + '++simplenavi:namespace21:start', |
257 | 158 | ]
|
258 | 159 | ];
|
259 | 160 | }
|
260 | 161 |
|
261 | 162 | /**
|
262 | 163 | * @dataProvider dataProvider
|
263 | 164 | */
|
264 |
| - public function testSorting($set, $titlesort, $natsort, $nsfirst, $home, $current, $expect) |
| 165 | + public function testSorting($set, $sort, $usetitle, $home, $current, $expect) |
| 166 | + { |
| 167 | + $simpleNavi = new \syntax_plugin_simplenavi(); |
| 168 | + |
| 169 | + $simpleNavi->initState('simplenavi', $current, $usetitle, $sort, $home); |
| 170 | + |
| 171 | + /** @var PageTreeBuilder $tree */ |
| 172 | + $tree = $this->callInaccessibleMethod($simpleNavi, 'getTree', []); |
| 173 | + |
| 174 | + |
| 175 | + $this->assertSame(join("\n", $expect), (string) $tree, $set); |
| 176 | + } |
| 177 | + |
| 178 | + /** |
| 179 | + * Data provider for isParent test |
| 180 | + */ |
| 181 | + public function isParentDataProvider(): array |
| 182 | + { |
| 183 | + return [ |
| 184 | + // Test cases where parent is a parent of child |
| 185 | + 'parent of deep child' => [true, 'namespace1:namespace2:page', 'namespace1'], |
| 186 | + 'direct parent' => [true, 'namespace1:namespace2:page', 'namespace1:namespace2'], |
| 187 | + 'parent of page' => [true, 'namespace1:page', 'namespace1'], |
| 188 | + |
| 189 | + // Test cases where parent is not a parent of child |
| 190 | + 'different namespace' => [false, 'namespace1:page', 'namespace2'], |
| 191 | + 'sibling namespace' => [false, 'namespace1:namespace2:page', 'namespace1:namespace3'], |
| 192 | + |
| 193 | + // Test edge cases |
| 194 | + 'empty parent' => [true, 'page', ''], // Empty parent is parent of all |
| 195 | + 'self as parent' => [true, 'page', 'page'], // Page is parent of itself |
| 196 | + ]; |
| 197 | + } |
| 198 | + |
| 199 | + /** |
| 200 | + * Test the isParent method |
| 201 | + * @dataProvider isParentDataProvider |
| 202 | + */ |
| 203 | + public function testIsParent(bool $expected, string $child, string $parent): void |
265 | 204 | {
|
266 | 205 | $simpleNavi = new \syntax_plugin_simplenavi();
|
267 |
| - $items = $simpleNavi->getSortedItems('simplenavi', $current, $titlesort, $natsort, $nsfirst, $home); |
268 |
| - $this->assertSame($expect, array_column($items, 'id'), $set); |
| 206 | + $result = $this->callInaccessibleMethod($simpleNavi, 'isParent', [$child, $parent]); |
| 207 | + $this->assertSame($expected, $result); |
269 | 208 | }
|
270 | 209 |
|
271 | 210 | }
|
|
0 commit comments