1b706c939SAndreas Gohr<?php 2b706c939SAndreas Gohr 3b706c939SAndreas Gohrnamespace dokuwiki\plugin\dw2pdf\test; 4b706c939SAndreas Gohr 5b706c939SAndreas Gohruse dokuwiki\plugin\dw2pdf\src\NamespaceCollector; 6b706c939SAndreas Gohruse DokuWikiTest; 7b706c939SAndreas Gohruse ReflectionClass; 8b706c939SAndreas Gohr 9b706c939SAndreas Gohr/** 10b706c939SAndreas Gohr * @group plugin_dw2pdf 11b706c939SAndreas Gohr * @group plugins 12b706c939SAndreas Gohr */ 13b706c939SAndreas Gohrclass NamespaceCollectorSortTest extends DokuWikiTest 14b706c939SAndreas Gohr{ 15b706c939SAndreas Gohr /** 16b706c939SAndreas Gohr * Provide a list of page orderings that should remain stable after sorting. 17b706c939SAndreas Gohr * 18b706c939SAndreas Gohr * @see testPagenameSort 19b706c939SAndreas Gohr * @return array 20b706c939SAndreas Gohr */ 21b706c939SAndreas Gohr public function providerPageNameSort(): array 22b706c939SAndreas Gohr { 23b706c939SAndreas Gohr return [ 24b706c939SAndreas Gohr 'start pages sorted' => [[ 25b706c939SAndreas Gohr 'bar', 26b706c939SAndreas Gohr 'bar:start', 27b706c939SAndreas Gohr 'bar:alpha', 28b706c939SAndreas Gohr 'bar:bar', 29b706c939SAndreas Gohr ]], 30b706c939SAndreas Gohr 31b706c939SAndreas Gohr 'pages and subspaces mixed' => [[ 32b706c939SAndreas Gohr 'alpha', 33b706c939SAndreas Gohr 'beta:foo', 34b706c939SAndreas Gohr 'gamma', 35b706c939SAndreas Gohr ]], 36b706c939SAndreas Gohr 37b706c939SAndreas Gohr 'full test' => [[ 38b706c939SAndreas Gohr 'start', 39b706c939SAndreas Gohr '01_page', 40b706c939SAndreas Gohr '10_page', 41b706c939SAndreas Gohr 'bar', 42b706c939SAndreas Gohr 'bar:start', 43b706c939SAndreas Gohr 'bar:1_page', 44b706c939SAndreas Gohr 'bar:2_page', 45b706c939SAndreas Gohr 'bar:10_page', 46b706c939SAndreas Gohr 'bar:22_page', 47b706c939SAndreas Gohr 'bar:aa_page', 48b706c939SAndreas Gohr 'bar:aa_page:detail1', 49b706c939SAndreas Gohr 'bar:zz_page', 50b706c939SAndreas Gohr 'foo', 51b706c939SAndreas Gohr 'foo:start', 52b706c939SAndreas Gohr 'foo:01_page', 53b706c939SAndreas Gohr 'foo:10_page', 54b706c939SAndreas Gohr 'foo:foo', 55b706c939SAndreas Gohr 'foo:zz_page', 56b706c939SAndreas Gohr 'ns', 57b706c939SAndreas Gohr 'ns:01_page', 58b706c939SAndreas Gohr 'ns:10_page', 59b706c939SAndreas Gohr 'ns:ns', 60b706c939SAndreas Gohr 'ns:zz_page', 61b706c939SAndreas Gohr 'zz_page', 62b706c939SAndreas Gohr ]], 63b706c939SAndreas Gohr ]; 64b706c939SAndreas Gohr } 65b706c939SAndreas Gohr 66b706c939SAndreas Gohr /** 67*92200750SAndreas Gohr * Ensure natural name sorting remains stable for multiple namespace scenarios. 68b706c939SAndreas Gohr * 69*92200750SAndreas Gohr * @dataProvider providerPageNameSort 70b706c939SAndreas Gohr * @param array $expected 71b706c939SAndreas Gohr */ 72b706c939SAndreas Gohr public function testPagenameSort(array $expected): void 73b706c939SAndreas Gohr { 74b706c939SAndreas Gohr // Build a namespace collector instance without running the heavy constructor logic. 75b706c939SAndreas Gohr $reflection = new ReflectionClass(NamespaceCollector::class); 76b706c939SAndreas Gohr /** @var NamespaceCollector $collector */ 77b706c939SAndreas Gohr $collector = $reflection->newInstanceWithoutConstructor(); 78b706c939SAndreas Gohr 79b706c939SAndreas Gohr $prepared = []; 80b706c939SAndreas Gohr foreach ($expected as $line) { 81b706c939SAndreas Gohr $prepared[] = ['id' => $line]; 82b706c939SAndreas Gohr } 83b706c939SAndreas Gohr 84b706c939SAndreas Gohr $input = $prepared; 85b706c939SAndreas Gohr shuffle($input); 86b706c939SAndreas Gohr 87b706c939SAndreas Gohr usort($input, [$collector, 'cbPagenameSort']); 88b706c939SAndreas Gohr 89b706c939SAndreas Gohr $this->assertSame($prepared, $input); 90b706c939SAndreas Gohr } 91b706c939SAndreas Gohr} 92