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 testGetPath() |
451
|
|
|
{ |
452
|
|
|
//test |
453
|
|
|
$return = $this->treeAdapter |
454
|
|
|
->getPath(123456789); |
455
|
|
|
$this->assertNull($return); |
456
|
|
|
|
457
|
|
|
//test |
458
|
|
|
$return = $this->treeAdapter |
459
|
|
|
->getPath(6); |
460
|
|
|
$expected = array( |
461
|
|
|
array( |
462
|
|
|
'tree_traversal_id' => '1', |
463
|
|
|
'name' => null, |
464
|
|
|
'lft' => '1', |
465
|
|
|
'rgt' => '50', |
466
|
|
|
'parent_id' => '0', |
467
|
|
|
'level' => '0', |
468
|
|
|
), |
469
|
|
|
array( |
470
|
|
|
'tree_traversal_id' => '3', |
471
|
|
|
'name' => null, |
472
|
|
|
'lft' => '16', |
473
|
|
|
'rgt' => '35', |
474
|
|
|
'parent_id' => '1', |
475
|
|
|
'level' => '1', |
476
|
|
|
), |
477
|
|
|
array( |
478
|
|
|
'tree_traversal_id' => '6', |
479
|
|
|
'name' => null, |
480
|
|
|
'lft' => '17', |
481
|
|
|
'rgt' => '32', |
482
|
|
|
'parent_id' => '3', |
483
|
|
|
'level' => '2', |
484
|
|
|
), |
485
|
|
|
); |
486
|
|
|
$this->assertEquals($expected, $return); |
487
|
|
|
|
488
|
|
|
//test |
489
|
|
|
$return = $this->treeAdapter |
490
|
|
|
->getPath(6, 1); |
491
|
|
|
$expected = array( |
492
|
|
|
array( |
493
|
|
|
'tree_traversal_id' => '3', |
494
|
|
|
'name' => null, |
495
|
|
|
'lft' => '16', |
496
|
|
|
'rgt' => '35', |
497
|
|
|
'parent_id' => '1', |
498
|
|
|
'level' => '1', |
499
|
|
|
), |
500
|
|
|
array( |
501
|
|
|
'tree_traversal_id' => '6', |
502
|
|
|
'name' => null, |
503
|
|
|
'lft' => '17', |
504
|
|
|
'rgt' => '32', |
505
|
|
|
'parent_id' => '3', |
506
|
|
|
'level' => '2', |
507
|
|
|
), |
508
|
|
|
); |
509
|
|
|
$this->assertEquals($expected, $return); |
510
|
|
|
|
511
|
|
|
//test |
512
|
|
|
$return = $this->treeAdapter |
513
|
|
|
->getPath(6, 0, true); |
514
|
|
|
$expected = array( |
515
|
|
|
array( |
516
|
|
|
'tree_traversal_id' => '1', |
517
|
|
|
'name' => null, |
518
|
|
|
'lft' => '1', |
519
|
|
|
'rgt' => '50', |
520
|
|
|
'parent_id' => '0', |
521
|
|
|
'level' => '0', |
522
|
|
|
), |
523
|
|
|
array( |
524
|
|
|
'tree_traversal_id' => '3', |
525
|
|
|
'name' => null, |
526
|
|
|
'lft' => '16', |
527
|
|
|
'rgt' => '35', |
528
|
|
|
'parent_id' => '1', |
529
|
|
|
'level' => '1', |
530
|
|
|
), |
531
|
|
|
); |
532
|
|
|
$this->assertEquals($expected, $return); |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
public function testGetDescendants() |
536
|
|
|
{ |
537
|
|
|
//test |
538
|
|
|
$return = $this->treeAdapter |
539
|
|
|
->getDescendants(123456789); |
540
|
|
|
$this->assertNull($return); |
541
|
|
|
|
542
|
|
|
//test |
543
|
|
|
$return = $this->treeAdapter |
544
|
|
|
->getDescendants(1, 100000); |
545
|
|
|
$this->assertNull($return); |
546
|
|
|
|
547
|
|
|
//test whole branche |
548
|
|
|
$return = $this->treeAdapter |
549
|
|
|
->getDescendants(21); |
550
|
|
|
$expected = array( |
551
|
|
|
array( |
552
|
|
|
'tree_traversal_id' => '21', |
553
|
|
|
'name' => null, |
554
|
|
|
'lft' => '20', |
555
|
|
|
'rgt' => '25', |
556
|
|
|
'parent_id' => '18', |
557
|
|
|
'level' => '5', |
558
|
|
|
), |
559
|
|
|
array( |
560
|
|
|
'tree_traversal_id' => '24', |
561
|
|
|
'name' => null, |
562
|
|
|
'lft' => '21', |
563
|
|
|
'rgt' => '22', |
564
|
|
|
'parent_id' => '21', |
565
|
|
|
'level' => '6', |
566
|
|
|
), |
567
|
|
|
array( |
568
|
|
|
'tree_traversal_id' => '25', |
569
|
|
|
'name' => null, |
570
|
|
|
'lft' => '23', |
571
|
|
|
'rgt' => '24', |
572
|
|
|
'parent_id' => '21', |
573
|
|
|
'level' => '6', |
574
|
|
|
), |
575
|
|
|
); |
576
|
|
|
$this->assertEquals($expected, $return); |
577
|
|
|
|
578
|
|
|
//test different start node |
579
|
|
|
$return = $this->treeAdapter |
580
|
|
|
->getDescendants(6, 3); |
581
|
|
|
$expected = array( |
582
|
|
|
array( |
583
|
|
|
'tree_traversal_id' => '21', |
584
|
|
|
'name' => null, |
585
|
|
|
'lft' => '20', |
586
|
|
|
'rgt' => '25', |
587
|
|
|
'parent_id' => '18', |
588
|
|
|
'level' => '5', |
589
|
|
|
), |
590
|
|
|
array( |
591
|
|
|
'tree_traversal_id' => '24', |
592
|
|
|
'name' => null, |
593
|
|
|
'lft' => '21', |
594
|
|
|
'rgt' => '22', |
595
|
|
|
'parent_id' => '21', |
596
|
|
|
'level' => '6', |
597
|
|
|
), |
598
|
|
|
array( |
599
|
|
|
'tree_traversal_id' => '25', |
600
|
|
|
'name' => null, |
601
|
|
|
'lft' => '23', |
602
|
|
|
'rgt' => '24', |
603
|
|
|
'parent_id' => '21', |
604
|
|
|
'level' => '6', |
605
|
|
|
), |
606
|
|
|
array( |
607
|
|
|
'tree_traversal_id' => '22', |
608
|
|
|
'name' => null, |
609
|
|
|
'lft' => '26', |
610
|
|
|
'rgt' => '27', |
611
|
|
|
'parent_id' => '18', |
612
|
|
|
'level' => '5', |
613
|
|
|
), |
614
|
|
|
); |
615
|
|
|
$this->assertEquals($expected, $return); |
616
|
|
|
|
617
|
|
|
//test custom levels |
618
|
|
|
$return = $this->treeAdapter |
619
|
|
|
->getDescendants(18, 0, 2); |
620
|
|
|
$expected = array( |
621
|
|
|
array( |
622
|
|
|
'tree_traversal_id' => '18', |
623
|
|
|
'name' => null, |
624
|
|
|
'lft' => '19', |
625
|
|
|
'rgt' => '28', |
626
|
|
|
'parent_id' => '12', |
627
|
|
|
'level' => '4', |
628
|
|
|
), |
629
|
|
|
array( |
630
|
|
|
'tree_traversal_id' => '21', |
631
|
|
|
'name' => null, |
632
|
|
|
'lft' => '20', |
633
|
|
|
'rgt' => '25', |
634
|
|
|
'parent_id' => '18', |
635
|
|
|
'level' => '5', |
636
|
|
|
), |
637
|
|
|
array( |
638
|
|
|
'tree_traversal_id' => '22', |
639
|
|
|
'name' => null, |
640
|
|
|
'lft' => '26', |
641
|
|
|
'rgt' => '27', |
642
|
|
|
'parent_id' => '18', |
643
|
|
|
'level' => '5', |
644
|
|
|
), |
645
|
|
|
); |
646
|
|
|
$this->assertEquals($expected, $return); |
647
|
|
|
|
648
|
|
|
//test exclude node |
649
|
|
|
$return = $this->treeAdapter |
650
|
|
|
->getDescendants(12, 0, null, 21); |
651
|
|
|
$expected = array( |
652
|
|
|
array( |
653
|
|
|
'tree_traversal_id' => '12', |
654
|
|
|
'name' => null, |
655
|
|
|
'lft' => '18', |
656
|
|
|
'rgt' => '29', |
657
|
|
|
'parent_id' => '6', |
658
|
|
|
'level' => '3', |
659
|
|
|
), |
660
|
|
|
array( |
661
|
|
|
'tree_traversal_id' => '18', |
662
|
|
|
'name' => null, |
663
|
|
|
'lft' => '19', |
664
|
|
|
'rgt' => '28', |
665
|
|
|
'parent_id' => '12', |
666
|
|
|
'level' => '4', |
667
|
|
|
), |
668
|
|
|
array( |
669
|
|
|
'tree_traversal_id' => '22', |
670
|
|
|
'name' => null, |
671
|
|
|
'lft' => '26', |
672
|
|
|
'rgt' => '27', |
673
|
|
|
'parent_id' => '18', |
674
|
|
|
'level' => '5', |
675
|
|
|
), |
676
|
|
|
); |
677
|
|
|
$this->assertEquals($expected, $return); |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
public function testGetChildren() |
681
|
|
|
{ |
682
|
|
|
//test |
683
|
|
|
$return = $this->treeAdapter |
684
|
|
|
->getChildren(123456789); |
685
|
|
|
$this->assertNull($return); |
686
|
|
|
|
687
|
|
|
//test exclude node |
688
|
|
|
$return = $this->treeAdapter |
689
|
|
|
->getChildren(18); |
690
|
|
|
$expected = array( |
691
|
|
|
array( |
692
|
|
|
'tree_traversal_id' => '21', |
693
|
|
|
'name' => null, |
694
|
|
|
'lft' => '20', |
695
|
|
|
'rgt' => '25', |
696
|
|
|
'parent_id' => '18', |
697
|
|
|
'level' => '5', |
698
|
|
|
), |
699
|
|
|
array( |
700
|
|
|
'tree_traversal_id' => '22', |
701
|
|
|
'name' => null, |
702
|
|
|
'lft' => '26', |
703
|
|
|
'rgt' => '27', |
704
|
|
|
'parent_id' => '18', |
705
|
|
|
'level' => '5', |
706
|
|
|
), |
707
|
|
|
); |
708
|
|
|
$this->assertEquals($expected, $return); |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
public function testUpdateNode() |
712
|
|
|
{ |
713
|
|
|
//test |
714
|
|
|
$data = array( |
715
|
|
|
'name' => 'ahoj', |
716
|
|
|
); |
717
|
|
|
$this->treeAdapter |
718
|
|
|
->updateNode(3, $data); |
719
|
|
|
|
720
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
721
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testUpdateNode-1.xml'); |
722
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
723
|
|
|
|
724
|
|
|
//test |
725
|
|
|
$data = array( |
726
|
|
|
'name' => 'ahoj', |
727
|
|
|
'lft' => '123456', |
728
|
|
|
'rgt' => '123456', |
729
|
|
|
'tree_traversal_id' => '123456', |
730
|
|
|
'level' => '123456', |
731
|
|
|
'parent_id' => '123456', |
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
|
|
|
|
741
|
|
|
public function testGetRootNodeRootDoesNotExist() |
742
|
|
|
{ |
743
|
|
|
$return = $this->treeAdapter |
744
|
|
|
->getRootNode(); |
745
|
|
|
|
746
|
|
|
$this->assertEquals(array(), $return); |
747
|
|
|
} |
748
|
|
|
|
749
|
|
|
public function testGetRootNode() |
750
|
|
|
{ |
751
|
|
|
$return = $this->treeAdapter |
752
|
|
|
->getRootNode(); |
753
|
|
|
|
754
|
|
|
$expected = array( |
755
|
|
|
'tree_traversal_id' => '1', |
756
|
|
|
'name' => '', |
757
|
|
|
'lft' => '1', |
758
|
|
|
'rgt' => '50', |
759
|
|
|
'parent_id' => '0', |
760
|
|
|
'level' => '0', |
761
|
|
|
); |
762
|
|
|
$this->assertEquals($expected, $return); |
763
|
|
|
} |
764
|
|
|
} |
765
|
|
|
|