xref: /plugin/struct/_test/ConfigParserTest.php (revision d90aa848684950ae06490f12279278db183f4fa5)
1<?php
2
3namespace dokuwiki\plugin\struct\test;
4
5use dokuwiki\plugin\struct\meta;
6
7/**
8 * Tests for parsing the aggregation config for the struct plugin
9 *
10 * @group plugin_struct
11 * @group plugins
12 *
13 */
14class ConfigParserTest extends StructTest
15{
16
17    public function test_simple()
18    {
19        $lines = [
20            "schema    : testtable, another, foo bar",
21            "cols      : %pageid%, count",
22            "sort      : ^count",
23            "sort      : %pageid%, ^bam",
24            "align     : r,l,center,foo"
25        ];
26
27        $configParser = new meta\ConfigParser($lines);
28        $actual_config = $configParser->getConfig();
29
30        $expected_config = [
31            'limit' => 0,
32            'dynfilters' => false,
33            'summarize' => false,
34            'rownumbers' => false,
35            'sepbyheaders' => false,
36            'headers' =>
37                [
38                    0 => NULL,
39                    1 => NULL,
40                ],
41            'widths' =>
42                [],
43            'filter' =>
44                [],
45            'schemas' =>
46                [
47                    0 =>
48                        [
49                            0 => 'testtable',
50                            1 => '',
51                        ],
52                    1 =>
53                        [
54                            0 => 'another',
55                            1 => '',
56                        ],
57                    2 =>
58                        [
59                            0 => 'foo',
60                            1 => 'bar',
61                        ],
62                ],
63            'cols' =>
64                [
65                    0 => '%pageid%',
66                    1 => 'count',
67                ],
68            'sort' =>
69                [
70                    [
71                        0 => 'count',
72                        1 => false,
73                    ],
74                    [
75                        0 => '%pageid%',
76                        1 => true,
77                    ],
78                    [
79                        0 => 'bam',
80                        1 => false,
81                    ]
82                ],
83            'csv' => true,
84            'target' => '',
85            'align' => ['right', 'left', 'center', null],
86            'nesting' => 0,
87        ];
88
89        $this->assertEquals($expected_config, $actual_config);
90    }
91
92    public function test_width()
93    {
94        $lines = ['width: 5, 15px, 23.4em, meh, 10em'];
95
96        $configParser = new meta\ConfigParser($lines);
97
98        $config = $configParser->getConfig();
99
100        $this->assertEquals(
101            ['5px', '15px', '23.4em', '', '10em'],
102            $config['widths']
103        );
104    }
105
106    /**
107     * @see test_splitLine
108     */
109    public function provide_splitLine()
110    {
111        return [
112            ['', ['', '']],
113            ['   ', ['', '']],
114            ['foo', ['foo', '']],
115            ['foo:bar', ['foo', 'bar']],
116            ['foo: bar', ['foo', 'bar']],
117            ['fOO: bar', ['foo', 'bar']],
118            ['  fOO: bar  ', ['foo', 'bar']],
119        ];
120    }
121
122    /**
123     * @dataProvider provide_splitLine
124     */
125    public function test_splitLine($line, $expected)
126    {
127        $configParser = new meta\ConfigParser(array());
128        $actual = $this->callInaccessibleMethod($configParser, 'splitLine', [$line]);
129        $this->assertEquals($expected, $actual);
130    }
131}
132