1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace StefanoTreeTest\Unit\NestedSet; |
6
|
|
|
|
7
|
|
|
use StefanoTree\NestedSet\Options; |
8
|
|
|
use StefanoTreeTest\UnitTestCase; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @internal |
12
|
|
|
*/ |
13
|
|
|
class OptionsTest extends UnitTestCase |
14
|
|
|
{ |
15
|
|
|
public function testThrowExceptionIfAllRequiredSettingsAreNotProvided() |
16
|
|
|
{ |
17
|
|
|
$this->expectException(\StefanoTree\Exception\InvalidArgumentException::class); |
18
|
|
|
$this->expectExceptionMessage('tableName, idColumnName must be set'); |
19
|
|
|
|
20
|
|
|
new Options(array()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @return \StefanoTree\NestedSet\Options |
25
|
|
|
*/ |
26
|
|
|
private function getOptionsWithDefaultSettings() |
27
|
|
|
{ |
28
|
|
|
return new Options(array( |
29
|
|
|
'tableName' => 'table', |
30
|
|
|
'idColumnName' => 'id', |
31
|
|
|
)); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testThrowExceptionIfTrySetWrongTableName() |
35
|
|
|
{ |
36
|
|
|
$optionsStub = $this->getOptionsWithDefaultSettings(); |
37
|
|
|
|
38
|
|
|
$this->expectException(\StefanoTree\Exception\InvalidArgumentException::class); |
39
|
|
|
$this->expectExceptionMessage('tableName cannot be empty'); |
40
|
|
|
|
41
|
|
|
$optionsStub->setTableName(' '); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testThrowExceptionIfTrySetWrongIdColumnName() |
45
|
|
|
{ |
46
|
|
|
$optionsStub = $this->getOptionsWithDefaultSettings(); |
47
|
|
|
|
48
|
|
|
$this->expectException(\StefanoTree\Exception\InvalidArgumentException::class); |
49
|
|
|
$this->expectExceptionMessage('idColumnName cannot be empty'); |
50
|
|
|
|
51
|
|
|
$optionsStub->setIdColumnName(' '); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testThrowExceptionIfTrySetWrongLeftColumnName() |
55
|
|
|
{ |
56
|
|
|
$optionsStub = $this->getOptionsWithDefaultSettings(); |
57
|
|
|
|
58
|
|
|
$this->expectException(\StefanoTree\Exception\InvalidArgumentException::class); |
59
|
|
|
$this->expectExceptionMessage('leftColumnName cannot be empty'); |
60
|
|
|
|
61
|
|
|
$optionsStub->setLeftColumnName(' '); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testThrowExceptionIfTrySetWrongRightColumnName() |
65
|
|
|
{ |
66
|
|
|
$optionsStub = $this->getOptionsWithDefaultSettings(); |
67
|
|
|
|
68
|
|
|
$this->expectException(\StefanoTree\Exception\InvalidArgumentException::class); |
69
|
|
|
$this->expectExceptionMessage('rightColumnName cannot be empty'); |
70
|
|
|
|
71
|
|
|
$optionsStub->setRightColumnName(' '); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testThrowExceptionIfTrySetWrongLevelColumnName() |
75
|
|
|
{ |
76
|
|
|
$optionsStub = $this->getOptionsWithDefaultSettings(); |
77
|
|
|
|
78
|
|
|
$this->expectException(\StefanoTree\Exception\InvalidArgumentException::class); |
79
|
|
|
$this->expectExceptionMessage('levelColumnName cannot be empty'); |
80
|
|
|
|
81
|
|
|
$optionsStub->setLevelColumnName(' '); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testThrowExceptionIfTrySetWrongParentIdColumnName() |
85
|
|
|
{ |
86
|
|
|
$optionsStub = $this->getOptionsWithDefaultSettings(); |
87
|
|
|
|
88
|
|
|
$this->expectException(\StefanoTree\Exception\InvalidArgumentException::class); |
89
|
|
|
$this->expectExceptionMessage('parentIdColumnName cannot be empty'); |
90
|
|
|
|
91
|
|
|
$optionsStub->setParentIdColumnName(' '); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testGetTableName() |
95
|
|
|
{ |
96
|
|
|
$optionsStub = $this->getOptionsWithDefaultSettings(); |
97
|
|
|
|
98
|
|
|
$optionsStub->setTableName(' table '); |
99
|
|
|
|
100
|
|
|
$this->assertEquals('table', $optionsStub->getTableName()); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function testGetIdColumnName() |
104
|
|
|
{ |
105
|
|
|
$optionsStub = $this->getOptionsWithDefaultSettings(); |
106
|
|
|
|
107
|
|
|
$optionsStub->setIdColumnName(' id '); |
108
|
|
|
|
109
|
|
|
$this->assertEquals('id', $optionsStub->getIdColumnName()); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function testGetLeftColumnName() |
113
|
|
|
{ |
114
|
|
|
$optionsStub = $this->getOptionsWithDefaultSettings(); |
115
|
|
|
|
116
|
|
|
$this->assertEquals('lft', $optionsStub->getLeftColumnName(), 'Wrong default value'); |
117
|
|
|
|
118
|
|
|
$optionsStub->setLeftColumnName(' left '); |
119
|
|
|
|
120
|
|
|
$this->assertEquals('left', $optionsStub->getLeftColumnName()); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function testGetRightColumnName() |
124
|
|
|
{ |
125
|
|
|
$optionsStub = $this->getOptionsWithDefaultSettings(); |
126
|
|
|
|
127
|
|
|
$this->assertEquals('rgt', $optionsStub->getRightColumnName(), 'Wrong default value'); |
128
|
|
|
|
129
|
|
|
$optionsStub->setRightColumnName(' right '); |
130
|
|
|
|
131
|
|
|
$this->assertEquals('right', $optionsStub->getRightColumnName()); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function testGetLevelColumnName() |
135
|
|
|
{ |
136
|
|
|
$optionsStub = $this->getOptionsWithDefaultSettings(); |
137
|
|
|
|
138
|
|
|
$this->assertEquals('level', $optionsStub->getLevelColumnName(), 'Wrong default value'); |
139
|
|
|
|
140
|
|
|
$optionsStub->setLevelColumnName(' lvl '); |
141
|
|
|
|
142
|
|
|
$this->assertEquals('lvl', $optionsStub->getLevelColumnName()); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function testGetParentIdColumnName() |
146
|
|
|
{ |
147
|
|
|
$optionsStub = $this->getOptionsWithDefaultSettings(); |
148
|
|
|
|
149
|
|
|
$this->assertEquals('parent_id', $optionsStub->getParentIdColumnName(), 'Wrong default value'); |
150
|
|
|
|
151
|
|
|
$optionsStub->setParentIdColumnName(' prt '); |
152
|
|
|
|
153
|
|
|
$this->assertEquals('prt', $optionsStub->getParentIdColumnName()); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function testGetSequenceName() |
157
|
|
|
{ |
158
|
|
|
$optionsStub = $this->getOptionsWithDefaultSettings(); |
159
|
|
|
|
160
|
|
|
$this->assertEquals('', $optionsStub->getSequenceName(), 'Wrong default value'); |
161
|
|
|
|
162
|
|
|
$optionsStub->setSequenceName(' seq '); |
163
|
|
|
|
164
|
|
|
$this->assertEquals('seq', $optionsStub->getSequenceName()); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function testGetDefaultScopeColumnName() |
168
|
|
|
{ |
169
|
|
|
$optionsStub = $this->getOptionsWithDefaultSettings(); |
170
|
|
|
|
171
|
|
|
$this->assertEquals('', $optionsStub->getScopeColumnName()); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function testSetScopeColumnName() |
175
|
|
|
{ |
176
|
|
|
$optionsStub = $this->getOptionsWithDefaultSettings(); |
177
|
|
|
|
178
|
|
|
$optionsStub->setScopeColumnName(' scope '); |
179
|
|
|
|
180
|
|
|
$this->assertEquals('scope', $optionsStub->getScopeColumnName()); |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|