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 = [ 27e58e2f72SAndreas Gohr ['foo', 'Foo Page'], 28*d418c031SAndreas Gohr ['simplenavi', 'Self Start'], 29e75a33bfSAndreas Gohr ['namespace1:start', 'ZZZ Namespace 1 Start'], 30e75a33bfSAndreas Gohr ['namespace2:foo', 'Namespace 2 Foo'], 31e75a33bfSAndreas Gohr ['namespace2', 'Namespace 2 Start'], 32e75a33bfSAndreas Gohr ['namespace12:foo', 'Namespace 12 Foo'], 33e75a33bfSAndreas Gohr ['namespace12:start', 'Namespace 12 Start'], 34e75a33bfSAndreas Gohr ['namespace123:namespace123', 'AAA Namespace 123 Start'], 35e75a33bfSAndreas Gohr ['namespace123:foo', 'Namespace 123 Foo'], 36e75a33bfSAndreas Gohr ['namespace123:deep:start', 'Namespace 123 Deep Start'], 37e75a33bfSAndreas Gohr ['namespace123:deep:foo', 'Namespace 123 Deep Foo'], 38e75a33bfSAndreas Gohr ['namespace21:foo', 'Namespace 21 Foo'], 39e75a33bfSAndreas Gohr ['namespace21:start', 'Namespace 21 Start'], 40e75a33bfSAndreas Gohr ]; 41e75a33bfSAndreas Gohr 42e75a33bfSAndreas Gohr foreach ($pages as $page) { 43e75a33bfSAndreas Gohr saveWikiText('simplenavi:' . $page[0], '====== ' . $page[1] . ' ======', 'create test page'); 44e75a33bfSAndreas Gohr } 45e75a33bfSAndreas Gohr 46e75a33bfSAndreas Gohr } 47e75a33bfSAndreas Gohr 48*d418c031SAndreas Gohr public function dataProvider() 49*d418c031SAndreas Gohr { 50e75a33bfSAndreas Gohr 51e75a33bfSAndreas Gohr yield [ 52e75a33bfSAndreas Gohr 'set' => 'by ID, all branches closed', 53e75a33bfSAndreas Gohr 'titlesort' => false, 54e75a33bfSAndreas Gohr 'natsort' => false, 55e58e2f72SAndreas Gohr 'nsfirst' => false, 56*d418c031SAndreas Gohr 'home' => false, 57e58e2f72SAndreas Gohr 'current' => 'simplenavi:page', 58e75a33bfSAndreas Gohr 'expect' => [ 59e58e2f72SAndreas Gohr 'simplenavi:foo', 60e75a33bfSAndreas Gohr 'simplenavi:namespace1:start', 61e75a33bfSAndreas Gohr 'simplenavi:namespace12:start', 62e75a33bfSAndreas Gohr 'simplenavi:namespace123:namespace123', 63e75a33bfSAndreas Gohr 'simplenavi:namespace2', 64e75a33bfSAndreas Gohr 'simplenavi:namespace21:start', 65e75a33bfSAndreas Gohr ] 66e75a33bfSAndreas Gohr ]; 67e75a33bfSAndreas Gohr 68e75a33bfSAndreas Gohr yield [ 69e75a33bfSAndreas Gohr 'set' => 'by ID, Natural Sort, all branches closed', 70e75a33bfSAndreas Gohr 'titlesort' => false, 71e75a33bfSAndreas Gohr 'natsort' => true, 72e58e2f72SAndreas Gohr 'nsfirst' => false, 73*d418c031SAndreas Gohr 'home' => false, 74e58e2f72SAndreas Gohr 'current' => 'simplenavi:page', 75e75a33bfSAndreas Gohr 'expect' => [ 76e58e2f72SAndreas Gohr 'simplenavi:foo', 77e75a33bfSAndreas Gohr 'simplenavi:namespace1:start', 78e75a33bfSAndreas Gohr 'simplenavi:namespace2', 79e75a33bfSAndreas Gohr 'simplenavi:namespace12:start', 80e75a33bfSAndreas Gohr 'simplenavi:namespace21:start', 81e75a33bfSAndreas Gohr 'simplenavi:namespace123:namespace123', 82e75a33bfSAndreas Gohr ] 83e75a33bfSAndreas Gohr ]; 84e75a33bfSAndreas Gohr 85e75a33bfSAndreas Gohr yield [ 86e75a33bfSAndreas Gohr 'set' => 'by ID, branch open', 87e75a33bfSAndreas Gohr 'titlesort' => false, 88e75a33bfSAndreas Gohr 'natsort' => false, 89e58e2f72SAndreas Gohr 'nsfirst' => false, 90*d418c031SAndreas Gohr 'home' => false, 91e75a33bfSAndreas Gohr 'current' => 'simplenavi:namespace123:deep:foo', 92e75a33bfSAndreas Gohr 'expect' => [ 93e58e2f72SAndreas Gohr 'simplenavi:foo', 94e75a33bfSAndreas Gohr 'simplenavi:namespace1:start', 95e75a33bfSAndreas Gohr 'simplenavi:namespace12:start', 96e75a33bfSAndreas Gohr 'simplenavi:namespace123:namespace123', 97e75a33bfSAndreas Gohr 'simplenavi:namespace123:deep:start', 98e75a33bfSAndreas Gohr 'simplenavi:namespace123:deep:foo', 99e75a33bfSAndreas Gohr 'simplenavi:namespace123:foo', 100e75a33bfSAndreas Gohr 'simplenavi:namespace2', 101e75a33bfSAndreas Gohr 'simplenavi:namespace21:start', 102e75a33bfSAndreas Gohr ] 103e75a33bfSAndreas Gohr ]; 104e75a33bfSAndreas Gohr 105e75a33bfSAndreas Gohr yield [ 106e75a33bfSAndreas Gohr 'set' => 'by ID, Natural Sort, branch open', 107e75a33bfSAndreas Gohr 'titlesort' => false, 108e75a33bfSAndreas Gohr 'natsort' => true, 109e58e2f72SAndreas Gohr 'nsfirst' => false, 110*d418c031SAndreas Gohr 'home' => false, 111e75a33bfSAndreas Gohr 'current' => 'simplenavi:namespace123:deep:foo', 112e75a33bfSAndreas Gohr 'expect' => [ 113e58e2f72SAndreas Gohr 'simplenavi:foo', 114e75a33bfSAndreas Gohr 'simplenavi:namespace1:start', 115e75a33bfSAndreas Gohr 'simplenavi:namespace2', 116e75a33bfSAndreas Gohr 'simplenavi:namespace12:start', 117e75a33bfSAndreas Gohr 'simplenavi:namespace21:start', 118e75a33bfSAndreas Gohr 'simplenavi:namespace123:namespace123', 119e75a33bfSAndreas Gohr 'simplenavi:namespace123:deep:start', 120e75a33bfSAndreas Gohr 'simplenavi:namespace123:deep:foo', 121e75a33bfSAndreas Gohr 'simplenavi:namespace123:foo', 122e75a33bfSAndreas Gohr ] 123e75a33bfSAndreas Gohr ]; 124e75a33bfSAndreas Gohr 125e75a33bfSAndreas Gohr yield [ 126e58e2f72SAndreas Gohr 'set' => 'by ID, Natural Sort, NS first, branch open', 127e58e2f72SAndreas Gohr 'titlesort' => false, 128e58e2f72SAndreas Gohr 'natsort' => true, 129e58e2f72SAndreas Gohr 'nsfirst' => true, 130*d418c031SAndreas Gohr 'home' => false, 131e58e2f72SAndreas Gohr 'current' => 'simplenavi:namespace123:deep:foo', 132e58e2f72SAndreas Gohr 'expect' => [ 133e58e2f72SAndreas Gohr 'simplenavi:namespace1:start', 134e58e2f72SAndreas Gohr 'simplenavi:namespace2', 135e58e2f72SAndreas Gohr 'simplenavi:namespace12:start', 136e58e2f72SAndreas Gohr 'simplenavi:namespace21:start', 137e58e2f72SAndreas Gohr 'simplenavi:namespace123:namespace123', 138e58e2f72SAndreas Gohr 'simplenavi:namespace123:deep:start', 139e58e2f72SAndreas Gohr 'simplenavi:namespace123:deep:foo', 140e58e2f72SAndreas Gohr 'simplenavi:namespace123:foo', 141e58e2f72SAndreas Gohr 'simplenavi:foo', 142e58e2f72SAndreas Gohr ] 143e58e2f72SAndreas Gohr ]; 144e58e2f72SAndreas Gohr 145e58e2f72SAndreas Gohr yield [ 146e75a33bfSAndreas Gohr 'set' => 'by Title, all branches closed', 147e75a33bfSAndreas Gohr 'titlesort' => true, 148e75a33bfSAndreas Gohr 'natsort' => false, 149e58e2f72SAndreas Gohr 'nsfirst' => false, 150*d418c031SAndreas Gohr 'home' => false, 151e58e2f72SAndreas Gohr 'current' => 'simplenavi:page', 152e75a33bfSAndreas Gohr 'expect' => [ 153e75a33bfSAndreas Gohr 'simplenavi:namespace123:namespace123', 154e58e2f72SAndreas Gohr 'simplenavi:foo', 155e75a33bfSAndreas Gohr 'simplenavi:namespace12:start', 156e75a33bfSAndreas Gohr 'simplenavi:namespace2', 157e75a33bfSAndreas Gohr 'simplenavi:namespace21:start', 158e75a33bfSAndreas Gohr 'simplenavi:namespace1:start', 159e75a33bfSAndreas Gohr ] 160e75a33bfSAndreas Gohr ]; 161e75a33bfSAndreas Gohr 162e75a33bfSAndreas Gohr yield [ 163e75a33bfSAndreas Gohr 'set' => 'by Title, Natural Search, all branches closed', 164e75a33bfSAndreas Gohr 'titlesort' => true, 165e75a33bfSAndreas Gohr 'natsort' => true, 166e58e2f72SAndreas Gohr 'nsfirst' => false, 167*d418c031SAndreas Gohr 'home' => false, 168e58e2f72SAndreas Gohr 'current' => 'simplenavi:page', 169e75a33bfSAndreas Gohr 'expect' => [ 170e75a33bfSAndreas Gohr 'simplenavi:namespace123:namespace123', 171e58e2f72SAndreas Gohr 'simplenavi:foo', 172e75a33bfSAndreas Gohr 'simplenavi:namespace2', 173e75a33bfSAndreas Gohr 'simplenavi:namespace12:start', 174e75a33bfSAndreas Gohr 'simplenavi:namespace21:start', 175e75a33bfSAndreas Gohr 'simplenavi:namespace1:start', 176e75a33bfSAndreas Gohr ] 177e75a33bfSAndreas Gohr ]; 178e75a33bfSAndreas Gohr 179e75a33bfSAndreas Gohr yield [ 180e75a33bfSAndreas Gohr 'set' => 'by Title, branch open', 181e75a33bfSAndreas Gohr 'titlesort' => true, 182e75a33bfSAndreas Gohr 'natsort' => false, 183e58e2f72SAndreas Gohr 'nsfirst' => false, 184*d418c031SAndreas Gohr 'home' => false, 185e75a33bfSAndreas Gohr 'current' => 'simplenavi:namespace123:deep:foo', 186e75a33bfSAndreas Gohr 'expect' => [ 187e75a33bfSAndreas Gohr 'simplenavi:namespace123:namespace123', 188e75a33bfSAndreas Gohr 'simplenavi:namespace123:deep:start', 189e75a33bfSAndreas Gohr 'simplenavi:namespace123:deep:foo', 190e75a33bfSAndreas Gohr 'simplenavi:namespace123:foo', 191e58e2f72SAndreas Gohr 'simplenavi:foo', 192e75a33bfSAndreas Gohr 'simplenavi:namespace12:start', 193e75a33bfSAndreas Gohr 'simplenavi:namespace2', 194e75a33bfSAndreas Gohr 'simplenavi:namespace21:start', 195e75a33bfSAndreas Gohr 'simplenavi:namespace1:start', 196e75a33bfSAndreas Gohr ] 197e75a33bfSAndreas Gohr ]; 198e75a33bfSAndreas Gohr 199e75a33bfSAndreas Gohr yield [ 200e75a33bfSAndreas Gohr 'set' => 'by Title, Natural Sort, branch open', 201e75a33bfSAndreas Gohr 'titlesort' => true, 202e75a33bfSAndreas Gohr 'natsort' => true, 203e58e2f72SAndreas Gohr 'nsfirst' => false, 204*d418c031SAndreas Gohr 'home' => false, 205e58e2f72SAndreas Gohr 'current' => 'simplenavi:namespace123:deep:foo', 206e58e2f72SAndreas Gohr 'expect' => [ 207e58e2f72SAndreas Gohr 'simplenavi:namespace123:namespace123', 208e58e2f72SAndreas Gohr 'simplenavi:namespace123:deep:start', 209e58e2f72SAndreas Gohr 'simplenavi:namespace123:deep:foo', 210e58e2f72SAndreas Gohr 'simplenavi:namespace123:foo', 211e58e2f72SAndreas Gohr 'simplenavi:foo', 212e58e2f72SAndreas Gohr 'simplenavi:namespace2', 213e58e2f72SAndreas Gohr 'simplenavi:namespace12:start', 214e58e2f72SAndreas Gohr 'simplenavi:namespace21:start', 215e58e2f72SAndreas Gohr 'simplenavi:namespace1:start', 216e58e2f72SAndreas Gohr ] 217e58e2f72SAndreas Gohr ]; 218e58e2f72SAndreas Gohr 219e58e2f72SAndreas Gohr yield [ 220e58e2f72SAndreas Gohr 'set' => 'by Title, Natural Sort, NS first, branch open', 221e58e2f72SAndreas Gohr 'titlesort' => true, 222e58e2f72SAndreas Gohr 'natsort' => true, 223e58e2f72SAndreas Gohr 'nsfirst' => true, 224*d418c031SAndreas Gohr 'home' => false, 225e75a33bfSAndreas Gohr 'current' => 'simplenavi:namespace123:deep:foo', 226e75a33bfSAndreas Gohr 'expect' => [ 227e75a33bfSAndreas Gohr 'simplenavi:namespace123:namespace123', 228e75a33bfSAndreas Gohr 'simplenavi:namespace123:deep:start', 229e75a33bfSAndreas Gohr 'simplenavi:namespace123:deep:foo', 230e75a33bfSAndreas Gohr 'simplenavi:namespace123:foo', 231e75a33bfSAndreas Gohr 'simplenavi:namespace2', 232e75a33bfSAndreas Gohr 'simplenavi:namespace12:start', 233e75a33bfSAndreas Gohr 'simplenavi:namespace21:start', 234e75a33bfSAndreas Gohr 'simplenavi:namespace1:start', 235e58e2f72SAndreas Gohr 'simplenavi:foo', 236e75a33bfSAndreas Gohr ] 237e75a33bfSAndreas Gohr ]; 238*d418c031SAndreas Gohr 239*d418c031SAndreas Gohr yield [ 240*d418c031SAndreas Gohr 'set' => 'by ID, branch open with home level', 241*d418c031SAndreas Gohr 'titlesort' => false, 242*d418c031SAndreas Gohr 'natsort' => false, 243*d418c031SAndreas Gohr 'nsfirst' => false, 244*d418c031SAndreas Gohr 'home' => true, 245*d418c031SAndreas Gohr 'current' => 'simplenavi:namespace123:deep:foo', 246*d418c031SAndreas Gohr 'expect' => [ 247*d418c031SAndreas Gohr 'simplenavi:simplenavi', 248*d418c031SAndreas Gohr 'simplenavi:foo', 249*d418c031SAndreas Gohr 'simplenavi:namespace1:start', 250*d418c031SAndreas Gohr 'simplenavi:namespace12:start', 251*d418c031SAndreas Gohr 'simplenavi:namespace123:namespace123', 252*d418c031SAndreas Gohr 'simplenavi:namespace123:deep:start', 253*d418c031SAndreas Gohr 'simplenavi:namespace123:deep:foo', 254*d418c031SAndreas Gohr 'simplenavi:namespace123:foo', 255*d418c031SAndreas Gohr 'simplenavi:namespace2', 256*d418c031SAndreas Gohr 'simplenavi:namespace21:start', 257*d418c031SAndreas Gohr ] 258*d418c031SAndreas Gohr ]; 259d8ce5486SAndreas Gohr } 260d8ce5486SAndreas Gohr 261d8ce5486SAndreas Gohr /** 262e75a33bfSAndreas Gohr * @dataProvider dataProvider 263d8ce5486SAndreas Gohr */ 264*d418c031SAndreas Gohr public function testSorting($set, $titlesort, $natsort, $nsfirst, $home, $current, $expect) 265d8ce5486SAndreas Gohr { 266e75a33bfSAndreas Gohr $simpleNavi = new \syntax_plugin_simplenavi(); 267*d418c031SAndreas Gohr $items = $simpleNavi->getSortedItems('simplenavi', $current, $titlesort, $natsort, $nsfirst, $home); 268e75a33bfSAndreas Gohr $this->assertSame($expect, array_column($items, 'id'), $set); 269d8ce5486SAndreas Gohr } 270d8ce5486SAndreas Gohr 271d8ce5486SAndreas Gohr} 272d8ce5486SAndreas Gohr 273d8ce5486SAndreas Gohr 274d8ce5486SAndreas Gohr 275