1d8ce5486SAndreas Gohr<?php 2d8ce5486SAndreas Gohr 3d8ce5486SAndreas Gohrnamespace dokuwiki\plugin\simplenavi\test; 4d8ce5486SAndreas Gohr 5*4c5e7fe5SAndreas Gohruse dokuwiki\TreeBuilder\PageTreeBuilder; 6d8ce5486SAndreas Gohruse DokuWikiTest; 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'], 28d418c031SAndreas 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 48d418c031SAndreas Gohr public function dataProvider() 49d418c031SAndreas Gohr { 50e75a33bfSAndreas Gohr 51e75a33bfSAndreas Gohr yield [ 52e75a33bfSAndreas Gohr 'set' => 'by ID, all branches closed', 53*4c5e7fe5SAndreas Gohr 'sort' => 'id', 54*4c5e7fe5SAndreas Gohr 'usetitle' => false, 55d418c031SAndreas Gohr 'home' => false, 56e58e2f72SAndreas Gohr 'current' => 'simplenavi:page', 57e75a33bfSAndreas Gohr 'expect' => [ 58*4c5e7fe5SAndreas Gohr '+simplenavi:foo', 59*4c5e7fe5SAndreas Gohr '+simplenavi:namespace1:start', 60*4c5e7fe5SAndreas Gohr '+simplenavi:namespace12:start', 61*4c5e7fe5SAndreas Gohr '+simplenavi:namespace123:namespace123', 62*4c5e7fe5SAndreas Gohr '+simplenavi:namespace2', 63*4c5e7fe5SAndreas Gohr '+simplenavi:namespace21:start', 64e75a33bfSAndreas Gohr ] 65e75a33bfSAndreas Gohr ]; 66e75a33bfSAndreas Gohr 67e75a33bfSAndreas Gohr yield [ 68e75a33bfSAndreas Gohr 'set' => 'by ID, branch open', 69*4c5e7fe5SAndreas Gohr 'sort' => 'id', 70*4c5e7fe5SAndreas Gohr 'usetitle' => false, 71d418c031SAndreas Gohr 'home' => false, 72e75a33bfSAndreas Gohr 'current' => 'simplenavi:namespace123:deep:foo', 73e75a33bfSAndreas Gohr 'expect' => [ 74*4c5e7fe5SAndreas Gohr '+simplenavi:foo', 75*4c5e7fe5SAndreas Gohr '+simplenavi:namespace1:start', 76*4c5e7fe5SAndreas Gohr '+simplenavi:namespace12:start', 77*4c5e7fe5SAndreas Gohr '+simplenavi:namespace123:namespace123', 78*4c5e7fe5SAndreas Gohr '++simplenavi:namespace123:deep:start', 79*4c5e7fe5SAndreas Gohr '+++simplenavi:namespace123:deep:foo', 80*4c5e7fe5SAndreas Gohr '++simplenavi:namespace123:foo', 81*4c5e7fe5SAndreas Gohr '+simplenavi:namespace2', 82*4c5e7fe5SAndreas Gohr '+simplenavi:namespace21:start', 83e75a33bfSAndreas Gohr ] 84e75a33bfSAndreas Gohr ]; 85e75a33bfSAndreas Gohr 86e75a33bfSAndreas Gohr 87e75a33bfSAndreas Gohr yield [ 88e75a33bfSAndreas Gohr 'set' => 'by Title, Natural Search, all branches closed', 89*4c5e7fe5SAndreas Gohr 'sort' => 'title', 90*4c5e7fe5SAndreas Gohr 'usetitle' => true, 91d418c031SAndreas Gohr 'home' => false, 92e58e2f72SAndreas Gohr 'current' => 'simplenavi:page', 93e75a33bfSAndreas Gohr 'expect' => [ 94*4c5e7fe5SAndreas Gohr '+simplenavi:namespace123:namespace123', 95*4c5e7fe5SAndreas Gohr '+simplenavi:foo', 96*4c5e7fe5SAndreas Gohr '+simplenavi:namespace2', 97*4c5e7fe5SAndreas Gohr '+simplenavi:namespace12:start', 98*4c5e7fe5SAndreas Gohr '+simplenavi:namespace21:start', 99*4c5e7fe5SAndreas Gohr '+simplenavi:namespace1:start', 100e75a33bfSAndreas Gohr ] 101e75a33bfSAndreas Gohr ]; 102e75a33bfSAndreas Gohr 103e75a33bfSAndreas Gohr yield [ 104e75a33bfSAndreas Gohr 'set' => 'by Title, Natural Sort, branch open', 105*4c5e7fe5SAndreas Gohr 'sort' => 'title', 106*4c5e7fe5SAndreas Gohr 'usetitle' => true, 107d418c031SAndreas Gohr 'home' => false, 108e58e2f72SAndreas Gohr 'current' => 'simplenavi:namespace123:deep:foo', 109e58e2f72SAndreas Gohr 'expect' => [ 110*4c5e7fe5SAndreas Gohr '+simplenavi:namespace123:namespace123', 111*4c5e7fe5SAndreas Gohr '++simplenavi:namespace123:deep:start', 112*4c5e7fe5SAndreas Gohr '+++simplenavi:namespace123:deep:foo', 113*4c5e7fe5SAndreas Gohr '++simplenavi:namespace123:foo', 114*4c5e7fe5SAndreas Gohr '+simplenavi:foo', 115*4c5e7fe5SAndreas Gohr '+simplenavi:namespace2', 116*4c5e7fe5SAndreas Gohr '+simplenavi:namespace12:start', 117*4c5e7fe5SAndreas Gohr '+simplenavi:namespace21:start', 118*4c5e7fe5SAndreas Gohr '+simplenavi:namespace1:start', 119e58e2f72SAndreas Gohr ] 120e58e2f72SAndreas Gohr ]; 121e58e2f72SAndreas Gohr 122e58e2f72SAndreas Gohr yield [ 123e58e2f72SAndreas Gohr 'set' => 'by Title, Natural Sort, NS first, branch open', 124*4c5e7fe5SAndreas Gohr 'sort' => 'ns_title', 125*4c5e7fe5SAndreas Gohr 'usetitle' => true, 126d418c031SAndreas Gohr 'home' => false, 127e75a33bfSAndreas Gohr 'current' => 'simplenavi:namespace123:deep:foo', 128e75a33bfSAndreas Gohr 'expect' => [ 129*4c5e7fe5SAndreas Gohr '+simplenavi:namespace123:namespace123', 130*4c5e7fe5SAndreas Gohr '++simplenavi:namespace123:deep:start', 131*4c5e7fe5SAndreas Gohr '+++simplenavi:namespace123:deep:foo', 132*4c5e7fe5SAndreas Gohr '++simplenavi:namespace123:foo', 133*4c5e7fe5SAndreas Gohr '+simplenavi:namespace2', 134*4c5e7fe5SAndreas Gohr '+simplenavi:namespace12:start', 135*4c5e7fe5SAndreas Gohr '+simplenavi:namespace21:start', 136*4c5e7fe5SAndreas Gohr '+simplenavi:namespace1:start', 137*4c5e7fe5SAndreas Gohr '+simplenavi:foo', 138e75a33bfSAndreas Gohr ] 139e75a33bfSAndreas Gohr ]; 140d418c031SAndreas Gohr 141d418c031SAndreas Gohr yield [ 142d418c031SAndreas Gohr 'set' => 'by ID, branch open with home level', 143*4c5e7fe5SAndreas Gohr 'sort' => 'id', 144*4c5e7fe5SAndreas Gohr 'usetitle' => false, 145d418c031SAndreas Gohr 'home' => true, 146d418c031SAndreas Gohr 'current' => 'simplenavi:namespace123:deep:foo', 147d418c031SAndreas Gohr 'expect' => [ 148*4c5e7fe5SAndreas Gohr '+simplenavi:simplenavi', 149*4c5e7fe5SAndreas Gohr '++simplenavi:foo', 150*4c5e7fe5SAndreas Gohr '++simplenavi:namespace1:start', 151*4c5e7fe5SAndreas Gohr '++simplenavi:namespace12:start', 152*4c5e7fe5SAndreas Gohr '++simplenavi:namespace123:namespace123', 153*4c5e7fe5SAndreas Gohr '+++simplenavi:namespace123:deep:start', 154*4c5e7fe5SAndreas Gohr '++++simplenavi:namespace123:deep:foo', 155*4c5e7fe5SAndreas Gohr '+++simplenavi:namespace123:foo', 156*4c5e7fe5SAndreas Gohr '++simplenavi:namespace2', 157*4c5e7fe5SAndreas Gohr '++simplenavi:namespace21:start', 158d418c031SAndreas Gohr ] 159d418c031SAndreas Gohr ]; 160d8ce5486SAndreas Gohr } 161d8ce5486SAndreas Gohr 162d8ce5486SAndreas Gohr /** 163e75a33bfSAndreas Gohr * @dataProvider dataProvider 164d8ce5486SAndreas Gohr */ 165*4c5e7fe5SAndreas Gohr public function testSorting($set, $sort, $usetitle, $home, $current, $expect) 166d8ce5486SAndreas Gohr { 167e75a33bfSAndreas Gohr $simpleNavi = new \syntax_plugin_simplenavi(); 168*4c5e7fe5SAndreas Gohr 169*4c5e7fe5SAndreas Gohr $simpleNavi->initState('simplenavi', $current, $usetitle, $sort, $home); 170*4c5e7fe5SAndreas Gohr 171*4c5e7fe5SAndreas Gohr /** @var PageTreeBuilder $tree */ 172*4c5e7fe5SAndreas Gohr $tree = $this->callInaccessibleMethod($simpleNavi, 'getTree', []); 173*4c5e7fe5SAndreas Gohr 174*4c5e7fe5SAndreas Gohr 175*4c5e7fe5SAndreas Gohr $this->assertSame(join("\n", $expect), (string) $tree, $set); 176d8ce5486SAndreas Gohr } 177d8ce5486SAndreas Gohr 178d8ce5486SAndreas Gohr} 179d8ce5486SAndreas Gohr 180d8ce5486SAndreas Gohr 181d8ce5486SAndreas Gohr 182