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