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