xref: /plugin/dw2pdf/_test/ActionPagenameSortTest.php (revision 852931daed0aa7c73fc4da5d421d2c117decf509)
132ff69b6SAndreas Gohr<?php
232ff69b6SAndreas Gohr
332ff69b6SAndreas Gohrnamespace dokuwiki\plugin\dw2pdf\test;
432ff69b6SAndreas Gohr
532ff69b6SAndreas Gohruse DokuWikiTest;
632ff69b6SAndreas Gohr
732ff69b6SAndreas Gohr/**
832ff69b6SAndreas Gohr * @group plugin_dw2pdf
932ff69b6SAndreas Gohr * @group plugins
1032ff69b6SAndreas Gohr */
1132ff69b6SAndreas Gohrclass ActionPagenameSortTest extends DokuWikiTest
1232ff69b6SAndreas Gohr{
1332ff69b6SAndreas Gohr
1432ff69b6SAndreas Gohr    protected $pluginsEnabled = array('dw2pdf');
1532ff69b6SAndreas Gohr
1632ff69b6SAndreas Gohr    public function testDirectPagenameSort()
1732ff69b6SAndreas Gohr    {
1832ff69b6SAndreas Gohr        $action = new \action_plugin_dw2pdf();
1932ff69b6SAndreas Gohr
20*852931daSAndreas Gohr        $this->assertLessThan(0, $action->cbPagenameSort(['id' => 'bar'], ['id' => 'bar:start']));
21*852931daSAndreas Gohr        $this->assertGreaterThan(0, $action->cbPagenameSort(['id' => 'bar:bar'], ['id' => 'bar:start']));
2232ff69b6SAndreas Gohr    }
2332ff69b6SAndreas Gohr
2432ff69b6SAndreas Gohr    /**
2532ff69b6SAndreas Gohr     * @return array
2632ff69b6SAndreas Gohr     * @see testPageNameSort
2732ff69b6SAndreas Gohr     */
2832ff69b6SAndreas Gohr    public function providerPageNameSort()
2932ff69b6SAndreas Gohr    {
3032ff69b6SAndreas Gohr        return [
3132ff69b6SAndreas Gohr            [
3232ff69b6SAndreas Gohr                'start pages sorted',
3332ff69b6SAndreas Gohr                [
3432ff69b6SAndreas Gohr                    'bar',
3532ff69b6SAndreas Gohr                    'bar:start',
3632ff69b6SAndreas Gohr                    'bar:alpha',
3732ff69b6SAndreas Gohr                    'bar:bar',
3832ff69b6SAndreas Gohr                ],
3932ff69b6SAndreas Gohr            ],
4032ff69b6SAndreas Gohr            [
4132ff69b6SAndreas Gohr                'pages and subspaces mixed',
4232ff69b6SAndreas Gohr                [
4332ff69b6SAndreas Gohr                    'alpha',
4432ff69b6SAndreas Gohr                    'beta:foo',
4532ff69b6SAndreas Gohr                    'gamma',
4632ff69b6SAndreas Gohr                ],
4732ff69b6SAndreas Gohr            ],
4832ff69b6SAndreas Gohr            [
4932ff69b6SAndreas Gohr                'full test',
5032ff69b6SAndreas Gohr                [
5132ff69b6SAndreas Gohr                    'start',
5232ff69b6SAndreas Gohr                    '01_page',
5332ff69b6SAndreas Gohr                    '10_page',
5432ff69b6SAndreas Gohr                    'bar',
5532ff69b6SAndreas Gohr                    'bar:start',
5632ff69b6SAndreas Gohr                    'bar:1_page',
5732ff69b6SAndreas Gohr                    'bar:2_page',
5832ff69b6SAndreas Gohr                    'bar:10_page',
5932ff69b6SAndreas Gohr                    'bar:22_page',
6032ff69b6SAndreas Gohr                    'bar:aa_page',
6132ff69b6SAndreas Gohr                    'bar:aa_page:detail1',
6232ff69b6SAndreas Gohr                    'bar:zz_page',
6332ff69b6SAndreas Gohr                    'foo',
6432ff69b6SAndreas Gohr                    'foo:start',
6532ff69b6SAndreas Gohr                    'foo:01_page',
6632ff69b6SAndreas Gohr                    'foo:10_page',
6732ff69b6SAndreas Gohr                    'foo:foo',
6832ff69b6SAndreas Gohr                    'foo:zz_page',
6932ff69b6SAndreas Gohr                    'ns',
7032ff69b6SAndreas Gohr                    'ns:01_page',
7132ff69b6SAndreas Gohr                    'ns:10_page',
7232ff69b6SAndreas Gohr                    'ns:ns',
7332ff69b6SAndreas Gohr                    'ns:zz_page',
7432ff69b6SAndreas Gohr                    'zz_page',
7532ff69b6SAndreas Gohr                ],
7632ff69b6SAndreas Gohr            ],
7732ff69b6SAndreas Gohr        ];
7832ff69b6SAndreas Gohr    }
7932ff69b6SAndreas Gohr
8032ff69b6SAndreas Gohr    /**
8132ff69b6SAndreas Gohr     * @dataProvider providerPageNameSort
8232ff69b6SAndreas Gohr     * @param string $comment
8332ff69b6SAndreas Gohr     * @param array $expected
8432ff69b6SAndreas Gohr     */
8532ff69b6SAndreas Gohr    public function testPagenameSort($comment, $expected)
8632ff69b6SAndreas Gohr    {
8732ff69b6SAndreas Gohr        // prepare the array as expected in the sort function
8832ff69b6SAndreas Gohr        $prepared = [];
8932ff69b6SAndreas Gohr        foreach ($expected as $line) {
9032ff69b6SAndreas Gohr            $prepared[] = ['id' => $line];
9132ff69b6SAndreas Gohr        }
9232ff69b6SAndreas Gohr
9332ff69b6SAndreas Gohr        // the input is random
9432ff69b6SAndreas Gohr        $input = $prepared;
9532ff69b6SAndreas Gohr        shuffle($input);
9632ff69b6SAndreas Gohr
9732ff69b6SAndreas Gohr        // run sort
9832ff69b6SAndreas Gohr        $action = new \action_plugin_dw2pdf();
99*852931daSAndreas Gohr        usort($input, [$action, 'cbPagenameSort']);
10032ff69b6SAndreas Gohr
10132ff69b6SAndreas Gohr        $this->assertSame($prepared, $input);
10232ff69b6SAndreas Gohr    }
10332ff69b6SAndreas Gohr}
10432ff69b6SAndreas Gohr
105