1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace StefanoTreeTest\Integration\Manipulator; |
6
|
|
|
|
7
|
|
|
use StefanoTree\NestedSet\Manipulator\Manipulator; |
8
|
|
|
use StefanoTree\NestedSet\Manipulator\ManipulatorInterface as ManipulatorInterface; |
9
|
|
|
use StefanoTree\NestedSet\NodeInfo; |
10
|
|
|
use StefanoTree\NestedSet\Options; |
11
|
|
|
use StefanoTreeTest\IntegrationTestCase; |
12
|
|
|
use StefanoTreeTest\TestUtil; |
13
|
|
|
|
14
|
|
|
class ManipulatorWithScopeTest extends IntegrationTestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var ManipulatorInterface |
18
|
|
|
*/ |
19
|
|
|
protected $manipulator; |
20
|
|
|
|
21
|
|
|
protected function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->manipulator = $this->getManipulator(); |
24
|
|
|
|
25
|
|
|
parent::setUp(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function tearDown() |
29
|
|
|
{ |
30
|
|
|
$this->manipulator = null; |
31
|
|
|
parent::tearDown(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return ManipulatorInterface |
36
|
|
|
*/ |
37
|
|
|
protected function getManipulator(): ManipulatorInterface |
38
|
|
|
{ |
39
|
|
|
$options = new Options(array( |
40
|
|
|
'tableName' => 'tree_traversal_with_scope', |
41
|
|
|
'idColumnName' => 'tree_traversal_id', |
42
|
|
|
'scopeColumnName' => 'scope', |
43
|
|
|
)); |
44
|
|
|
|
45
|
|
|
if ('pgsql' == TEST_STEFANO_DB_VENDOR) { |
46
|
|
|
$options->setSequenceName('tree_traversal_with_scope_tree_traversal_id_seq'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return new Manipulator($options, TestUtil::buildAdapter($options)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function getDataSet() |
53
|
|
|
{ |
54
|
|
|
return $this->createMySQLXMLDataSet(__DIR__.'/_files/adapter/with_scope/initDataSet.xml'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testUpdateDataDoesNotChangeMetadata() |
58
|
|
|
{ |
59
|
|
|
$data = array( |
60
|
|
|
'name' => 'changed', |
61
|
|
|
'lft' => 'a', |
62
|
|
|
'rgt' => 'b', |
63
|
|
|
'parent_id' => 'c', |
64
|
|
|
'level' => 'd', |
65
|
|
|
'scope' => 'e', |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$this->manipulator |
69
|
|
|
->update(2, $data); |
70
|
|
|
|
71
|
|
|
$this->assertCompareDataSet(array('tree_traversal_with_scope'), __DIR__.'/_files/adapter/with_scope/testUpdateData.xml'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testInsertDataDoesNotChangeMetadata() |
75
|
|
|
{ |
76
|
|
|
$nodeInfo = new NodeInfo(null, 6, 1001, 1002, 1003, 1004); |
77
|
|
|
|
78
|
|
|
$data = array( |
79
|
|
|
'name' => 'some-name', |
80
|
|
|
'lft' => 'a', |
81
|
|
|
'rgt' => 'b', |
82
|
|
|
'parent_id' => 'c', |
83
|
|
|
'level' => 'd', |
84
|
|
|
'scope' => 'e', |
85
|
|
|
); |
86
|
|
|
|
87
|
|
|
$this->manipulator |
88
|
|
|
->insert($nodeInfo, $data); |
89
|
|
|
|
90
|
|
|
$this->assertCompareDataSet(array('tree_traversal_with_scope'), __DIR__.'/_files/adapter/with_scope/testInsertData.xml'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function testDeleteBranch() |
94
|
|
|
{ |
95
|
|
|
$this->manipulator |
96
|
|
|
->delete(2); |
97
|
|
|
|
98
|
|
|
$this->assertCompareDataSet(array('tree_traversal_with_scope'), __DIR__.'/_files/adapter/with_scope/testDeleteBranch.xml'); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testMoveLeftIndexes() |
102
|
|
|
{ |
103
|
|
|
$this->manipulator |
104
|
|
|
->moveLeftIndexes(3, 500, 2); |
105
|
|
|
|
106
|
|
|
$this->assertCompareDataSet(array('tree_traversal_with_scope'), __DIR__.'/_files/adapter/with_scope/testMoveLeftIndexes.xml'); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function testMoveRightIndexes() |
110
|
|
|
{ |
111
|
|
|
$this->manipulator |
112
|
|
|
->moveRightIndexes(4, 500, 2); |
113
|
|
|
|
114
|
|
|
$this->assertCompareDataSet(array('tree_traversal_with_scope'), __DIR__.'/_files/adapter/with_scope/testMoveRightIndexes.xml'); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function testUpdateLevels() |
118
|
|
|
{ |
119
|
|
|
$this->manipulator |
120
|
|
|
->updateLevels(2, 9, 500, 2); |
121
|
|
|
|
122
|
|
|
$this->assertCompareDataSet(array('tree_traversal_with_scope'), __DIR__.'/_files/adapter/with_scope/testUpdateLevels.xml'); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function testMoveBranch() |
126
|
|
|
{ |
127
|
|
|
$this->manipulator |
128
|
|
|
->moveBranch(2, 9, 500, 2); |
129
|
|
|
|
130
|
|
|
$this->assertCompareDataSet(array('tree_traversal_with_scope'), __DIR__.'/_files/adapter/with_scope/testMoveBranch.xml'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function testGetRoots() |
134
|
|
|
{ |
135
|
|
|
$roots = $this->manipulator |
136
|
|
|
->getRoots(); |
137
|
|
|
|
138
|
|
|
$expected = include __DIR__.'/_files/adapter/with_scope/testGetRoots.php'; |
139
|
|
|
$this->assertEquals($expected, $roots); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function testGetRoot() |
143
|
|
|
{ |
144
|
|
|
$roots = $this->manipulator |
145
|
|
|
->getRoot(2); |
146
|
|
|
|
147
|
|
|
$expected = include __DIR__.'/_files/adapter/with_scope/testGetRoot.php'; |
148
|
|
|
$this->assertEquals($expected, $roots); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function testGetNodeInfo() |
152
|
|
|
{ |
153
|
|
|
$nodeInfo = $this->manipulator |
154
|
|
|
->getNodeInfo(8); |
155
|
|
|
|
156
|
|
|
$this->assertEquals($nodeInfo->getId(), 8); |
157
|
|
|
$this->assertEquals($nodeInfo->getParentId(), 7); |
158
|
|
|
$this->assertEquals($nodeInfo->getLeft(), 3); |
159
|
|
|
$this->assertEquals($nodeInfo->getRight(), 8); |
160
|
|
|
$this->assertEquals($nodeInfo->getLevel(), 2); |
161
|
|
|
$this->assertEquals($nodeInfo->getScope(), 1); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
public function testGetChildrenNodeInfo() |
165
|
|
|
{ |
166
|
|
|
$nodeInfo = $this->manipulator |
167
|
|
|
->getChildrenNodeInfo(2); |
168
|
|
|
|
169
|
|
|
$this->assertCount(3, $nodeInfo); |
|
|
|
|
170
|
|
|
|
171
|
|
|
// check first node info |
172
|
|
|
$this->assertEquals($nodeInfo[0]->getId(), 3); |
173
|
|
|
$this->assertEquals($nodeInfo[0]->getParentId(), 2); |
174
|
|
|
$this->assertEquals($nodeInfo[0]->getLeft(), 3); |
175
|
|
|
$this->assertEquals($nodeInfo[0]->getRight(), 4); |
176
|
|
|
$this->assertEquals($nodeInfo[0]->getLevel(), 2); |
177
|
|
|
|
178
|
|
|
// check last node info |
179
|
|
|
$this->assertEquals($nodeInfo[2]->getId(), 5); |
180
|
|
|
$this->assertEquals($nodeInfo[2]->getParentId(), 2); |
181
|
|
|
$this->assertEquals($nodeInfo[2]->getLeft(), 7); |
182
|
|
|
$this->assertEquals($nodeInfo[2]->getRight(), 8); |
183
|
|
|
$this->assertEquals($nodeInfo[2]->getLevel(), 2); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
public function testUpdateNodeMetadata() |
187
|
|
|
{ |
188
|
|
|
$nodeInfo = new NodeInfo(3, 1000, 1001, 1002, 1003, 2); |
189
|
|
|
|
190
|
|
|
$this->manipulator |
191
|
|
|
->updateNodeMetadata($nodeInfo); |
192
|
|
|
|
193
|
|
|
$this->assertCompareDataSet(array('tree_traversal_with_scope'), __DIR__.'/_files/adapter/with_scope/testUpdateNodeMetadata.xml'); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function testGetPath() |
197
|
|
|
{ |
198
|
|
|
$path = $this->manipulator |
199
|
|
|
->getAncestors(5); |
200
|
|
|
|
201
|
|
|
$this->assertCount(3, $path); |
|
|
|
|
202
|
|
|
|
203
|
|
|
$expected = include __DIR__.'/_files/adapter/with_scope/testGetPath.php'; |
204
|
|
|
$this->assertEquals($expected, $path); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public function testGetDescendants() |
208
|
|
|
{ |
209
|
|
|
$nodes = $this->manipulator |
210
|
|
|
->getDescendants(1); |
211
|
|
|
|
212
|
|
|
$this->assertCount(5, $nodes); |
|
|
|
|
213
|
|
|
|
214
|
|
|
$expected = include __DIR__.'/_files/adapter/with_scope/testGetDescendants.php'; |
215
|
|
|
$this->assertEquals($expected, $nodes); |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: