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