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'); 25*e75a33bfSAndreas Gohr 26*e75a33bfSAndreas Gohr $pages = [ 27*e75a33bfSAndreas Gohr ['namespace1:foo', 'Namespace 1 Foo'], 28*e75a33bfSAndreas Gohr ['namespace1:start', 'ZZZ Namespace 1 Start'], 29*e75a33bfSAndreas Gohr ['namespace2:foo', 'Namespace 2 Foo'], 30*e75a33bfSAndreas Gohr ['namespace2', 'Namespace 2 Start'], 31*e75a33bfSAndreas Gohr ['namespace12:foo', 'Namespace 12 Foo'], 32*e75a33bfSAndreas Gohr ['namespace12:start', 'Namespace 12 Start'], 33*e75a33bfSAndreas Gohr ['namespace123:namespace123', 'AAA Namespace 123 Start'], 34*e75a33bfSAndreas Gohr ['namespace123:foo', 'Namespace 123 Foo'], 35*e75a33bfSAndreas Gohr ['namespace123:deep:start', 'Namespace 123 Deep Start'], 36*e75a33bfSAndreas Gohr ['namespace123:deep:foo', 'Namespace 123 Deep Foo'], 37*e75a33bfSAndreas Gohr ['namespace21:foo', 'Namespace 21 Foo'], 38*e75a33bfSAndreas Gohr ['namespace21:start', 'Namespace 21 Start'], 39*e75a33bfSAndreas Gohr ]; 40*e75a33bfSAndreas Gohr 41*e75a33bfSAndreas Gohr foreach ($pages as $page) { 42*e75a33bfSAndreas Gohr saveWikiText('simplenavi:' . $page[0], '====== ' . $page[1] . ' ======', 'create test page'); 43*e75a33bfSAndreas Gohr } 44*e75a33bfSAndreas Gohr 45*e75a33bfSAndreas Gohr } 46*e75a33bfSAndreas Gohr 47*e75a33bfSAndreas Gohr public function dataProvider() { 48*e75a33bfSAndreas Gohr 49*e75a33bfSAndreas Gohr yield [ 50*e75a33bfSAndreas Gohr 'set' => 'by ID, all branches closed', 51*e75a33bfSAndreas Gohr 'titlesort' => false, 52*e75a33bfSAndreas Gohr 'natsort' => false, 53*e75a33bfSAndreas Gohr 'current' => 'simplenavi', 54*e75a33bfSAndreas Gohr 'expect' => [ 55*e75a33bfSAndreas Gohr 'simplenavi:namespace1:start', 56*e75a33bfSAndreas Gohr 'simplenavi:namespace12:start', 57*e75a33bfSAndreas Gohr 'simplenavi:namespace123:namespace123', 58*e75a33bfSAndreas Gohr 'simplenavi:namespace2', 59*e75a33bfSAndreas Gohr 'simplenavi:namespace21:start', 60*e75a33bfSAndreas Gohr ] 61*e75a33bfSAndreas Gohr ]; 62*e75a33bfSAndreas Gohr 63*e75a33bfSAndreas Gohr yield [ 64*e75a33bfSAndreas Gohr 'set' => 'by ID, Natural Sort, all branches closed', 65*e75a33bfSAndreas Gohr 'titlesort' => false, 66*e75a33bfSAndreas Gohr 'natsort' => true, 67*e75a33bfSAndreas Gohr 'current' => 'simplenavi', 68*e75a33bfSAndreas Gohr 'expect' => [ 69*e75a33bfSAndreas Gohr 'simplenavi:namespace1:start', 70*e75a33bfSAndreas Gohr 'simplenavi:namespace2', 71*e75a33bfSAndreas Gohr 'simplenavi:namespace12:start', 72*e75a33bfSAndreas Gohr 'simplenavi:namespace21:start', 73*e75a33bfSAndreas Gohr 'simplenavi:namespace123:namespace123', 74*e75a33bfSAndreas Gohr ] 75*e75a33bfSAndreas Gohr ]; 76*e75a33bfSAndreas Gohr 77*e75a33bfSAndreas Gohr yield [ 78*e75a33bfSAndreas Gohr 'set' => 'by ID, branch open', 79*e75a33bfSAndreas Gohr 'titlesort' => false, 80*e75a33bfSAndreas Gohr 'natsort' => false, 81*e75a33bfSAndreas Gohr 'current' => 'simplenavi:namespace123:deep:foo', 82*e75a33bfSAndreas Gohr 'expect' => [ 83*e75a33bfSAndreas Gohr 'simplenavi:namespace1:start', 84*e75a33bfSAndreas Gohr 'simplenavi:namespace12:start', 85*e75a33bfSAndreas Gohr 'simplenavi:namespace123:namespace123', 86*e75a33bfSAndreas Gohr 'simplenavi:namespace123:deep:start', 87*e75a33bfSAndreas Gohr 'simplenavi:namespace123:deep:foo', 88*e75a33bfSAndreas Gohr 'simplenavi:namespace123:foo', 89*e75a33bfSAndreas Gohr 'simplenavi:namespace2', 90*e75a33bfSAndreas Gohr 'simplenavi:namespace21:start', 91*e75a33bfSAndreas Gohr ] 92*e75a33bfSAndreas Gohr ]; 93*e75a33bfSAndreas Gohr 94*e75a33bfSAndreas Gohr yield [ 95*e75a33bfSAndreas Gohr 'set' => 'by ID, Natural Sort, branch open', 96*e75a33bfSAndreas Gohr 'titlesort' => false, 97*e75a33bfSAndreas Gohr 'natsort' => true, 98*e75a33bfSAndreas Gohr 'current' => 'simplenavi:namespace123:deep:foo', 99*e75a33bfSAndreas Gohr 'expect' => [ 100*e75a33bfSAndreas Gohr 'simplenavi:namespace1:start', 101*e75a33bfSAndreas Gohr 'simplenavi:namespace2', 102*e75a33bfSAndreas Gohr 'simplenavi:namespace12:start', 103*e75a33bfSAndreas Gohr 'simplenavi:namespace21:start', 104*e75a33bfSAndreas Gohr 'simplenavi:namespace123:namespace123', 105*e75a33bfSAndreas Gohr 'simplenavi:namespace123:deep:start', 106*e75a33bfSAndreas Gohr 'simplenavi:namespace123:deep:foo', 107*e75a33bfSAndreas Gohr 'simplenavi:namespace123:foo', 108*e75a33bfSAndreas Gohr ] 109*e75a33bfSAndreas Gohr ]; 110*e75a33bfSAndreas Gohr 111*e75a33bfSAndreas Gohr yield [ 112*e75a33bfSAndreas Gohr 'set' => 'by Title, all branches closed', 113*e75a33bfSAndreas Gohr 'titlesort' => true, 114*e75a33bfSAndreas Gohr 'natsort' => false, 115*e75a33bfSAndreas Gohr 'current' => 'simplenavi', 116*e75a33bfSAndreas Gohr 'expect' => [ 117*e75a33bfSAndreas Gohr 'simplenavi:namespace123:namespace123', 118*e75a33bfSAndreas Gohr 'simplenavi:namespace12:start', 119*e75a33bfSAndreas Gohr 'simplenavi:namespace2', 120*e75a33bfSAndreas Gohr 'simplenavi:namespace21:start', 121*e75a33bfSAndreas Gohr 'simplenavi:namespace1:start', 122*e75a33bfSAndreas Gohr ] 123*e75a33bfSAndreas Gohr ]; 124*e75a33bfSAndreas Gohr 125*e75a33bfSAndreas Gohr yield [ 126*e75a33bfSAndreas Gohr 'set' => 'by Title, Natural Search, all branches closed', 127*e75a33bfSAndreas Gohr 'titlesort' => true, 128*e75a33bfSAndreas Gohr 'natsort' => true, 129*e75a33bfSAndreas Gohr 'current' => 'simplenavi', 130*e75a33bfSAndreas Gohr 'expect' => [ 131*e75a33bfSAndreas Gohr 'simplenavi:namespace123:namespace123', 132*e75a33bfSAndreas Gohr 'simplenavi:namespace2', 133*e75a33bfSAndreas Gohr 'simplenavi:namespace12:start', 134*e75a33bfSAndreas Gohr 'simplenavi:namespace21:start', 135*e75a33bfSAndreas Gohr 'simplenavi:namespace1:start', 136*e75a33bfSAndreas Gohr ] 137*e75a33bfSAndreas Gohr ]; 138*e75a33bfSAndreas Gohr 139*e75a33bfSAndreas Gohr yield [ 140*e75a33bfSAndreas Gohr 'set' => 'by Title, branch open', 141*e75a33bfSAndreas Gohr 'titlesort' => true, 142*e75a33bfSAndreas Gohr 'natsort' => false, 143*e75a33bfSAndreas Gohr 'current' => 'simplenavi:namespace123:deep:foo', 144*e75a33bfSAndreas Gohr 'expect' => [ 145*e75a33bfSAndreas Gohr 'simplenavi:namespace123:namespace123', 146*e75a33bfSAndreas Gohr 'simplenavi:namespace123:deep:start', 147*e75a33bfSAndreas Gohr 'simplenavi:namespace123:deep:foo', 148*e75a33bfSAndreas Gohr 'simplenavi:namespace123:foo', 149*e75a33bfSAndreas Gohr 'simplenavi:namespace12:start', 150*e75a33bfSAndreas Gohr 'simplenavi:namespace2', 151*e75a33bfSAndreas Gohr 'simplenavi:namespace21:start', 152*e75a33bfSAndreas Gohr 'simplenavi:namespace1:start', 153*e75a33bfSAndreas Gohr ] 154*e75a33bfSAndreas Gohr ]; 155*e75a33bfSAndreas Gohr 156*e75a33bfSAndreas Gohr yield [ 157*e75a33bfSAndreas Gohr 'set' => 'by Title, Natural Sort, branch open', 158*e75a33bfSAndreas Gohr 'titlesort' => true, 159*e75a33bfSAndreas Gohr 'natsort' => true, 160*e75a33bfSAndreas Gohr 'current' => 'simplenavi:namespace123:deep:foo', 161*e75a33bfSAndreas Gohr 'expect' => [ 162*e75a33bfSAndreas Gohr 'simplenavi:namespace123:namespace123', 163*e75a33bfSAndreas Gohr 'simplenavi:namespace123:deep:start', 164*e75a33bfSAndreas Gohr 'simplenavi:namespace123:deep:foo', 165*e75a33bfSAndreas Gohr 'simplenavi:namespace123:foo', 166*e75a33bfSAndreas Gohr 'simplenavi:namespace2', 167*e75a33bfSAndreas Gohr 'simplenavi:namespace12:start', 168*e75a33bfSAndreas Gohr 'simplenavi:namespace21:start', 169*e75a33bfSAndreas Gohr 'simplenavi:namespace1:start', 170*e75a33bfSAndreas Gohr ] 171*e75a33bfSAndreas Gohr ]; 172d8ce5486SAndreas Gohr 173d8ce5486SAndreas Gohr } 174d8ce5486SAndreas Gohr 175d8ce5486SAndreas Gohr /** 176*e75a33bfSAndreas Gohr * @dataProvider dataProvider 177d8ce5486SAndreas Gohr */ 178*e75a33bfSAndreas Gohr public function testSorting($set, $titlesort, $natsort, $current, $expect) 179d8ce5486SAndreas Gohr { 180*e75a33bfSAndreas Gohr $simpleNavi = new \syntax_plugin_simplenavi(); 181*e75a33bfSAndreas Gohr $items = $simpleNavi->getSortedItems('simplenavi', $current, $titlesort, $natsort); 182*e75a33bfSAndreas Gohr $this->assertSame($expect, array_column($items, 'id'), $set); 183d8ce5486SAndreas Gohr } 184d8ce5486SAndreas Gohr 185d8ce5486SAndreas Gohr} 186d8ce5486SAndreas Gohr 187d8ce5486SAndreas Gohr 188d8ce5486SAndreas Gohr 189