1
|
|
|
<?php |
2
|
|
|
namespace StefanoTreeTest\Integration; |
3
|
|
|
|
4
|
|
|
use StefanoTree\NestedSet as TreeAdapter; |
5
|
|
|
use StefanoTreeTest\IntegrationTestCase; |
6
|
|
|
|
7
|
|
|
abstract class AbstractTest |
8
|
|
|
extends IntegrationTestCase |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var TreeAdapter |
12
|
|
|
*/ |
13
|
|
|
protected $treeAdapter; |
14
|
|
|
|
15
|
|
|
protected function setUp() |
16
|
|
|
{ |
17
|
|
|
$this->treeAdapter = $this->getTreeAdapter(); |
18
|
|
|
|
19
|
|
|
parent::setUp(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
protected function tearDown() |
23
|
|
|
{ |
24
|
|
|
$this->treeAdapter = null; |
25
|
|
|
parent::tearDown(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return TreeAdapter |
30
|
|
|
*/ |
31
|
|
|
abstract protected function getTreeAdapter(); |
32
|
|
|
|
33
|
|
|
protected function getDataSet() |
34
|
|
|
{ |
35
|
|
|
switch ($this->getName()) { |
36
|
|
|
case 'testCreateRootNode': |
37
|
|
|
case 'testCreateRootNodeWithCustomData': |
38
|
|
|
case 'testGetRootNodeRootDoesNotExist': |
39
|
|
|
return $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initEmptyDataSet.xml'); |
40
|
|
|
default: |
41
|
|
|
return $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSet.xml'); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testCreateRootNode() |
46
|
|
|
{ |
47
|
|
|
$newId = $this->treeAdapter |
48
|
|
|
->createRootNode(); |
49
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
50
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testCreateRootNode.xml'); |
51
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
52
|
|
|
$this->assertEquals(1, $newId); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testCreateRootNodeWithCustomData() |
56
|
|
|
{ |
57
|
|
|
$newId = $this->treeAdapter |
58
|
|
|
->createRootNode(array('name' => 'This is root node')); |
59
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
60
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testCreateRootNodeWithCustomData.xml'); |
61
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
62
|
|
|
$this->assertEquals(1, $newId); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testCreateRootRootAlreadyExist() |
66
|
|
|
{ |
67
|
|
|
$this->expectException( |
68
|
|
|
'\StefanoTree\Exception\RootNodeAlreadyExistException' |
69
|
|
|
); |
70
|
|
|
$this->expectExceptionMessage('Root node already exist'); |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
$this->treeAdapter |
74
|
|
|
->createRootNode(); |
75
|
|
|
$this->treeAdapter |
76
|
|
|
->createRootNode(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testGetNode() |
80
|
|
|
{ |
81
|
|
|
$expectedNodeData = array( |
82
|
|
|
'tree_traversal_id' => '12', |
83
|
|
|
'name' => null, |
84
|
|
|
'lft' => '18', |
85
|
|
|
'rgt' => '29', |
86
|
|
|
'parent_id' => '6', |
87
|
|
|
'level' => '3', |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
$nodeData = $this->treeAdapter |
91
|
|
|
->getNode(12); |
92
|
|
|
|
93
|
|
|
$this->assertEquals($expectedNodeData, $nodeData); |
94
|
|
|
$this->assertNull($this->treeAdapter->getNode(123456789)); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testAddNodeTargetNodeDoesNotExist() |
98
|
|
|
{ |
99
|
|
|
//test |
100
|
|
|
$return = $this->treeAdapter |
101
|
|
|
->addNodePlacementBottom(123456789); |
102
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
103
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
104
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
105
|
|
|
$this->assertFalse($return); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function testAddNodePlacementBottom() |
109
|
|
|
{ |
110
|
|
|
//test |
111
|
|
|
$return = $this->treeAdapter |
112
|
|
|
->addNodePlacementBottom(1); |
113
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
114
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
115
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
116
|
|
|
$this->assertFalse($return); |
117
|
|
|
|
118
|
|
|
//test 1 |
119
|
|
|
$lastGeneratedValue = $this->treeAdapter |
120
|
|
|
->addNodePlacementBottom(12); |
121
|
|
|
|
122
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
123
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testAddNodePlacementBottom-1.xml'); |
124
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
125
|
|
|
$this->assertEquals(26, $lastGeneratedValue); |
126
|
|
|
|
127
|
|
|
//test 2 with data |
128
|
|
|
$data = array( |
129
|
|
|
'name' => 'ahoj', |
130
|
|
|
); |
131
|
|
|
|
132
|
|
|
$lastGeneratedValue = $this->treeAdapter |
133
|
|
|
->addNodePlacementBottom(19, $data); |
134
|
|
|
|
135
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
136
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testAddNodePlacementBottom-2.xml'); |
137
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
138
|
|
|
$this->assertEquals(27, $lastGeneratedValue); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function testAddNodePlacementTop() |
142
|
|
|
{ |
143
|
|
|
//test |
144
|
|
|
$return = $this->treeAdapter |
145
|
|
|
->addNodePlacementTop(1); |
146
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
147
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
148
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
149
|
|
|
$this->assertFalse($return); |
150
|
|
|
|
151
|
|
|
//test 1 |
152
|
|
|
$lastGeneratedValue = $this->treeAdapter |
153
|
|
|
->addNodePlacementTop(16); |
154
|
|
|
|
155
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
156
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testAddNodePlacementTop-1.xml'); |
157
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
158
|
|
|
$this->assertEquals(26, $lastGeneratedValue); |
159
|
|
|
|
160
|
|
|
//test 2 with data |
161
|
|
|
$data = array( |
162
|
|
|
'name' => 'ahoj', |
163
|
|
|
); |
164
|
|
|
$lastGeneratedValue = $this->treeAdapter |
165
|
|
|
->addNodePlacementTop(3, $data); |
166
|
|
|
|
167
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
168
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testAddNodePlacementTop-2.xml'); |
169
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
170
|
|
|
$this->assertEquals(27, $lastGeneratedValue); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function testAddNodePlacementChildBottom() |
174
|
|
|
{ |
175
|
|
|
//test 1 |
176
|
|
|
$lastGeneratedValue = $this->treeAdapter |
177
|
|
|
->addNodePlacementChildBottom(21); |
178
|
|
|
|
179
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
180
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testAddNodePlacementChildBottom-1.xml'); |
181
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
182
|
|
|
$this->assertEquals(26, $lastGeneratedValue); |
183
|
|
|
|
184
|
|
|
//test 2 with data |
185
|
|
|
$data = array( |
186
|
|
|
'name' => 'ahoj', |
187
|
|
|
); |
188
|
|
|
$lastGeneratedValue = $this->treeAdapter |
189
|
|
|
->addNodePlacementChildBottom(4, $data); |
190
|
|
|
|
191
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
192
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testAddNodePlacementChildBottom-2.xml'); |
193
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
194
|
|
|
$this->assertEquals(27, $lastGeneratedValue); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
public function testAddNodePlacementChildTop() |
198
|
|
|
{ |
199
|
|
|
//test 1 |
200
|
|
|
$lastGeneratedValue = $this->treeAdapter |
201
|
|
|
->addNodePlacementChildTop(4); |
202
|
|
|
|
203
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
204
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testAddNodePlacementChildTop-1.xml'); |
205
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
206
|
|
|
$this->assertEquals(26, $lastGeneratedValue); |
207
|
|
|
|
208
|
|
|
//test 2 with data |
209
|
|
|
$data = array( |
210
|
|
|
'name' => 'ahoj', |
211
|
|
|
); |
212
|
|
|
$lastGeneratedValue = $this->treeAdapter |
213
|
|
|
->addNodePlacementChildTop(10, $data); |
214
|
|
|
|
215
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
216
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testAddNodePlacementChildTop-2.xml'); |
217
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
218
|
|
|
$this->assertEquals(27, $lastGeneratedValue); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
public function testDeleteBranch() |
222
|
|
|
{ |
223
|
|
|
//test 2 |
224
|
|
|
$return = $this->treeAdapter |
225
|
|
|
->deleteBranch(123456789); |
226
|
|
|
|
227
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
228
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
229
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Not Exist Branch'); |
230
|
|
|
$this->assertFalse($return); |
231
|
|
|
|
232
|
|
|
//test 3 |
233
|
|
|
$return = $this->treeAdapter |
234
|
|
|
->deleteBranch(6); |
235
|
|
|
|
236
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
237
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testDeleteBranch.xml'); |
238
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
239
|
|
|
$this->assertTrue($return); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
public function testMoveUnmovableNode() |
243
|
|
|
{ |
244
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
245
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
246
|
|
|
|
247
|
|
|
//test 1 |
248
|
|
|
$return = $this->treeAdapter |
249
|
|
|
->moveNodePlacementBottom(1, 12); |
250
|
|
|
|
251
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Target node is inside source node'); |
252
|
|
|
$this->assertFalse($return); |
253
|
|
|
|
254
|
|
|
//test |
255
|
|
|
$return = $this->treeAdapter |
256
|
|
|
->moveNodePlacementBottom(10, 10); |
257
|
|
|
|
258
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Target node and source node are same'); |
259
|
|
|
$this->assertFalse($return); |
260
|
|
|
|
261
|
|
|
//test |
262
|
|
|
$return = $this->treeAdapter |
263
|
|
|
->moveNodePlacementBottom(5, 123456); |
264
|
|
|
|
265
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Target node does not exist'); |
266
|
|
|
$this->assertFalse($return); |
267
|
|
|
|
268
|
|
|
//test |
269
|
|
|
$return = $this->treeAdapter |
270
|
|
|
->moveNodePlacementBottom(123456, 6); |
271
|
|
|
|
272
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Source node does not exist'); |
273
|
|
|
$this->assertFalse($return); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
public function testMoveNodePlacementBottom() |
277
|
|
|
{ |
278
|
|
|
//test |
279
|
|
|
$return = $this->treeAdapter |
280
|
|
|
->moveNodePlacementBottom(11, 1); |
281
|
|
|
|
282
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
283
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
284
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Root node cannot have sibling'); |
285
|
|
|
$this->assertFalse($return); |
286
|
|
|
|
287
|
|
|
//test |
288
|
|
|
$return = $this->treeAdapter |
289
|
|
|
->moveNodePlacementBottom(3, 2); |
290
|
|
|
|
291
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
292
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
293
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Source node is in required position'); |
294
|
|
|
$this->assertTrue($return); |
295
|
|
|
|
296
|
|
|
//test |
297
|
|
|
$return = $this->treeAdapter |
298
|
|
|
->moveNodePlacementBottom(14, 18); |
299
|
|
|
|
300
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
301
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementBottom-1.xml'); |
302
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
303
|
|
|
$this->assertTrue($return); |
304
|
|
|
|
305
|
|
|
//test |
306
|
|
|
$return = $this->treeAdapter |
307
|
|
|
->moveNodePlacementBottom(16, 7); |
308
|
|
|
|
309
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
310
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementBottom-2.xml'); |
311
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
312
|
|
|
$this->assertTrue($return); |
313
|
|
|
|
314
|
|
|
//test |
315
|
|
|
$return = $this->treeAdapter |
316
|
|
|
->moveNodePlacementBottom(14, 3); |
317
|
|
|
|
318
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
319
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementBottom-3.xml'); |
320
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
321
|
|
|
$this->assertTrue($return); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
public function testMoveNodePlacementTop() |
325
|
|
|
{ |
326
|
|
|
//test |
327
|
|
|
$return = $this->treeAdapter |
328
|
|
|
->moveNodePlacementTop(17, 1); |
329
|
|
|
|
330
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
331
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
332
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Root node cannot have sibling'); |
333
|
|
|
$this->assertFalse($return); |
334
|
|
|
|
335
|
|
|
//test |
336
|
|
|
$return = $this->treeAdapter |
337
|
|
|
->moveNodePlacementTop(3, 4); |
338
|
|
|
|
339
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
340
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
341
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Source node is in required position'); |
342
|
|
|
$this->assertTrue($return); |
343
|
|
|
|
344
|
|
|
//test |
345
|
|
|
$return = $this->treeAdapter |
346
|
|
|
->moveNodePlacementTop(19, 12); |
347
|
|
|
|
348
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
349
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementTop-1.xml'); |
350
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
351
|
|
|
$this->assertTrue($return); |
352
|
|
|
|
353
|
|
|
//test |
354
|
|
|
$return = $this->treeAdapter |
355
|
|
|
->moveNodePlacementTop(10, 18); |
356
|
|
|
|
357
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
358
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementTop-2.xml'); |
359
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
360
|
|
|
$this->assertTrue($return); |
361
|
|
|
|
362
|
|
|
//test |
363
|
|
|
$return = $this->treeAdapter |
364
|
|
|
->moveNodePlacementTop(21, 6); |
365
|
|
|
|
366
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
367
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementTop-3.xml'); |
368
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
369
|
|
|
$this->assertTrue($return); |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
public function testMoveNodePlacementChildBottom() |
373
|
|
|
{ |
374
|
|
|
//test |
375
|
|
|
$return = $this->treeAdapter |
376
|
|
|
->moveNodePlacementChildBottom(22, 18); |
377
|
|
|
|
378
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
379
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
380
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Source node is in required position'); |
381
|
|
|
$this->assertTrue($return); |
382
|
|
|
|
383
|
|
|
//test |
384
|
|
|
$return = $this->treeAdapter |
385
|
|
|
->moveNodePlacementChildBottom(9, 12); |
386
|
|
|
|
387
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
388
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementChildBottom-1.xml'); |
389
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
390
|
|
|
$this->assertTrue($return); |
391
|
|
|
|
392
|
|
|
//test |
393
|
|
|
$return = $this->treeAdapter |
394
|
|
|
->moveNodePlacementChildBottom(10, 3); |
395
|
|
|
|
396
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
397
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementChildBottom-2.xml'); |
398
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
399
|
|
|
$this->assertTrue($return); |
400
|
|
|
|
401
|
|
|
//test |
402
|
|
|
$return = $this->treeAdapter |
403
|
|
|
->moveNodePlacementChildBottom(21, 12); |
404
|
|
|
|
405
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
406
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementChildBottom-3.xml'); |
407
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
408
|
|
|
$this->assertTrue($return); |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
public function testMoveNodePlacementChildTop() |
412
|
|
|
{ |
413
|
|
|
//test |
414
|
|
|
$return = $this->treeAdapter |
415
|
|
|
->moveNodePlacementChildTop(21, 18); |
416
|
|
|
|
417
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
418
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
419
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Source node is in required position'); |
420
|
|
|
$this->assertTrue($return); |
421
|
|
|
|
422
|
|
|
//test |
423
|
|
|
$return = $this->treeAdapter |
424
|
|
|
->moveNodePlacementChildTop(9, 21); |
425
|
|
|
|
426
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
427
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementChildTop-1.xml'); |
428
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
429
|
|
|
$this->assertTrue($return); |
430
|
|
|
|
431
|
|
|
//test |
432
|
|
|
$return = $this->treeAdapter |
433
|
|
|
->moveNodePlacementChildTop(16, 3); |
434
|
|
|
|
435
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
436
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementChildTop-2.xml'); |
437
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
438
|
|
|
$this->assertTrue($return); |
439
|
|
|
|
440
|
|
|
//test |
441
|
|
|
$return = $this->treeAdapter |
442
|
|
|
->moveNodePlacementChildTop(18, 3); |
443
|
|
|
|
444
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
445
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementChildTop-3.xml'); |
446
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
447
|
|
|
$this->assertTrue($return); |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
public function testGetPathReturnEmptyArrayIfNodeDoesNotExist() { |
451
|
|
|
$return = $this->treeAdapter |
452
|
|
|
->getPath(123456789); |
453
|
|
|
$this->assertEquals(array(), $return); |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
public function testGetPathReturnEmptyArrayIfNodeExistButHasNoPath() { |
457
|
|
|
$return = $this->treeAdapter |
458
|
|
|
->getPath(1, 0, True); |
459
|
|
|
$this->assertEquals(array(), $return); |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
public function testGetPath() |
463
|
|
|
{ |
464
|
|
|
//test |
465
|
|
|
$return = $this->treeAdapter |
466
|
|
|
->getPath(6); |
467
|
|
|
$expected = array( |
468
|
|
|
array( |
469
|
|
|
'tree_traversal_id' => '1', |
470
|
|
|
'name' => null, |
471
|
|
|
'lft' => '1', |
472
|
|
|
'rgt' => '50', |
473
|
|
|
'parent_id' => '0', |
474
|
|
|
'level' => '0', |
475
|
|
|
), |
476
|
|
|
array( |
477
|
|
|
'tree_traversal_id' => '3', |
478
|
|
|
'name' => null, |
479
|
|
|
'lft' => '16', |
480
|
|
|
'rgt' => '35', |
481
|
|
|
'parent_id' => '1', |
482
|
|
|
'level' => '1', |
483
|
|
|
), |
484
|
|
|
array( |
485
|
|
|
'tree_traversal_id' => '6', |
486
|
|
|
'name' => null, |
487
|
|
|
'lft' => '17', |
488
|
|
|
'rgt' => '32', |
489
|
|
|
'parent_id' => '3', |
490
|
|
|
'level' => '2', |
491
|
|
|
), |
492
|
|
|
); |
493
|
|
|
$this->assertEquals($expected, $return); |
494
|
|
|
|
495
|
|
|
//test |
496
|
|
|
$return = $this->treeAdapter |
497
|
|
|
->getPath(6, 1); |
498
|
|
|
$expected = array( |
499
|
|
|
array( |
500
|
|
|
'tree_traversal_id' => '3', |
501
|
|
|
'name' => null, |
502
|
|
|
'lft' => '16', |
503
|
|
|
'rgt' => '35', |
504
|
|
|
'parent_id' => '1', |
505
|
|
|
'level' => '1', |
506
|
|
|
), |
507
|
|
|
array( |
508
|
|
|
'tree_traversal_id' => '6', |
509
|
|
|
'name' => null, |
510
|
|
|
'lft' => '17', |
511
|
|
|
'rgt' => '32', |
512
|
|
|
'parent_id' => '3', |
513
|
|
|
'level' => '2', |
514
|
|
|
), |
515
|
|
|
); |
516
|
|
|
$this->assertEquals($expected, $return); |
517
|
|
|
|
518
|
|
|
//test |
519
|
|
|
$return = $this->treeAdapter |
520
|
|
|
->getPath(6, 0, true); |
521
|
|
|
$expected = array( |
522
|
|
|
array( |
523
|
|
|
'tree_traversal_id' => '1', |
524
|
|
|
'name' => null, |
525
|
|
|
'lft' => '1', |
526
|
|
|
'rgt' => '50', |
527
|
|
|
'parent_id' => '0', |
528
|
|
|
'level' => '0', |
529
|
|
|
), |
530
|
|
|
array( |
531
|
|
|
'tree_traversal_id' => '3', |
532
|
|
|
'name' => null, |
533
|
|
|
'lft' => '16', |
534
|
|
|
'rgt' => '35', |
535
|
|
|
'parent_id' => '1', |
536
|
|
|
'level' => '1', |
537
|
|
|
), |
538
|
|
|
); |
539
|
|
|
$this->assertEquals($expected, $return); |
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
public function testGetDescendantsReturnEmptyArrayIfNodeDoesNotExist() { |
543
|
|
|
$return = $this->treeAdapter |
544
|
|
|
->getDescendants(123456789); |
545
|
|
|
$this->assertEquals(array(), $return); |
546
|
|
|
} |
547
|
|
|
|
548
|
|
|
public function testGetDescendantsReturnEmptyArrayNodeDoesNotHaveDescendants() { |
549
|
|
|
$return = $this->treeAdapter |
550
|
|
|
->getDescendants(8, 1); |
551
|
|
|
$this->assertEquals(array(), $return); |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
public function testGetDescendants() |
555
|
|
|
{ |
556
|
|
|
//test whole branche |
557
|
|
|
$return = $this->treeAdapter |
558
|
|
|
->getDescendants(21); |
559
|
|
|
$expected = array( |
560
|
|
|
array( |
561
|
|
|
'tree_traversal_id' => '21', |
562
|
|
|
'name' => null, |
563
|
|
|
'lft' => '20', |
564
|
|
|
'rgt' => '25', |
565
|
|
|
'parent_id' => '18', |
566
|
|
|
'level' => '5', |
567
|
|
|
), |
568
|
|
|
array( |
569
|
|
|
'tree_traversal_id' => '24', |
570
|
|
|
'name' => null, |
571
|
|
|
'lft' => '21', |
572
|
|
|
'rgt' => '22', |
573
|
|
|
'parent_id' => '21', |
574
|
|
|
'level' => '6', |
575
|
|
|
), |
576
|
|
|
array( |
577
|
|
|
'tree_traversal_id' => '25', |
578
|
|
|
'name' => null, |
579
|
|
|
'lft' => '23', |
580
|
|
|
'rgt' => '24', |
581
|
|
|
'parent_id' => '21', |
582
|
|
|
'level' => '6', |
583
|
|
|
), |
584
|
|
|
); |
585
|
|
|
$this->assertEquals($expected, $return); |
586
|
|
|
|
587
|
|
|
//test different start node |
588
|
|
|
$return = $this->treeAdapter |
589
|
|
|
->getDescendants(6, 3); |
590
|
|
|
$expected = array( |
591
|
|
|
array( |
592
|
|
|
'tree_traversal_id' => '21', |
593
|
|
|
'name' => null, |
594
|
|
|
'lft' => '20', |
595
|
|
|
'rgt' => '25', |
596
|
|
|
'parent_id' => '18', |
597
|
|
|
'level' => '5', |
598
|
|
|
), |
599
|
|
|
array( |
600
|
|
|
'tree_traversal_id' => '24', |
601
|
|
|
'name' => null, |
602
|
|
|
'lft' => '21', |
603
|
|
|
'rgt' => '22', |
604
|
|
|
'parent_id' => '21', |
605
|
|
|
'level' => '6', |
606
|
|
|
), |
607
|
|
|
array( |
608
|
|
|
'tree_traversal_id' => '25', |
609
|
|
|
'name' => null, |
610
|
|
|
'lft' => '23', |
611
|
|
|
'rgt' => '24', |
612
|
|
|
'parent_id' => '21', |
613
|
|
|
'level' => '6', |
614
|
|
|
), |
615
|
|
|
array( |
616
|
|
|
'tree_traversal_id' => '22', |
617
|
|
|
'name' => null, |
618
|
|
|
'lft' => '26', |
619
|
|
|
'rgt' => '27', |
620
|
|
|
'parent_id' => '18', |
621
|
|
|
'level' => '5', |
622
|
|
|
), |
623
|
|
|
); |
624
|
|
|
$this->assertEquals($expected, $return); |
625
|
|
|
|
626
|
|
|
//test custom levels |
627
|
|
|
$return = $this->treeAdapter |
628
|
|
|
->getDescendants(18, 0, 2); |
629
|
|
|
$expected = array( |
630
|
|
|
array( |
631
|
|
|
'tree_traversal_id' => '18', |
632
|
|
|
'name' => null, |
633
|
|
|
'lft' => '19', |
634
|
|
|
'rgt' => '28', |
635
|
|
|
'parent_id' => '12', |
636
|
|
|
'level' => '4', |
637
|
|
|
), |
638
|
|
|
array( |
639
|
|
|
'tree_traversal_id' => '21', |
640
|
|
|
'name' => null, |
641
|
|
|
'lft' => '20', |
642
|
|
|
'rgt' => '25', |
643
|
|
|
'parent_id' => '18', |
644
|
|
|
'level' => '5', |
645
|
|
|
), |
646
|
|
|
array( |
647
|
|
|
'tree_traversal_id' => '22', |
648
|
|
|
'name' => null, |
649
|
|
|
'lft' => '26', |
650
|
|
|
'rgt' => '27', |
651
|
|
|
'parent_id' => '18', |
652
|
|
|
'level' => '5', |
653
|
|
|
), |
654
|
|
|
); |
655
|
|
|
$this->assertEquals($expected, $return); |
656
|
|
|
|
657
|
|
|
//test exclude node |
658
|
|
|
$return = $this->treeAdapter |
659
|
|
|
->getDescendants(12, 0, null, 21); |
660
|
|
|
$expected = array( |
661
|
|
|
array( |
662
|
|
|
'tree_traversal_id' => '12', |
663
|
|
|
'name' => null, |
664
|
|
|
'lft' => '18', |
665
|
|
|
'rgt' => '29', |
666
|
|
|
'parent_id' => '6', |
667
|
|
|
'level' => '3', |
668
|
|
|
), |
669
|
|
|
array( |
670
|
|
|
'tree_traversal_id' => '18', |
671
|
|
|
'name' => null, |
672
|
|
|
'lft' => '19', |
673
|
|
|
'rgt' => '28', |
674
|
|
|
'parent_id' => '12', |
675
|
|
|
'level' => '4', |
676
|
|
|
), |
677
|
|
|
array( |
678
|
|
|
'tree_traversal_id' => '22', |
679
|
|
|
'name' => null, |
680
|
|
|
'lft' => '26', |
681
|
|
|
'rgt' => '27', |
682
|
|
|
'parent_id' => '18', |
683
|
|
|
'level' => '5', |
684
|
|
|
), |
685
|
|
|
); |
686
|
|
|
$this->assertEquals($expected, $return); |
687
|
|
|
} |
688
|
|
|
|
689
|
|
|
public function testGetChildrenReturnEmptyArrayIfNodeDoesNotExist() { |
690
|
|
|
$return = $this->treeAdapter |
691
|
|
|
->getChildren(123456789); |
692
|
|
|
$this->assertEquals(array(), $return); |
693
|
|
|
} |
694
|
|
|
|
695
|
|
|
public function testGetChildrenReturnEmptyArrayIfNodeDoesNotHaveChildren() { |
696
|
|
|
$return = $this->treeAdapter |
697
|
|
|
->getChildren(8); |
698
|
|
|
$this->assertEquals(array(), $return); |
699
|
|
|
} |
700
|
|
|
|
701
|
|
|
public function testGetChildren() |
702
|
|
|
{ |
703
|
|
|
//test exclude node |
704
|
|
|
$return = $this->treeAdapter |
705
|
|
|
->getChildren(18); |
706
|
|
|
$expected = array( |
707
|
|
|
array( |
708
|
|
|
'tree_traversal_id' => '21', |
709
|
|
|
'name' => null, |
710
|
|
|
'lft' => '20', |
711
|
|
|
'rgt' => '25', |
712
|
|
|
'parent_id' => '18', |
713
|
|
|
'level' => '5', |
714
|
|
|
), |
715
|
|
|
array( |
716
|
|
|
'tree_traversal_id' => '22', |
717
|
|
|
'name' => null, |
718
|
|
|
'lft' => '26', |
719
|
|
|
'rgt' => '27', |
720
|
|
|
'parent_id' => '18', |
721
|
|
|
'level' => '5', |
722
|
|
|
), |
723
|
|
|
); |
724
|
|
|
$this->assertEquals($expected, $return); |
725
|
|
|
} |
726
|
|
|
|
727
|
|
|
public function testUpdateNode() |
728
|
|
|
{ |
729
|
|
|
//test |
730
|
|
|
$data = array( |
731
|
|
|
'name' => 'ahoj', |
732
|
|
|
); |
733
|
|
|
$this->treeAdapter |
734
|
|
|
->updateNode(3, $data); |
735
|
|
|
|
736
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
737
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testUpdateNode-1.xml'); |
738
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
739
|
|
|
|
740
|
|
|
//test |
741
|
|
|
$data = array( |
742
|
|
|
'name' => 'ahoj', |
743
|
|
|
'lft' => '123456', |
744
|
|
|
'rgt' => '123456', |
745
|
|
|
'tree_traversal_id' => '123456', |
746
|
|
|
'level' => '123456', |
747
|
|
|
'parent_id' => '123456', |
748
|
|
|
); |
749
|
|
|
$this->treeAdapter |
750
|
|
|
->updateNode(3, $data); |
751
|
|
|
|
752
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
753
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testUpdateNode-1.xml'); |
754
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
755
|
|
|
} |
756
|
|
|
|
757
|
|
|
public function testGetRootNodeRootDoesNotExist() |
758
|
|
|
{ |
759
|
|
|
$return = $this->treeAdapter |
760
|
|
|
->getRootNode(); |
761
|
|
|
|
762
|
|
|
$this->assertEquals(array(), $return); |
763
|
|
|
} |
764
|
|
|
|
765
|
|
|
public function testGetRootNode() |
766
|
|
|
{ |
767
|
|
|
$return = $this->treeAdapter |
768
|
|
|
->getRootNode(); |
769
|
|
|
|
770
|
|
|
$expected = array( |
771
|
|
|
'tree_traversal_id' => '1', |
772
|
|
|
'name' => '', |
773
|
|
|
'lft' => '1', |
774
|
|
|
'rgt' => '50', |
775
|
|
|
'parent_id' => '0', |
776
|
|
|
'level' => '0', |
777
|
|
|
); |
778
|
|
|
$this->assertEquals($expected, $return); |
779
|
|
|
} |
780
|
|
|
} |
781
|
|
|
|