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
|
|
|
return $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSet.xml'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testClear() |
39
|
|
|
{ |
40
|
|
|
$this->treeAdapter |
41
|
|
|
->clear(); |
42
|
|
|
|
43
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
44
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testClear-1.xml'); |
45
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testGetNode() |
49
|
|
|
{ |
50
|
|
|
$expectedNodeData = array( |
51
|
|
|
'tree_traversal_id' => '12', |
52
|
|
|
'name' => null, |
53
|
|
|
'lft' => '18', |
54
|
|
|
'rgt' => '29', |
55
|
|
|
'parent_id' => '6', |
56
|
|
|
'level' => '3', |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$nodeData = $this->treeAdapter |
60
|
|
|
->getNode(12); |
61
|
|
|
|
62
|
|
|
$this->assertEquals($expectedNodeData, $nodeData); |
63
|
|
|
$this->assertNull($this->treeAdapter->getNode(123456789)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testAddNodeTargetNodeDoesNotExist() |
67
|
|
|
{ |
68
|
|
|
//test |
69
|
|
|
$return = $this->treeAdapter |
70
|
|
|
->addNodePlacementBottom(123456789); |
71
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
72
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
73
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
74
|
|
|
$this->assertFalse($return); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testAddNodePlacementBottom() |
78
|
|
|
{ |
79
|
|
|
//test |
80
|
|
|
$return = $this->treeAdapter |
81
|
|
|
->addNodePlacementBottom(1); |
82
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
83
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
84
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
85
|
|
|
$this->assertFalse($return); |
86
|
|
|
|
87
|
|
|
//test 1 |
88
|
|
|
$lastGeneratedValue = $this->treeAdapter |
89
|
|
|
->addNodePlacementBottom(12); |
90
|
|
|
|
91
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
92
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testAddNodePlacementBottom-1.xml'); |
93
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
94
|
|
|
$this->assertEquals(26, $lastGeneratedValue); |
95
|
|
|
|
96
|
|
|
//test 2 with data |
97
|
|
|
$data = array( |
98
|
|
|
'name' => 'ahoj', |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
$lastGeneratedValue = $this->treeAdapter |
102
|
|
|
->addNodePlacementBottom(19, $data); |
103
|
|
|
|
104
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
105
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testAddNodePlacementBottom-2.xml'); |
106
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
107
|
|
|
$this->assertEquals(27, $lastGeneratedValue); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function testAddNodePlacementTop() |
111
|
|
|
{ |
112
|
|
|
//test |
113
|
|
|
$return = $this->treeAdapter |
114
|
|
|
->addNodePlacementTop(1); |
115
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
116
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
117
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
118
|
|
|
$this->assertFalse($return); |
119
|
|
|
|
120
|
|
|
//test 1 |
121
|
|
|
$lastGeneratedValue = $this->treeAdapter |
122
|
|
|
->addNodePlacementTop(16); |
123
|
|
|
|
124
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
125
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testAddNodePlacementTop-1.xml'); |
126
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
127
|
|
|
$this->assertEquals(26, $lastGeneratedValue); |
128
|
|
|
|
129
|
|
|
//test 2 with data |
130
|
|
|
$data = array( |
131
|
|
|
'name' => 'ahoj', |
132
|
|
|
); |
133
|
|
|
$lastGeneratedValue = $this->treeAdapter |
134
|
|
|
->addNodePlacementTop(3, $data); |
135
|
|
|
|
136
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
137
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testAddNodePlacementTop-2.xml'); |
138
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
139
|
|
|
$this->assertEquals(27, $lastGeneratedValue); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function testAddNodePlacementChildBottom() |
143
|
|
|
{ |
144
|
|
|
//test 1 |
145
|
|
|
$lastGeneratedValue = $this->treeAdapter |
146
|
|
|
->addNodePlacementChildBottom(21); |
147
|
|
|
|
148
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
149
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testAddNodePlacementChildBottom-1.xml'); |
150
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
151
|
|
|
$this->assertEquals(26, $lastGeneratedValue); |
152
|
|
|
|
153
|
|
|
//test 2 with data |
154
|
|
|
$data = array( |
155
|
|
|
'name' => 'ahoj', |
156
|
|
|
); |
157
|
|
|
$lastGeneratedValue = $this->treeAdapter |
158
|
|
|
->addNodePlacementChildBottom(4, $data); |
159
|
|
|
|
160
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
161
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testAddNodePlacementChildBottom-2.xml'); |
162
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
163
|
|
|
$this->assertEquals(27, $lastGeneratedValue); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function testAddNodePlacementChildTop() |
167
|
|
|
{ |
168
|
|
|
//test 1 |
169
|
|
|
$lastGeneratedValue = $this->treeAdapter |
170
|
|
|
->addNodePlacementChildTop(4); |
171
|
|
|
|
172
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
173
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testAddNodePlacementChildTop-1.xml'); |
174
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
175
|
|
|
$this->assertEquals(26, $lastGeneratedValue); |
176
|
|
|
|
177
|
|
|
//test 2 with data |
178
|
|
|
$data = array( |
179
|
|
|
'name' => 'ahoj', |
180
|
|
|
); |
181
|
|
|
$lastGeneratedValue = $this->treeAdapter |
182
|
|
|
->addNodePlacementChildTop(10, $data); |
183
|
|
|
|
184
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
185
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testAddNodePlacementChildTop-2.xml'); |
186
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
187
|
|
|
$this->assertEquals(27, $lastGeneratedValue); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
public function testDeleteBranch() |
191
|
|
|
{ |
192
|
|
|
//test 1 |
193
|
|
|
$return = $this->treeAdapter |
194
|
|
|
->deleteBranch(1); |
195
|
|
|
|
196
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
197
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
198
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Cannot delete root node'); |
199
|
|
|
$this->assertFalse($return); |
200
|
|
|
|
201
|
|
|
//test 2 |
202
|
|
|
$return = $this->treeAdapter |
203
|
|
|
->deleteBranch(123456789); |
204
|
|
|
|
205
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
206
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
207
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Not Exist Branch'); |
208
|
|
|
$this->assertFalse($return); |
209
|
|
|
|
210
|
|
|
//test 3 |
211
|
|
|
$return = $this->treeAdapter |
212
|
|
|
->deleteBranch(6); |
213
|
|
|
|
214
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
215
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testDeleteBranch.xml'); |
216
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
217
|
|
|
$this->assertTrue($return); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public function testMoveUnmovableNode() |
221
|
|
|
{ |
222
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
223
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
224
|
|
|
|
225
|
|
|
//test 1 |
226
|
|
|
$return = $this->treeAdapter |
227
|
|
|
->moveNodePlacementBottom(1, 12); |
228
|
|
|
|
229
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Target node is inside source node'); |
230
|
|
|
$this->assertFalse($return); |
231
|
|
|
|
232
|
|
|
//test |
233
|
|
|
$return = $this->treeAdapter |
234
|
|
|
->moveNodePlacementBottom(10, 10); |
235
|
|
|
|
236
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Target node and source node are same'); |
237
|
|
|
$this->assertFalse($return); |
238
|
|
|
|
239
|
|
|
//test |
240
|
|
|
$return = $this->treeAdapter |
241
|
|
|
->moveNodePlacementBottom(5, 123456); |
242
|
|
|
|
243
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Target node does not exist'); |
244
|
|
|
$this->assertFalse($return); |
245
|
|
|
|
246
|
|
|
//test |
247
|
|
|
$return = $this->treeAdapter |
248
|
|
|
->moveNodePlacementBottom(123456, 6); |
249
|
|
|
|
250
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Source node does not exist'); |
251
|
|
|
$this->assertFalse($return); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
public function testMoveNodePlacementBottom() |
255
|
|
|
{ |
256
|
|
|
//test |
257
|
|
|
$return = $this->treeAdapter |
258
|
|
|
->moveNodePlacementBottom(11, 1); |
259
|
|
|
|
260
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
261
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
262
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Root node cannot have sibling'); |
263
|
|
|
$this->assertFalse($return); |
264
|
|
|
|
265
|
|
|
//test |
266
|
|
|
$return = $this->treeAdapter |
267
|
|
|
->moveNodePlacementBottom(3, 2); |
268
|
|
|
|
269
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
270
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
271
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Source node is in required position'); |
272
|
|
|
$this->assertTrue($return); |
273
|
|
|
|
274
|
|
|
//test |
275
|
|
|
$return = $this->treeAdapter |
276
|
|
|
->moveNodePlacementBottom(14, 18); |
277
|
|
|
|
278
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
279
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementBottom-1.xml'); |
280
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
281
|
|
|
$this->assertTrue($return); |
282
|
|
|
|
283
|
|
|
//test |
284
|
|
|
$return = $this->treeAdapter |
285
|
|
|
->moveNodePlacementBottom(16, 7); |
286
|
|
|
|
287
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
288
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementBottom-2.xml'); |
289
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
290
|
|
|
$this->assertTrue($return); |
291
|
|
|
|
292
|
|
|
//test |
293
|
|
|
$return = $this->treeAdapter |
294
|
|
|
->moveNodePlacementBottom(14, 3); |
295
|
|
|
|
296
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
297
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementBottom-3.xml'); |
298
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
299
|
|
|
$this->assertTrue($return); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
public function testMoveNodePlacementTop() |
303
|
|
|
{ |
304
|
|
|
//test |
305
|
|
|
$return = $this->treeAdapter |
306
|
|
|
->moveNodePlacementTop(17, 1); |
307
|
|
|
|
308
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
309
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
310
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Root node cannot have sibling'); |
311
|
|
|
$this->assertFalse($return); |
312
|
|
|
|
313
|
|
|
//test |
314
|
|
|
$return = $this->treeAdapter |
315
|
|
|
->moveNodePlacementTop(3, 4); |
316
|
|
|
|
317
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
318
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
319
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Source node is in required position'); |
320
|
|
|
$this->assertTrue($return); |
321
|
|
|
|
322
|
|
|
//test |
323
|
|
|
$return = $this->treeAdapter |
324
|
|
|
->moveNodePlacementTop(19, 12); |
325
|
|
|
|
326
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
327
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementTop-1.xml'); |
328
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
329
|
|
|
$this->assertTrue($return); |
330
|
|
|
|
331
|
|
|
//test |
332
|
|
|
$return = $this->treeAdapter |
333
|
|
|
->moveNodePlacementTop(10, 18); |
334
|
|
|
|
335
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
336
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementTop-2.xml'); |
337
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
338
|
|
|
$this->assertTrue($return); |
339
|
|
|
|
340
|
|
|
//test |
341
|
|
|
$return = $this->treeAdapter |
342
|
|
|
->moveNodePlacementTop(21, 6); |
343
|
|
|
|
344
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
345
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementTop-3.xml'); |
346
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
347
|
|
|
$this->assertTrue($return); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
public function testMoveNodePlacementChildBottom() |
351
|
|
|
{ |
352
|
|
|
//test |
353
|
|
|
$return = $this->treeAdapter |
354
|
|
|
->moveNodePlacementChildBottom(22, 18); |
355
|
|
|
|
356
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
357
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
358
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Source node is in required position'); |
359
|
|
|
$this->assertTrue($return); |
360
|
|
|
|
361
|
|
|
//test |
362
|
|
|
$return = $this->treeAdapter |
363
|
|
|
->moveNodePlacementChildBottom(9, 12); |
364
|
|
|
|
365
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
366
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementChildBottom-1.xml'); |
367
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
368
|
|
|
$this->assertTrue($return); |
369
|
|
|
|
370
|
|
|
//test |
371
|
|
|
$return = $this->treeAdapter |
372
|
|
|
->moveNodePlacementChildBottom(10, 3); |
373
|
|
|
|
374
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
375
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementChildBottom-2.xml'); |
376
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
377
|
|
|
$this->assertTrue($return); |
378
|
|
|
|
379
|
|
|
//test |
380
|
|
|
$return = $this->treeAdapter |
381
|
|
|
->moveNodePlacementChildBottom(21, 12); |
382
|
|
|
|
383
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
384
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementChildBottom-3.xml'); |
385
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
386
|
|
|
$this->assertTrue($return); |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
public function testMoveNodePlacementChildTop() |
390
|
|
|
{ |
391
|
|
|
//test |
392
|
|
|
$return = $this->treeAdapter |
393
|
|
|
->moveNodePlacementChildTop(21, 18); |
394
|
|
|
|
395
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
396
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/initDataSetWithIds.xml'); |
397
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet, 'Source node is in required position'); |
398
|
|
|
$this->assertTrue($return); |
399
|
|
|
|
400
|
|
|
//test |
401
|
|
|
$return = $this->treeAdapter |
402
|
|
|
->moveNodePlacementChildTop(9, 21); |
403
|
|
|
|
404
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
405
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementChildTop-1.xml'); |
406
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
407
|
|
|
$this->assertTrue($return); |
408
|
|
|
|
409
|
|
|
//test |
410
|
|
|
$return = $this->treeAdapter |
411
|
|
|
->moveNodePlacementChildTop(16, 3); |
412
|
|
|
|
413
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
414
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementChildTop-2.xml'); |
415
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
416
|
|
|
$this->assertTrue($return); |
417
|
|
|
|
418
|
|
|
//test |
419
|
|
|
$return = $this->treeAdapter |
420
|
|
|
->moveNodePlacementChildTop(18, 3); |
421
|
|
|
|
422
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
423
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testMoveNodePlacementChildTop-3.xml'); |
424
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
425
|
|
|
$this->assertTrue($return); |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
public function testGetPath() |
429
|
|
|
{ |
430
|
|
|
//test |
431
|
|
|
$return = $this->treeAdapter |
432
|
|
|
->getPath(123456789); |
433
|
|
|
$this->assertNull($return); |
434
|
|
|
|
435
|
|
|
//test |
436
|
|
|
$return = $this->treeAdapter |
437
|
|
|
->getPath(6); |
438
|
|
|
$expected = array( |
439
|
|
|
array( |
440
|
|
|
'tree_traversal_id' => '1', |
441
|
|
|
'name' => null, |
442
|
|
|
'lft' => '1', |
443
|
|
|
'rgt' => '50', |
444
|
|
|
'parent_id' => '0', |
445
|
|
|
'level' => '0', |
446
|
|
|
), |
447
|
|
|
array( |
448
|
|
|
'tree_traversal_id' => '3', |
449
|
|
|
'name' => null, |
450
|
|
|
'lft' => '16', |
451
|
|
|
'rgt' => '35', |
452
|
|
|
'parent_id' => '1', |
453
|
|
|
'level' => '1', |
454
|
|
|
), |
455
|
|
|
array( |
456
|
|
|
'tree_traversal_id' => '6', |
457
|
|
|
'name' => null, |
458
|
|
|
'lft' => '17', |
459
|
|
|
'rgt' => '32', |
460
|
|
|
'parent_id' => '3', |
461
|
|
|
'level' => '2', |
462
|
|
|
), |
463
|
|
|
); |
464
|
|
|
$this->assertEquals($expected, $return); |
465
|
|
|
|
466
|
|
|
//test |
467
|
|
|
$return = $this->treeAdapter |
468
|
|
|
->getPath(6, 1); |
469
|
|
|
$expected = array( |
470
|
|
|
array( |
471
|
|
|
'tree_traversal_id' => '3', |
472
|
|
|
'name' => null, |
473
|
|
|
'lft' => '16', |
474
|
|
|
'rgt' => '35', |
475
|
|
|
'parent_id' => '1', |
476
|
|
|
'level' => '1', |
477
|
|
|
), |
478
|
|
|
array( |
479
|
|
|
'tree_traversal_id' => '6', |
480
|
|
|
'name' => null, |
481
|
|
|
'lft' => '17', |
482
|
|
|
'rgt' => '32', |
483
|
|
|
'parent_id' => '3', |
484
|
|
|
'level' => '2', |
485
|
|
|
), |
486
|
|
|
); |
487
|
|
|
$this->assertEquals($expected, $return); |
488
|
|
|
|
489
|
|
|
//test |
490
|
|
|
$return = $this->treeAdapter |
491
|
|
|
->getPath(6, 0, true); |
492
|
|
|
$expected = array( |
493
|
|
|
array( |
494
|
|
|
'tree_traversal_id' => '1', |
495
|
|
|
'name' => null, |
496
|
|
|
'lft' => '1', |
497
|
|
|
'rgt' => '50', |
498
|
|
|
'parent_id' => '0', |
499
|
|
|
'level' => '0', |
500
|
|
|
), |
501
|
|
|
array( |
502
|
|
|
'tree_traversal_id' => '3', |
503
|
|
|
'name' => null, |
504
|
|
|
'lft' => '16', |
505
|
|
|
'rgt' => '35', |
506
|
|
|
'parent_id' => '1', |
507
|
|
|
'level' => '1', |
508
|
|
|
), |
509
|
|
|
); |
510
|
|
|
$this->assertEquals($expected, $return); |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
public function testGetDescendants() |
514
|
|
|
{ |
515
|
|
|
//test |
516
|
|
|
$return = $this->treeAdapter |
517
|
|
|
->getDescendants(123456789); |
518
|
|
|
$this->assertNull($return); |
519
|
|
|
|
520
|
|
|
//test |
521
|
|
|
$return = $this->treeAdapter |
522
|
|
|
->getDescendants(1, 100000); |
523
|
|
|
$this->assertNull($return); |
524
|
|
|
|
525
|
|
|
//test whole branche |
526
|
|
|
$return = $this->treeAdapter |
527
|
|
|
->getDescendants(21); |
528
|
|
|
$expected = array( |
529
|
|
|
array( |
530
|
|
|
'tree_traversal_id' => '21', |
531
|
|
|
'name' => null, |
532
|
|
|
'lft' => '20', |
533
|
|
|
'rgt' => '25', |
534
|
|
|
'parent_id' => '18', |
535
|
|
|
'level' => '5', |
536
|
|
|
), |
537
|
|
|
array( |
538
|
|
|
'tree_traversal_id' => '24', |
539
|
|
|
'name' => null, |
540
|
|
|
'lft' => '21', |
541
|
|
|
'rgt' => '22', |
542
|
|
|
'parent_id' => '21', |
543
|
|
|
'level' => '6', |
544
|
|
|
), |
545
|
|
|
array( |
546
|
|
|
'tree_traversal_id' => '25', |
547
|
|
|
'name' => null, |
548
|
|
|
'lft' => '23', |
549
|
|
|
'rgt' => '24', |
550
|
|
|
'parent_id' => '21', |
551
|
|
|
'level' => '6', |
552
|
|
|
), |
553
|
|
|
); |
554
|
|
|
$this->assertEquals($expected, $return); |
555
|
|
|
|
556
|
|
|
//test different start node |
557
|
|
|
$return = $this->treeAdapter |
558
|
|
|
->getDescendants(6, 3); |
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
|
|
|
array( |
585
|
|
|
'tree_traversal_id' => '22', |
586
|
|
|
'name' => null, |
587
|
|
|
'lft' => '26', |
588
|
|
|
'rgt' => '27', |
589
|
|
|
'parent_id' => '18', |
590
|
|
|
'level' => '5', |
591
|
|
|
), |
592
|
|
|
); |
593
|
|
|
$this->assertEquals($expected, $return); |
594
|
|
|
|
595
|
|
|
//test custom levels |
596
|
|
|
$return = $this->treeAdapter |
597
|
|
|
->getDescendants(18, 0, 2); |
598
|
|
|
$expected = array( |
599
|
|
|
array( |
600
|
|
|
'tree_traversal_id' => '18', |
601
|
|
|
'name' => null, |
602
|
|
|
'lft' => '19', |
603
|
|
|
'rgt' => '28', |
604
|
|
|
'parent_id' => '12', |
605
|
|
|
'level' => '4', |
606
|
|
|
), |
607
|
|
|
array( |
608
|
|
|
'tree_traversal_id' => '21', |
609
|
|
|
'name' => null, |
610
|
|
|
'lft' => '20', |
611
|
|
|
'rgt' => '25', |
612
|
|
|
'parent_id' => '18', |
613
|
|
|
'level' => '5', |
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 exclude node |
627
|
|
|
$return = $this->treeAdapter |
628
|
|
|
->getDescendants(12, 0, null, 21); |
629
|
|
|
$expected = array( |
630
|
|
|
array( |
631
|
|
|
'tree_traversal_id' => '12', |
632
|
|
|
'name' => null, |
633
|
|
|
'lft' => '18', |
634
|
|
|
'rgt' => '29', |
635
|
|
|
'parent_id' => '6', |
636
|
|
|
'level' => '3', |
637
|
|
|
), |
638
|
|
|
array( |
639
|
|
|
'tree_traversal_id' => '18', |
640
|
|
|
'name' => null, |
641
|
|
|
'lft' => '19', |
642
|
|
|
'rgt' => '28', |
643
|
|
|
'parent_id' => '12', |
644
|
|
|
'level' => '4', |
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
|
|
|
|
658
|
|
|
public function testGetChildren() |
659
|
|
|
{ |
660
|
|
|
//test |
661
|
|
|
$return = $this->treeAdapter |
662
|
|
|
->getChildren(123456789); |
663
|
|
|
$this->assertNull($return); |
664
|
|
|
|
665
|
|
|
//test exclude node |
666
|
|
|
$return = $this->treeAdapter |
667
|
|
|
->getChildren(18); |
668
|
|
|
$expected = array( |
669
|
|
|
array( |
670
|
|
|
'tree_traversal_id' => '21', |
671
|
|
|
'name' => null, |
672
|
|
|
'lft' => '20', |
673
|
|
|
'rgt' => '25', |
674
|
|
|
'parent_id' => '18', |
675
|
|
|
'level' => '5', |
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 testUpdateNode() |
690
|
|
|
{ |
691
|
|
|
//test |
692
|
|
|
$data = array( |
693
|
|
|
'name' => 'ahoj', |
694
|
|
|
); |
695
|
|
|
$this->treeAdapter |
696
|
|
|
->updateNode(3, $data); |
697
|
|
|
|
698
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
699
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testUpdateNode-1.xml'); |
700
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
701
|
|
|
|
702
|
|
|
//test |
703
|
|
|
$data = array( |
704
|
|
|
'name' => 'ahoj', |
705
|
|
|
'lft' => '123456', |
706
|
|
|
'rgt' => '123456', |
707
|
|
|
'tree_traversal_id' => '123456', |
708
|
|
|
'level' => '123456', |
709
|
|
|
'parent_id' => '123456', |
710
|
|
|
); |
711
|
|
|
$this->treeAdapter |
712
|
|
|
->updateNode(3, $data); |
713
|
|
|
|
714
|
|
|
$dataSet = $this->getConnection()->createDataSet(array('tree_traversal')); |
715
|
|
|
$expectedDataSet = $this->createMySQLXMLDataSet(__DIR__ . '/_files/NestedSet/testUpdateNode-1.xml'); |
716
|
|
|
$this->assertDataSetsEqual($expectedDataSet, $dataSet); |
717
|
|
|
} |
718
|
|
|
} |
719
|
|
|
|