1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpMyAdmin\SqlParser\Tests\Components; |
4
|
|
|
|
5
|
|
|
use PhpMyAdmin\SqlParser\Components\OptionsArray; |
6
|
|
|
use PhpMyAdmin\SqlParser\Parser; |
7
|
|
|
use PhpMyAdmin\SqlParser\Tests\TestCase; |
8
|
|
|
|
9
|
|
|
class OptionsArrayTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
public function testParse() |
12
|
|
|
{ |
13
|
|
|
$component = OptionsArray::parse( |
14
|
|
|
new Parser(), |
15
|
|
|
$this->getTokensList('A B = /*comment*/ (test) C'), |
16
|
|
|
array( |
17
|
|
|
'A' => 1, |
18
|
|
|
'B' => array( |
19
|
|
|
2, |
20
|
|
|
'var', |
21
|
|
|
), |
22
|
|
|
'C' => 3 |
23
|
|
|
) |
24
|
|
|
); |
25
|
|
|
$this->assertEquals( |
26
|
|
|
array( |
27
|
|
|
1 => 'A', |
28
|
|
|
2 => array( |
29
|
|
|
'name' => 'B', |
30
|
|
|
'expr' => '(test)', |
31
|
|
|
'value' => 'test', |
32
|
|
|
'equals' => true, |
33
|
|
|
), |
34
|
|
|
3 => 'C', |
35
|
|
|
), |
36
|
|
|
$component->options |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testParseExpr() |
41
|
|
|
{ |
42
|
|
|
$component = OptionsArray::parse( |
43
|
|
|
new Parser(), |
44
|
|
|
$this->getTokensList('SUM = (3 + 5) RESULT = 8'), |
45
|
|
|
array( |
46
|
|
|
'SUM' => array( |
47
|
|
|
1, |
48
|
|
|
'expr', |
49
|
|
|
array('parenthesesDelimited' => true), |
50
|
|
|
), |
51
|
|
|
'RESULT' => array( |
52
|
|
|
2, |
53
|
|
|
'var', |
54
|
|
|
) |
55
|
|
|
) |
56
|
|
|
); |
57
|
|
|
$this->assertEquals('(3 + 5)', (string) $component->has('SUM', true)); |
58
|
|
|
$this->assertEquals('8', $component->has('RESULT')); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testHas() |
62
|
|
|
{ |
63
|
|
|
$component = OptionsArray::parse( |
64
|
|
|
new Parser(), |
65
|
|
|
$this->getTokensList('A B = /*comment*/ (test) C'), |
66
|
|
|
array( |
67
|
|
|
'A' => 1, |
68
|
|
|
'B' => array( |
69
|
|
|
2, |
70
|
|
|
'var', |
71
|
|
|
), |
72
|
|
|
'C' => 3 |
73
|
|
|
) |
74
|
|
|
); |
75
|
|
|
$this->assertTrue($component->has('A')); |
76
|
|
|
$this->assertEquals('test', $component->has('B')); |
77
|
|
|
$this->assertTrue($component->has('C')); |
78
|
|
|
$this->assertFalse($component->has('D')); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testRemove() |
82
|
|
|
{ |
83
|
|
|
/* Assertion 1 */ |
84
|
|
|
$component = new OptionsArray(array('a', 'b', 'c')); |
85
|
|
|
$this->assertTrue($component->remove('b')); |
86
|
|
|
$this->assertFalse($component->remove('d')); |
87
|
|
|
$this->assertEquals($component->options, array(0 => 'a', 2 => 'c')); |
88
|
|
|
|
89
|
|
|
/* Assertion 2 */ |
90
|
|
|
$component = OptionsArray::parse( |
91
|
|
|
new Parser(), |
92
|
|
|
$this->getTokensList('A B = /*comment*/ (test) C'), |
93
|
|
|
array( |
94
|
|
|
'A' => 1, |
95
|
|
|
'B' => array( |
96
|
|
|
2, |
97
|
|
|
'var', |
98
|
|
|
), |
99
|
|
|
'C' => 3 |
100
|
|
|
) |
101
|
|
|
); |
102
|
|
|
$this->assertEquals('test', $component->has('B')); |
103
|
|
|
$component->remove('B'); |
104
|
|
|
$this->assertFalse($component->has('B')); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function testMerge() |
108
|
|
|
{ |
109
|
|
|
$component = new OptionsArray(array('a')); |
110
|
|
|
$component->merge(array('b', 'c')); |
111
|
|
|
$this->assertEquals($component->options, array('a', 'b', 'c')); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testBuild() |
115
|
|
|
{ |
116
|
|
|
$component = new OptionsArray( |
117
|
|
|
array( |
118
|
|
|
'ALL', |
119
|
|
|
'SQL_CALC_FOUND_ROWS', |
120
|
|
|
array( |
121
|
|
|
'name' => 'MAX_STATEMENT_TIME', |
122
|
|
|
'value' => '42', |
123
|
|
|
'equals' => true, |
124
|
|
|
), |
125
|
|
|
) |
126
|
|
|
); |
127
|
|
|
$this->assertEquals( |
128
|
|
|
OptionsArray::build($component), |
129
|
|
|
'ALL SQL_CALC_FOUND_ROWS MAX_STATEMENT_TIME=42' |
130
|
|
|
); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|