1<?php 2 3namespace dokuwiki\plugin\dw2pdf\test; 4 5use DokuWikiTest; 6 7/** 8 * @group plugin_dw2pdf 9 * @group plugins 10 */ 11class ActionPagenameSortTest extends DokuWikiTest 12{ 13 14 protected $pluginsEnabled = array('dw2pdf'); 15 16 public function testDirectPagenameSort() 17 { 18 $action = new \action_plugin_dw2pdf(); 19 20 $this->assertLessThan(0, $action->cbPagenameSort(['id' => 'bar'], ['id' => 'bar:start'])); 21 $this->assertGreaterThan(0, $action->cbPagenameSort(['id' => 'bar:bar'], ['id' => 'bar:start'])); 22 } 23 24 /** 25 * @return array 26 * @see testPageNameSort 27 */ 28 public function providerPageNameSort() 29 { 30 return [ 31 [ 32 'start pages sorted', 33 [ 34 'bar', 35 'bar:start', 36 'bar:alpha', 37 'bar:bar', 38 ], 39 ], 40 [ 41 'pages and subspaces mixed', 42 [ 43 'alpha', 44 'beta:foo', 45 'gamma', 46 ], 47 ], 48 [ 49 'full test', 50 [ 51 'start', 52 '01_page', 53 '10_page', 54 'bar', 55 'bar:start', 56 'bar:1_page', 57 'bar:2_page', 58 'bar:10_page', 59 'bar:22_page', 60 'bar:aa_page', 61 'bar:aa_page:detail1', 62 'bar:zz_page', 63 'foo', 64 'foo:start', 65 'foo:01_page', 66 'foo:10_page', 67 'foo:foo', 68 'foo:zz_page', 69 'ns', 70 'ns:01_page', 71 'ns:10_page', 72 'ns:ns', 73 'ns:zz_page', 74 'zz_page', 75 ], 76 ], 77 ]; 78 } 79 80 /** 81 * @dataProvider providerPageNameSort 82 * @param string $comment 83 * @param array $expected 84 */ 85 public function testPagenameSort($comment, $expected) 86 { 87 // prepare the array as expected in the sort function 88 $prepared = []; 89 foreach ($expected as $line) { 90 $prepared[] = ['id' => $line]; 91 } 92 93 // the input is random 94 $input = $prepared; 95 shuffle($input); 96 97 // run sort 98 $action = new \action_plugin_dw2pdf(); 99 usort($input, [$action, 'cbPagenameSort']); 100 101 $this->assertSame($prepared, $input); 102 } 103} 104 105