1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Aimeos\MW\Tree\Manager; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class DBNestedSetTest extends \PHPUnit\Framework\TestCase |
7
|
|
|
{ |
8
|
|
|
private static $dbm; |
9
|
|
|
private $config; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
public static function setUpBeforeClass() |
13
|
|
|
{ |
14
|
|
|
self::$dbm = \TestHelperMw::getDBManager(); |
15
|
|
|
|
16
|
|
|
if( !( self::$dbm instanceof \Aimeos\MW\DB\Manager\DBAL ) ) { |
17
|
|
|
return; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
$schema = new \Doctrine\DBAL\Schema\Schema(); |
21
|
|
|
|
22
|
|
|
$table = $schema->createTable( 'mw_tree_test' ); |
23
|
|
|
$table->addColumn( 'id', 'integer', array( 'autoincrement' => true ) ); |
24
|
|
|
$table->addColumn( 'parentid', 'integer', array( 'notnull' => false ) ); |
25
|
|
|
$table->addColumn( 'label', 'string', array( 'length' => 16 ) ); |
26
|
|
|
$table->addColumn( 'code', 'string', array( 'length' => 32 ) ); |
27
|
|
|
$table->addColumn( 'level', 'integer', [] ); |
28
|
|
|
$table->addColumn( 'nleft', 'integer', [] ); |
29
|
|
|
$table->addColumn( 'nright', 'integer', [] ); |
30
|
|
|
$table->addColumn( 'status', 'smallint', [] ); |
31
|
|
|
$table->setPrimaryKey( array( 'id' ) ); |
32
|
|
|
|
33
|
|
|
$conn = self::$dbm->acquire(); |
34
|
|
|
|
35
|
|
|
foreach( $schema->toSQL( $conn->getRawObject()->getDatabasePlatform() ) as $sql ) { |
36
|
|
|
$conn->create( $sql )->execute()->finish(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
self::$dbm->release( $conn ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
public static function tearDownAfterClass() |
44
|
|
|
{ |
45
|
|
|
if( self::$dbm instanceof \Aimeos\MW\DB\Manager\DBAL ) |
46
|
|
|
{ |
47
|
|
|
$conn = self::$dbm->acquire(); |
48
|
|
|
|
49
|
|
|
$conn->create( 'DROP TABLE "mw_tree_test"' )->execute()->finish(); |
50
|
|
|
|
51
|
|
|
self::$dbm->release( $conn ); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
protected function setUp() |
57
|
|
|
{ |
58
|
|
|
if( !( self::$dbm instanceof \Aimeos\MW\DB\Manager\DBAL ) ) { |
59
|
|
|
$this->markTestSkipped( 'No DBAL database manager configured' ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$this->config = []; |
63
|
|
|
|
64
|
|
|
$this->config['search'] = array( |
65
|
|
|
'id' => array( 'label' => 'Tree node ID', 'code' => 'tree.id', 'internalcode' => 'id', 'type' => 'integer', 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT ), |
66
|
|
|
'parentid' => array( 'label' => 'Tree node parent id', 'code' => 'tree.parentid', 'internalcode' => 'parentid', 'type' => 'integer', 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT ), |
67
|
|
|
'label' => array( 'label' => 'Tree node name', 'code' => 'tree.label', 'internalcode' => 'label', 'type' => 'string', 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR ), |
68
|
|
|
'code' => array( 'label' => 'Tree node code', 'code' => 'tree.code', 'internalcode' => 'code', 'type' => 'string', 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR ), |
69
|
|
|
'status' => array( 'label' => 'Tree node status', 'code' => 'tree.status', 'internalcode' => 'status', 'type' => 'boolean', 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT ), |
70
|
|
|
'level' => array( 'label' => 'Tree node level', 'code' => 'tree.level', 'internalcode' => 'level', 'type' => 'integer', 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT ), |
71
|
|
|
'left' => array( 'label' => 'Tree node left number', 'code' => 'tree.left', 'internalcode' => 'nleft', 'type' => 'integer', 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT ), |
72
|
|
|
'right' => array( 'label' => 'Tree node right number', 'code' => 'tree.right', 'internalcode' => 'nright', 'type' => 'integer', 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT ), |
73
|
|
|
|
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$this->config['sql'] = array( |
77
|
|
|
'delete' => ' |
78
|
|
|
DELETE FROM "mw_tree_test" WHERE nleft >= ? AND nright <= ? |
79
|
|
|
', |
80
|
|
|
'get' => ' |
81
|
|
|
SELECT |
82
|
|
|
node."id", node."label", node."code", node."status", node."level", |
83
|
|
|
node."parentid", node."nleft" AS "left", node."nright" AS "right" |
84
|
|
|
FROM "mw_tree_test" AS parent, "mw_tree_test" AS node |
85
|
|
|
WHERE |
86
|
|
|
node.nleft >= parent.nleft AND node.nleft <= parent.nright |
87
|
|
|
AND parent.id = ? AND node.level <= parent.level + ? |
88
|
|
|
AND :cond |
89
|
|
|
ORDER BY node.nleft |
90
|
|
|
', |
91
|
|
|
'insert' => ' |
92
|
|
|
INSERT INTO "mw_tree_test" ( label, code, status, parentid, level, nleft, nright ) VALUES ( ?, ?, ?, ?, ?, ?, ? ) |
93
|
|
|
', |
94
|
|
|
'move-left' => ' |
95
|
|
|
UPDATE "mw_tree_test" |
96
|
|
|
SET nleft = nleft + ?, level = level + ? |
97
|
|
|
WHERE nleft >= ? AND nleft <= ? |
98
|
|
|
', |
99
|
|
|
'move-right' => ' |
100
|
|
|
UPDATE "mw_tree_test" |
101
|
|
|
SET nright = nright + ? |
102
|
|
|
WHERE nright >= ? AND nright <= ? |
103
|
|
|
', |
104
|
|
|
'search' => ' |
105
|
|
|
SELECT "id", "label", "code", "status", "level", "nleft" AS "left", "nright" AS "right" |
106
|
|
|
FROM "mw_tree_test" AS node |
107
|
|
|
WHERE nleft >= ? AND nright <= ? AND :cond |
108
|
|
|
ORDER BY :order |
109
|
|
|
', |
110
|
|
|
'update' => ' |
111
|
|
|
UPDATE "mw_tree_test" SET label = ?, code = ?, status = ? WHERE id = ? |
112
|
|
|
', |
113
|
|
|
'update-parentid' => ' |
114
|
|
|
UPDATE "mw_tree_test" SET parentid = ? WHERE id = ? |
115
|
|
|
', |
116
|
|
|
'transstart' => 'BEGIN', |
117
|
|
|
'transcommit' => 'COMMIT', |
118
|
|
|
'transrollback' => 'ROLLBACK', |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
switch( \TestHelperMw::getConfig()->get( 'resource/db/adapter' ) ) |
122
|
|
|
{ |
123
|
|
|
case 'mysql': $this->config['sql']['newid'] = 'SELECT LAST_INSERT_ID()'; break; |
124
|
|
|
case 'pgsql': $this->config['sql']['newid'] = 'SELECT lastval()'; break; |
125
|
|
|
default: |
126
|
|
|
$this->markTestSkipped( 'Only for MySQL and PostgreSQL' ); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
$conn = self::$dbm->acquire(); |
131
|
|
|
|
132
|
|
|
$sql = 'INSERT INTO "mw_tree_test" (parentid, status, label, code, level, nleft, nright) VALUES (0, 1, \'root\', \'root\', 0, 1, 18)'; |
133
|
|
|
$conn->create( $sql )->execute()->finish(); |
134
|
|
|
|
135
|
|
|
$sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (1, \'l1n1\', \'l1n1\', 1, 2, 7)'; |
136
|
|
|
$conn->create( $sql )->execute()->finish(); |
137
|
|
|
|
138
|
|
|
$sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (1, \'l2n1\', \'l2n1\', 2, 3, 6)'; |
139
|
|
|
$conn->create( $sql )->execute()->finish(); |
140
|
|
|
|
141
|
|
|
$sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (1, \'l3n1\', \'l3n1\', 3, 4, 5)'; |
142
|
|
|
$conn->create( $sql )->execute()->finish(); |
143
|
|
|
|
144
|
|
|
$sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (1, \'l1n2\', \'l1n2\', 1, 8, 15)'; |
145
|
|
|
$conn->create( $sql )->execute()->finish(); |
146
|
|
|
|
147
|
|
|
$sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (1, \'l2n2\', \'l2n2\', 2, 9, 14)'; |
148
|
|
|
$conn->create( $sql )->execute()->finish(); |
149
|
|
|
|
150
|
|
|
$sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (1, \'l3n2\', \'l3n2\', 3, 10, 11)'; |
151
|
|
|
$conn->create( $sql )->execute()->finish(); |
152
|
|
|
|
153
|
|
|
$sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (1, \'l3n3\', \'l3n3\', 3, 12, 13)'; |
154
|
|
|
$conn->create( $sql )->execute()->finish(); |
155
|
|
|
|
156
|
|
|
$sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (1, \'l1n3\', \'l1n3\', 1, 16, 17)'; |
157
|
|
|
$conn->create( $sql )->execute()->finish(); |
158
|
|
|
|
159
|
|
|
$sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (1, \'root2\', \'root2\', 0, 19, 20)'; |
160
|
|
|
$conn->create( $sql )->execute()->finish(); |
161
|
|
|
|
162
|
|
|
self::$dbm->release( $conn ); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
protected function tearDown() |
167
|
|
|
{ |
168
|
|
|
if( self::$dbm instanceof \Aimeos\MW\DB\Manager\DBAL ) |
169
|
|
|
{ |
170
|
|
|
$conn = self::$dbm->acquire(); |
171
|
|
|
|
172
|
|
|
$conn->create( 'DELETE FROM "mw_tree_test"' )->execute()->finish(); |
173
|
|
|
|
174
|
|
|
self::$dbm->release( $conn ); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
|
179
|
|
|
public function testConstructorNoDatabaseManager() |
180
|
|
|
{ |
181
|
|
|
$this->setExpectedException( '\\Aimeos\\MW\\Tree\\Exception' ); |
182
|
|
|
new \Aimeos\MW\Tree\Manager\DBNestedSet($this->config, null); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
public function testConstructorNoConfig() |
187
|
|
|
{ |
188
|
|
|
$this->setExpectedException( '\\Aimeos\\MW\\Tree\\Exception' ); |
189
|
|
|
new \Aimeos\MW\Tree\Manager\DBNestedSet([], self::$dbm); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
|
193
|
|
|
public function testConstructorNoSqlConfig() |
194
|
|
|
{ |
195
|
|
|
unset( $this->config['sql'] ); |
196
|
|
|
|
197
|
|
|
$this->setExpectedException( '\\Aimeos\\MW\\Tree\\Exception' ); |
198
|
|
|
new \Aimeos\MW\Tree\Manager\DBNestedSet($this->config, self::$dbm); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
|
202
|
|
|
public function testConstructorMissingSqlConfig() |
203
|
|
|
{ |
204
|
|
|
unset( $this->config['sql']['newid'] ); |
205
|
|
|
|
206
|
|
|
$this->setExpectedException( '\\Aimeos\\MW\\Tree\\Exception' ); |
207
|
|
|
new \Aimeos\MW\Tree\Manager\DBNestedSet($this->config, self::$dbm); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
|
211
|
|
|
public function testConstructorMissingSsearchConfig() |
212
|
|
|
{ |
213
|
|
|
unset( $this->config['search']['id'] ); |
214
|
|
|
|
215
|
|
|
$this->setExpectedException( '\\Aimeos\\MW\\Tree\\Exception' ); |
216
|
|
|
new \Aimeos\MW\Tree\Manager\DBNestedSet($this->config, self::$dbm); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
|
220
|
|
|
public function testGetSearchAttributes() |
221
|
|
|
{ |
222
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
223
|
|
|
|
224
|
|
|
foreach( $manager->getSearchAttributes() as $attribute ) { |
225
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute ); |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
|
230
|
|
|
public function testIsReadOnly() |
231
|
|
|
{ |
232
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
233
|
|
|
|
234
|
|
|
$this->assertFalse( $manager->isReadOnly() ); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
|
238
|
|
|
public function testCreateSearch() |
239
|
|
|
{ |
240
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
241
|
|
|
|
242
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $manager->createSearch() ); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
|
246
|
|
|
public function testSearchNodes() |
247
|
|
|
{ |
248
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
249
|
|
|
$search = $manager->createSearch(); |
250
|
|
|
|
251
|
|
|
|
252
|
|
|
$search->setConditions( $search->compare( '==', 'tree.level', 1 ) ); |
253
|
|
|
$nodes = $manager->searchNodes( $search ); |
254
|
|
|
|
255
|
|
|
$this->assertEquals( 3, count( $nodes ) ); |
256
|
|
|
|
257
|
|
|
foreach( $nodes as $node ) { |
258
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Tree\\Node\\Iface', $node ); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
|
262
|
|
|
if( ( $node = reset( $nodes ) ) === false ) { |
263
|
|
|
throw new \RuntimeException('No node found'); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
$search->setConditions( $search->compare( '==', 'tree.level', 3 ) ); |
267
|
|
|
$nodes = $manager->searchNodes( $search, $node->getId() ); |
268
|
|
|
|
269
|
|
|
$this->assertEquals( 1, count( $nodes ) ); |
270
|
|
|
|
271
|
|
|
foreach( $nodes as $node ) { |
272
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Tree\\Node\\Iface', $node ); |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
|
277
|
|
|
public function testSearchException() |
278
|
|
|
{ |
279
|
|
|
$this->config['sql']['search'] = ' |
280
|
|
|
SELECT "id", "label", "code", "status", "level", "domain" as "base", "left" AS "left", "right" AS "right" |
281
|
|
|
FROM "mw_tree_test" |
282
|
|
|
WHERE domain123 = ? AND nleft >= ? AND nright <= ? AND :cond |
283
|
|
|
'; |
284
|
|
|
|
285
|
|
|
$this->setExpectedException( '\\Aimeos\\MW\\DB\\Exception' ); |
286
|
|
|
|
287
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet($this->config, self::$dbm); |
288
|
|
|
$manager->searchNodes( $manager->createSearch() ); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
|
292
|
|
|
public function testDeleteNode() |
293
|
|
|
{ |
294
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
295
|
|
|
|
296
|
|
|
$search = $manager->createSearch(); |
297
|
|
|
$search->setConditions( $search->compare( '==', 'tree.label', 'l2n2' ) ); |
298
|
|
|
$nodes = $manager->searchNodes( $search ); |
299
|
|
|
$this->assertEquals( 1, count( $nodes ) ); |
300
|
|
|
|
301
|
|
|
$manager->deleteNode( reset( $nodes )->getId() ); |
302
|
|
|
|
303
|
|
|
$search = $manager->createSearch(); |
304
|
|
|
$nodes = $manager->searchNodes( $search ); |
305
|
|
|
$this->assertEquals( 7, count( $nodes ) ); |
306
|
|
|
|
307
|
|
|
$manager->deleteNode(); |
308
|
|
|
|
309
|
|
|
$search = $manager->createSearch(); |
310
|
|
|
$nodes = $manager->searchNodes( $search ); |
311
|
|
|
$this->assertEquals( 1, count( $nodes ) ); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
|
315
|
|
|
public function testDeleteNodeException() |
316
|
|
|
{ |
317
|
|
|
$this->config['sql']['search'] = ' |
318
|
|
|
DELETE FROM "mw_tree_test" WHERE domain = ? AND nleft12 >= ? AND nright <= ? |
319
|
|
|
'; |
320
|
|
|
|
321
|
|
|
$this->setExpectedException( '\\Aimeos\\MW\\DB\\Exception' ); |
322
|
|
|
|
323
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
324
|
|
|
$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); |
325
|
|
|
$manager->deleteNode($root->getId()); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
|
329
|
|
|
public function testGetNode() |
330
|
|
|
{ |
331
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
332
|
|
|
$search = $manager->createSearch(); |
333
|
|
|
|
334
|
|
|
$node = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE, $search ); |
335
|
|
|
|
336
|
|
|
$this->assertEquals( 0, $node->level ); |
337
|
|
|
$this->assertEquals( 0, count( $node->getChildren() ) ); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
|
341
|
|
|
public function testGetNodeList() |
342
|
|
|
{ |
343
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
344
|
|
|
|
345
|
|
|
$node = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); |
346
|
|
|
$node = $manager->getNode( $node->getId(), \Aimeos\MW\Tree\Manager\Base::LEVEL_LIST ); |
347
|
|
|
|
348
|
|
|
$this->assertEquals( 3, count( $node->getChildren() ) ); |
349
|
|
|
$this->assertEquals( 0, count( $node->getChild( 0 )->getChildren() ) ); |
350
|
|
|
$this->assertEquals( 0, count( $node->getChild( 1 )->getChildren() ) ); |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
|
354
|
|
|
public function testGetNodeTree() |
355
|
|
|
{ |
356
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
357
|
|
|
|
358
|
|
|
$node = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); |
359
|
|
|
$node = $manager->getNode( $node->getId(), \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
360
|
|
|
|
361
|
|
|
$this->assertEquals( 3, count( $node->getChildren() ) ); |
362
|
|
|
$this->assertEquals( 1, count( $node->getChild( 0 )->getChildren() ) ); |
363
|
|
|
$this->assertEquals( 1, count( $node->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
364
|
|
|
$this->assertEquals( 1, count( $node->getChild( 1 )->getChildren() ) ); |
365
|
|
|
$this->assertEquals( 2, count( $node->getChild( 1 )->getChild( 0 )->getChildren() ) ); |
366
|
|
|
$this->assertEquals( 0, count( $node->getChild( 2 )->getChildren() ) ); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
|
370
|
|
|
public function testGetPath() |
371
|
|
|
{ |
372
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
373
|
|
|
|
374
|
|
|
$nodes = []; |
375
|
|
|
$nodes[0] = $manager->getNode(); |
376
|
|
|
$nodes[1] = $nodes[0]->getChild( 1 ); |
377
|
|
|
$nodes[2] = $nodes[1]->getChild( 0 ); |
378
|
|
|
$nodes[3] = $nodes[2]->getChild( 1 ); |
379
|
|
|
|
380
|
|
|
$path = $manager->getPath( $nodes[3]->getId() ); |
381
|
|
|
|
382
|
|
|
foreach( $nodes as $node ) |
383
|
|
|
{ |
384
|
|
|
if( ( $actual = array_shift( $path ) ) === null ) { |
385
|
|
|
throw new \RuntimeException( 'Not enough nodes in path' ); |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
$this->assertEquals( $node->getId(), $actual->getId() ); |
389
|
|
|
} |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
|
393
|
|
|
public function testGetLevelFromConstantException() |
394
|
|
|
{ |
395
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet($this->config, self::$dbm); |
396
|
|
|
|
397
|
|
|
$this->setExpectedException('\\Aimeos\\MW\\Tree\\Exception'); |
398
|
|
|
$manager->getNode( null, 0); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
|
402
|
|
|
public function testInsertNode() |
403
|
|
|
{ |
404
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
405
|
|
|
$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); |
406
|
|
|
|
407
|
|
|
$newNode = $manager->createNode(); |
408
|
|
|
$newNode->setLabel( 'l1n4' ); |
409
|
|
|
$manager->insertNode( $newNode, $root->getId() ); |
410
|
|
|
|
411
|
|
|
$root = $manager->getNode( $root->getId(), \Aimeos\MW\Tree\Manager\Base::LEVEL_LIST ); |
412
|
|
|
$this->assertEquals( 4, count( $root->getChildren() ) ); |
413
|
|
|
$this->assertEquals( 'l1n4', $root->getChild( 3 )->getLabel() ); |
414
|
|
|
$this->assertEquals( $newNode->getId(), $root->getChild( 3 )->getId() ); |
415
|
|
|
|
416
|
|
|
$search = $manager->createSearch(); |
417
|
|
|
$search->setConditions( $search->compare( '==', 'tree.label', 'l1n3' ) ); |
418
|
|
|
$nodes = $manager->searchNodes( $search ); |
419
|
|
|
$this->assertEquals( 1, count( $nodes ) ); |
420
|
|
|
|
421
|
|
|
$newNode->setLabel( 'new l1n3' ); |
422
|
|
|
$manager->insertNode( $newNode, $root->getId(), reset( $nodes )->getId() ); |
423
|
|
|
|
424
|
|
|
$root = $manager->getNode( $root->getId(), \Aimeos\MW\Tree\Manager\Base::LEVEL_LIST ); |
425
|
|
|
$this->assertEquals( 5, count( $root->getChildren() ) ); |
426
|
|
|
$this->assertEquals( 'l1n2', $root->getChild( 1 )->getLabel() ); |
427
|
|
|
$this->assertEquals( 'new l1n3', $root->getChild( 2 )->getLabel() ); |
428
|
|
|
$this->assertEquals( 'l1n3', $root->getChild( 3 )->getLabel() ); |
429
|
|
|
$this->assertEquals( 'l1n4', $root->getChild( 4 )->getLabel() ); |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
|
433
|
|
|
public function testInsertNodeException() |
434
|
|
|
{ |
435
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet($this->config, self::$dbm); |
436
|
|
|
$newNode = $manager->createNode(); |
437
|
|
|
|
438
|
|
|
$this->setExpectedException( '\\Aimeos\\MW\\Tree\\Exception' ); |
439
|
|
|
$manager->insertNode( $newNode, -1 ); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
|
443
|
|
|
public function testInsertNodeRoot() |
444
|
|
|
{ |
445
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
446
|
|
|
|
447
|
|
|
$newNode = $manager->createNode(); |
448
|
|
|
$newNode->setCode( 'root3' ); |
449
|
|
|
$newNode->setLabel( 'Root 3' ); |
450
|
|
|
|
451
|
|
|
$manager->insertNode( $newNode ); |
452
|
|
|
|
453
|
|
|
$root = $manager->getNode( $newNode->getId() ); |
454
|
|
|
$this->assertEquals( 'Root 3', $root->getLabel() ); |
455
|
|
|
$this->assertEquals( 21, $root->left ); |
456
|
|
|
$this->assertEquals( 22, $root->right ); |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
|
460
|
|
|
public function testMoveNodeNoParent() |
461
|
|
|
{ |
462
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
463
|
|
|
$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
464
|
|
|
|
465
|
|
|
$nodeid = $root->getChild( 0 )->getChild( 0 )->getChild( 0 )->getId(); |
466
|
|
|
$oldparentid = $root->getChild( 0 )->getChild( 0 )->getId(); |
467
|
|
|
|
468
|
|
|
$manager->moveNode( $nodeid, $oldparentid, null ); |
469
|
|
|
|
470
|
|
|
$testroot = $manager->getNode( $nodeid, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
471
|
|
|
|
472
|
|
|
$this->assertEquals( 0, $testroot->level ); |
473
|
|
|
$this->assertEquals( 19, $testroot->left ); |
474
|
|
|
$this->assertEquals( 20, $testroot->right ); |
475
|
|
|
$this->assertEquals( 0, count( $testroot->getChildren() ) ); |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
|
479
|
|
|
public function testMoveNode1() |
480
|
|
|
{ |
481
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
482
|
|
|
$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
483
|
|
|
|
484
|
|
|
$nodeid = $root->getChild( 0 )->getChild( 0 )->getChild( 0 )->getId(); |
485
|
|
|
$oldparentid = $root->getChild( 0 )->getChild( 0 )->getId(); |
486
|
|
|
$newparentid = $root->getChild( 0 )->getId(); |
487
|
|
|
$refnodeid = null; |
488
|
|
|
|
489
|
|
|
$manager->moveNode( $nodeid, $oldparentid, $newparentid, $refnodeid ); |
490
|
|
|
|
491
|
|
|
$testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
492
|
|
|
|
493
|
|
|
$this->assertEquals( 0, $testroot->level ); |
494
|
|
|
$this->assertEquals( 1, $testroot->left ); |
495
|
|
|
$this->assertEquals( 18, $testroot->right ); |
496
|
|
|
$this->assertEquals( 3, count( $testroot->getChildren() ) ); |
497
|
|
|
|
498
|
|
|
$this->assertEquals( 1, $testroot->getChild( 0 )->level ); |
499
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->left ); |
500
|
|
|
$this->assertEquals( 7, $testroot->getChild( 0 )->right ); |
501
|
|
|
$this->assertEquals( 2, count( $testroot->getChild( 0 )->getChildren() ) ); |
502
|
|
|
|
503
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level ); |
504
|
|
|
$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left ); |
505
|
|
|
$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->right ); |
506
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
507
|
|
|
|
508
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 1 )->level ); |
509
|
|
|
$this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 1 )->left ); |
510
|
|
|
$this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 1 )->right ); |
511
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 1 )->getChildren() ) ); |
512
|
|
|
|
513
|
|
|
$this->assertEquals( 1, $testroot->getChild( 1 )->level ); |
514
|
|
|
$this->assertEquals( 8, $testroot->getChild( 1 )->left ); |
515
|
|
|
$this->assertEquals( 15, $testroot->getChild( 1 )->right ); |
516
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 1 )->getChildren() ) ); |
517
|
|
|
|
518
|
|
|
$this->assertEquals( 2, $testroot->getChild( 1 )->getChild( 0 )->level ); |
519
|
|
|
$this->assertEquals( 9, $testroot->getChild( 1 )->getChild( 0 )->left ); |
520
|
|
|
$this->assertEquals( 14, $testroot->getChild( 1 )->getChild( 0 )->right ); |
521
|
|
|
$this->assertEquals( 2, count( $testroot->getChild( 1 )->getChild( 0 )->getChildren() ) ); |
522
|
|
|
|
523
|
|
|
$this->assertEquals( 3, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->level ); |
524
|
|
|
$this->assertEquals( 10, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->left ); |
525
|
|
|
$this->assertEquals( 11, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->right ); |
526
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
527
|
|
|
|
528
|
|
|
$this->assertEquals( 3, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->level ); |
529
|
|
|
$this->assertEquals( 12, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->left ); |
530
|
|
|
$this->assertEquals( 13, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->right ); |
531
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->getChildren() ) ); |
532
|
|
|
|
533
|
|
|
$this->assertEquals( 1, $testroot->getChild( 2 )->level ); |
534
|
|
|
$this->assertEquals( 16, $testroot->getChild( 2 )->left ); |
535
|
|
|
$this->assertEquals( 17, $testroot->getChild( 2 )->right ); |
536
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChildren() ) ); |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
|
540
|
|
|
public function testMoveNode2() |
541
|
|
|
{ |
542
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
543
|
|
|
$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
544
|
|
|
|
545
|
|
|
$nodeid = $root->getChild( 1 )->getChild( 0 )->getId(); |
546
|
|
|
$oldparentid = $root->getChild( 1 )->getId(); |
547
|
|
|
$newparentid = $root->getId(); |
548
|
|
|
$refnodeid = $root->getChild( 1 )->getId(); |
549
|
|
|
|
550
|
|
|
$manager->moveNode( $nodeid, $oldparentid, $newparentid, $refnodeid ); |
551
|
|
|
|
552
|
|
|
$testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
553
|
|
|
|
554
|
|
|
$this->assertEquals( 0, $testroot->level ); |
555
|
|
|
$this->assertEquals( 1, $testroot->left ); |
556
|
|
|
$this->assertEquals( 18, $testroot->right ); |
557
|
|
|
$this->assertEquals( 4, count( $testroot->getChildren() ) ); |
558
|
|
|
|
559
|
|
|
$this->assertEquals( 1, $testroot->getChild( 0 )->level ); |
560
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->left ); |
561
|
|
|
$this->assertEquals( 7, $testroot->getChild( 0 )->right ); |
562
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChildren() ) ); |
563
|
|
|
|
564
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level ); |
565
|
|
|
$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left ); |
566
|
|
|
$this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right ); |
567
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
568
|
|
|
|
569
|
|
|
$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level ); |
570
|
|
|
$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left ); |
571
|
|
|
$this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right ); |
572
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
573
|
|
|
|
574
|
|
|
$this->assertEquals( 1, $testroot->getChild( 1 )->level ); |
575
|
|
|
$this->assertEquals( 8, $testroot->getChild( 1 )->left ); |
576
|
|
|
$this->assertEquals( 13, $testroot->getChild( 1 )->right ); |
577
|
|
|
$this->assertEquals( 2, count( $testroot->getChild( 1 )->getChildren() ) ); |
578
|
|
|
|
579
|
|
|
$this->assertEquals( 2, $testroot->getChild( 1 )->getChild( 0 )->level ); |
580
|
|
|
$this->assertEquals( 9, $testroot->getChild( 1 )->getChild( 0 )->left ); |
581
|
|
|
$this->assertEquals( 10, $testroot->getChild( 1 )->getChild( 0 )->right ); |
582
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChildren() ) ); |
583
|
|
|
|
584
|
|
|
$this->assertEquals( 2, $testroot->getChild( 1 )->getChild( 1 )->level ); |
585
|
|
|
$this->assertEquals( 11, $testroot->getChild( 1 )->getChild( 1 )->left ); |
586
|
|
|
$this->assertEquals( 12, $testroot->getChild( 1 )->getChild( 1 )->right ); |
587
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 1 )->getChildren() ) ); |
588
|
|
|
|
589
|
|
|
$this->assertEquals( 1, $testroot->getChild( 2 )->level ); |
590
|
|
|
$this->assertEquals( 14, $testroot->getChild( 2 )->left ); |
591
|
|
|
$this->assertEquals( 15, $testroot->getChild( 2 )->right ); |
592
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChildren() ) ); |
593
|
|
|
|
594
|
|
|
$this->assertEquals( 1, $testroot->getChild( 3 )->level ); |
595
|
|
|
$this->assertEquals( 16, $testroot->getChild( 3 )->left ); |
596
|
|
|
$this->assertEquals( 17, $testroot->getChild( 3 )->right ); |
597
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 3 )->getChildren() ) ); |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
|
601
|
|
|
public function testMoveNode3() |
602
|
|
|
{ |
603
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
604
|
|
|
$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
605
|
|
|
|
606
|
|
|
$nodeid = $root->getChild( 1 )->getChild( 0 )->getId(); |
607
|
|
|
$oldparentid = $root->getChild( 1 )->getId(); |
608
|
|
|
$newparentid = $root->getId(); |
609
|
|
|
$refnodeid = $root->getChild( 2 )->getId(); |
610
|
|
|
|
611
|
|
|
$manager->moveNode( $nodeid, $oldparentid, $newparentid, $refnodeid ); |
612
|
|
|
|
613
|
|
|
$testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
614
|
|
|
|
615
|
|
|
$this->assertEquals( 0, $testroot->level ); |
616
|
|
|
$this->assertEquals( 1, $testroot->left ); |
617
|
|
|
$this->assertEquals( 18, $testroot->right ); |
618
|
|
|
$this->assertEquals( 4, count( $testroot->getChildren() ) ); |
619
|
|
|
|
620
|
|
|
$this->assertEquals( 1, $testroot->getChild( 0 )->level ); |
621
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->left ); |
622
|
|
|
$this->assertEquals( 7, $testroot->getChild( 0 )->right ); |
623
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChildren() ) ); |
624
|
|
|
|
625
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level ); |
626
|
|
|
$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left ); |
627
|
|
|
$this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right ); |
628
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
629
|
|
|
|
630
|
|
|
$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level ); |
631
|
|
|
$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left ); |
632
|
|
|
$this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right ); |
633
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
634
|
|
|
|
635
|
|
|
$this->assertEquals( 1, $testroot->getChild( 1 )->level ); |
636
|
|
|
$this->assertEquals( 8, $testroot->getChild( 1 )->left ); |
637
|
|
|
$this->assertEquals( 9, $testroot->getChild( 1 )->right ); |
638
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChildren() ) ); |
639
|
|
|
|
640
|
|
|
$this->assertEquals( 1, $testroot->getChild( 2 )->level ); |
641
|
|
|
$this->assertEquals( 10, $testroot->getChild( 2 )->left ); |
642
|
|
|
$this->assertEquals( 15, $testroot->getChild( 2 )->right ); |
643
|
|
|
$this->assertEquals( 2, count( $testroot->getChild( 2 )->getChildren() ) ); |
644
|
|
|
|
645
|
|
|
$this->assertEquals( 2, $testroot->getChild( 2 )->getChild( 0 )->level ); |
646
|
|
|
$this->assertEquals( 11, $testroot->getChild( 2 )->getChild( 0 )->left ); |
647
|
|
|
$this->assertEquals( 12, $testroot->getChild( 2 )->getChild( 0 )->right ); |
648
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChild( 0 )->getChildren() ) ); |
649
|
|
|
|
650
|
|
|
$this->assertEquals( 2, $testroot->getChild( 2 )->getChild( 1 )->level ); |
651
|
|
|
$this->assertEquals( 13, $testroot->getChild( 2 )->getChild( 1 )->left ); |
652
|
|
|
$this->assertEquals( 14, $testroot->getChild( 2 )->getChild( 1 )->right ); |
653
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChild( 1 )->getChildren() ) ); |
654
|
|
|
|
655
|
|
|
$this->assertEquals( 1, $testroot->getChild( 3 )->level ); |
656
|
|
|
$this->assertEquals( 16, $testroot->getChild( 3 )->left ); |
657
|
|
|
$this->assertEquals( 17, $testroot->getChild( 3 )->right ); |
658
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 3 )->getChildren() ) ); |
659
|
|
|
} |
660
|
|
|
|
661
|
|
|
|
662
|
|
|
public function testMoveNode4() |
663
|
|
|
{ |
664
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
665
|
|
|
$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
666
|
|
|
|
667
|
|
|
$nodeid = $root->getChild( 1 )->getChild( 0 )->getId(); |
668
|
|
|
$oldparentid = $root->getChild( 1 )->getId(); |
669
|
|
|
$newparentid = $root->getId(); |
670
|
|
|
$refnodeid = null; |
671
|
|
|
|
672
|
|
|
$manager->moveNode( $nodeid, $oldparentid, $newparentid, $refnodeid ); |
673
|
|
|
|
674
|
|
|
$testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
675
|
|
|
|
676
|
|
|
$this->assertEquals( 0, $testroot->level ); |
677
|
|
|
$this->assertEquals( 1, $testroot->left ); |
678
|
|
|
$this->assertEquals( 18, $testroot->right ); |
679
|
|
|
$this->assertEquals( 4, count( $testroot->getChildren() ) ); |
680
|
|
|
|
681
|
|
|
$this->assertEquals( 1, $testroot->getChild( 0 )->level ); |
682
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->left ); |
683
|
|
|
$this->assertEquals( 7, $testroot->getChild( 0 )->right ); |
684
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChildren() ) ); |
685
|
|
|
|
686
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level ); |
687
|
|
|
$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left ); |
688
|
|
|
$this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right ); |
689
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
690
|
|
|
|
691
|
|
|
$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level ); |
692
|
|
|
$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left ); |
693
|
|
|
$this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right ); |
694
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
695
|
|
|
|
696
|
|
|
$this->assertEquals( 1, $testroot->getChild( 1 )->level ); |
697
|
|
|
$this->assertEquals( 8, $testroot->getChild( 1 )->left ); |
698
|
|
|
$this->assertEquals( 9, $testroot->getChild( 1 )->right ); |
699
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChildren() ) ); |
700
|
|
|
|
701
|
|
|
$this->assertEquals( 1, $testroot->getChild( 2 )->level ); |
702
|
|
|
$this->assertEquals( 10, $testroot->getChild( 2 )->left ); |
703
|
|
|
$this->assertEquals( 11, $testroot->getChild( 2 )->right ); |
704
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChildren() ) ); |
705
|
|
|
|
706
|
|
|
$this->assertEquals( 1, $testroot->getChild( 3 )->level ); |
707
|
|
|
$this->assertEquals( 12, $testroot->getChild( 3 )->left ); |
708
|
|
|
$this->assertEquals( 17, $testroot->getChild( 3 )->right ); |
709
|
|
|
$this->assertEquals( 2, count( $testroot->getChild( 3 )->getChildren() ) ); |
710
|
|
|
|
711
|
|
|
$this->assertEquals( 2, $testroot->getChild( 3 )->getChild( 0 )->level ); |
712
|
|
|
$this->assertEquals( 13, $testroot->getChild( 3 )->getChild( 0 )->left ); |
713
|
|
|
$this->assertEquals( 14, $testroot->getChild( 3 )->getChild( 0 )->right ); |
714
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 3 )->getChild( 0 )->getChildren() ) ); |
715
|
|
|
|
716
|
|
|
$this->assertEquals( 2, $testroot->getChild( 3 )->getChild( 1 )->level ); |
717
|
|
|
$this->assertEquals( 15, $testroot->getChild( 3 )->getChild( 1 )->left ); |
718
|
|
|
$this->assertEquals( 16, $testroot->getChild( 3 )->getChild( 1 )->right ); |
719
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 3 )->getChild( 1 )->getChildren() ) ); |
720
|
|
|
} |
721
|
|
|
|
722
|
|
|
|
723
|
|
|
public function testMoveNode5() |
724
|
|
|
{ |
725
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
726
|
|
|
$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
727
|
|
|
|
728
|
|
|
$nodeid = $root->getChild( 1 )->getChild( 0 )->getId(); |
729
|
|
|
$oldparentid = $root->getChild( 1 )->getId(); |
730
|
|
|
$newparentid = $root->getChild( 2 )->getId(); |
731
|
|
|
$refnodeid = null; |
732
|
|
|
|
733
|
|
|
$manager->moveNode( $nodeid, $oldparentid, $newparentid, $refnodeid ); |
734
|
|
|
|
735
|
|
|
$testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
736
|
|
|
|
737
|
|
|
$this->assertEquals( 0, $testroot->level ); |
738
|
|
|
$this->assertEquals( 1, $testroot->left ); |
739
|
|
|
$this->assertEquals( 18, $testroot->right ); |
740
|
|
|
$this->assertEquals( 3, count( $testroot->getChildren() ) ); |
741
|
|
|
|
742
|
|
|
$this->assertEquals( 1, $testroot->getChild( 0 )->level ); |
743
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->left ); |
744
|
|
|
$this->assertEquals( 7, $testroot->getChild( 0 )->right ); |
745
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChildren() ) ); |
746
|
|
|
|
747
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level ); |
748
|
|
|
$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left ); |
749
|
|
|
$this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right ); |
750
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
751
|
|
|
|
752
|
|
|
$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level ); |
753
|
|
|
$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left ); |
754
|
|
|
$this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right ); |
755
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
756
|
|
|
|
757
|
|
|
$this->assertEquals( 1, $testroot->getChild( 1 )->level ); |
758
|
|
|
$this->assertEquals( 8, $testroot->getChild( 1 )->left ); |
759
|
|
|
$this->assertEquals( 9, $testroot->getChild( 1 )->right ); |
760
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChildren() ) ); |
761
|
|
|
|
762
|
|
|
$this->assertEquals( 1, $testroot->getChild( 2 )->level ); |
763
|
|
|
$this->assertEquals( 10, $testroot->getChild( 2 )->left ); |
764
|
|
|
$this->assertEquals( 17, $testroot->getChild( 2 )->right ); |
765
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 2 )->getChildren() ) ); |
766
|
|
|
|
767
|
|
|
$this->assertEquals( 2, $testroot->getChild( 2 )->getChild( 0 )->level ); |
768
|
|
|
$this->assertEquals( 11, $testroot->getChild( 2 )->getChild( 0 )->left ); |
769
|
|
|
$this->assertEquals( 16, $testroot->getChild( 2 )->getChild( 0 )->right ); |
770
|
|
|
$this->assertEquals( 2, count( $testroot->getChild( 2 )->getChild( 0 )->getChildren() ) ); |
771
|
|
|
|
772
|
|
|
$this->assertEquals( 3, $testroot->getChild( 2 )->getChild( 0 )->getChild( 0 )->level ); |
773
|
|
|
$this->assertEquals( 12, $testroot->getChild( 2 )->getChild( 0 )->getChild( 0 )->left ); |
774
|
|
|
$this->assertEquals( 13, $testroot->getChild( 2 )->getChild( 0 )->getChild( 0 )->right ); |
775
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
776
|
|
|
|
777
|
|
|
$this->assertEquals( 3, $testroot->getChild( 2 )->getChild( 0 )->getChild( 1 )->level ); |
778
|
|
|
$this->assertEquals( 14, $testroot->getChild( 2 )->getChild( 0 )->getChild( 1 )->left ); |
779
|
|
|
$this->assertEquals( 15, $testroot->getChild( 2 )->getChild( 0 )->getChild( 1 )->right ); |
780
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChild( 0 )->getChild( 1 )->getChildren() ) ); |
781
|
|
|
} |
782
|
|
|
|
783
|
|
|
|
784
|
|
|
public function testMoveNode6() |
785
|
|
|
{ |
786
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
787
|
|
|
$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
788
|
|
|
|
789
|
|
|
$nodeid = $root->getChild( 1 )->getChild( 0 )->getId(); |
790
|
|
|
$oldparentid = $root->getChild( 1 )->getId(); |
791
|
|
|
$newparentid = $root->getId(); |
792
|
|
|
$refnodeid = $root->getChild( 2 )->getId(); |
793
|
|
|
|
794
|
|
|
$manager->moveNode( $nodeid, $oldparentid, $newparentid, $refnodeid ); |
795
|
|
|
|
796
|
|
|
|
797
|
|
|
$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
798
|
|
|
|
799
|
|
|
$nodeid = $root->getChild( 2 )->getId(); |
800
|
|
|
$oldparentid = $root->getId(); |
801
|
|
|
$newparentid = $root->getChild( 1 )->getId(); |
802
|
|
|
$refnodeid = null; |
803
|
|
|
|
804
|
|
|
$manager->moveNode( $nodeid, $oldparentid, $newparentid, $refnodeid ); |
805
|
|
|
|
806
|
|
|
|
807
|
|
|
$testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
808
|
|
|
|
809
|
|
|
$this->assertEquals( 0, $testroot->level ); |
810
|
|
|
$this->assertEquals( 1, $testroot->left ); |
811
|
|
|
$this->assertEquals( 18, $testroot->right ); |
812
|
|
|
$this->assertEquals( 3, count( $testroot->getChildren() ) ); |
813
|
|
|
|
814
|
|
|
$this->assertEquals( 1, $testroot->getChild( 0 )->level ); |
815
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->left ); |
816
|
|
|
$this->assertEquals( 7, $testroot->getChild( 0 )->right ); |
817
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChildren() ) ); |
818
|
|
|
|
819
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level ); |
820
|
|
|
$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left ); |
821
|
|
|
$this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right ); |
822
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
823
|
|
|
|
824
|
|
|
$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level ); |
825
|
|
|
$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left ); |
826
|
|
|
$this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right ); |
827
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
828
|
|
|
|
829
|
|
|
$this->assertEquals( 1, $testroot->getChild( 1 )->level ); |
830
|
|
|
$this->assertEquals( 8, $testroot->getChild( 1 )->left ); |
831
|
|
|
$this->assertEquals( 15, $testroot->getChild( 1 )->right ); |
832
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 1 )->getChildren() ) ); |
833
|
|
|
|
834
|
|
|
$this->assertEquals( 2, $testroot->getChild( 1 )->getChild( 0 )->level ); |
835
|
|
|
$this->assertEquals( 9, $testroot->getChild( 1 )->getChild( 0 )->left ); |
836
|
|
|
$this->assertEquals( 14, $testroot->getChild( 1 )->getChild( 0 )->right ); |
837
|
|
|
$this->assertEquals( 2, count( $testroot->getChild( 1 )->getChild( 0 )->getChildren() ) ); |
838
|
|
|
|
839
|
|
|
$this->assertEquals( 3, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->level ); |
840
|
|
|
$this->assertEquals( 10, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->left ); |
841
|
|
|
$this->assertEquals( 11, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->right ); |
842
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
843
|
|
|
|
844
|
|
|
$this->assertEquals( 3, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->level ); |
845
|
|
|
$this->assertEquals( 12, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->left ); |
846
|
|
|
$this->assertEquals( 13, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->right ); |
847
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->getChildren() ) ); |
848
|
|
|
|
849
|
|
|
$this->assertEquals( 1, $testroot->getChild( 2 )->level ); |
850
|
|
|
$this->assertEquals( 16, $testroot->getChild( 2 )->left ); |
851
|
|
|
$this->assertEquals( 17, $testroot->getChild( 2 )->right ); |
852
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChildren() ) ); |
853
|
|
|
} |
854
|
|
|
|
855
|
|
|
|
856
|
|
|
public function testMoveNode7() |
857
|
|
|
{ |
858
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
859
|
|
|
$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
860
|
|
|
|
861
|
|
|
$nodeid = $root->getChild( 1 )->getChild( 0 )->getId(); |
862
|
|
|
$oldparentid = $root->getChild( 1 )->getId(); |
863
|
|
|
$newparentid = $root->getId(); |
864
|
|
|
$refnodeid = $root->getChild( 1 )->getId(); |
865
|
|
|
|
866
|
|
|
$manager->moveNode( $nodeid, $oldparentid, $newparentid, $refnodeid ); |
867
|
|
|
|
868
|
|
|
|
869
|
|
|
$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
870
|
|
|
|
871
|
|
|
$nodeid = $root->getChild( 1 )->getId(); |
872
|
|
|
$oldparentid = $root->getId(); |
873
|
|
|
$newparentid = $root->getChild( 2 )->getId(); |
874
|
|
|
$refnodeid = null; |
875
|
|
|
|
876
|
|
|
$manager->moveNode( $nodeid, $oldparentid, $newparentid, $refnodeid ); |
877
|
|
|
|
878
|
|
|
|
879
|
|
|
$testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
880
|
|
|
|
881
|
|
|
$this->assertEquals( 0, $testroot->level ); |
882
|
|
|
$this->assertEquals( 1, $testroot->left ); |
883
|
|
|
$this->assertEquals( 18, $testroot->right ); |
884
|
|
|
$this->assertEquals( 3, count( $testroot->getChildren() ) ); |
885
|
|
|
|
886
|
|
|
$this->assertEquals( 1, $testroot->getChild( 0 )->level ); |
887
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->left ); |
888
|
|
|
$this->assertEquals( 7, $testroot->getChild( 0 )->right ); |
889
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChildren() ) ); |
890
|
|
|
|
891
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level ); |
892
|
|
|
$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left ); |
893
|
|
|
$this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right ); |
894
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
895
|
|
|
|
896
|
|
|
$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level ); |
897
|
|
|
$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left ); |
898
|
|
|
$this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right ); |
899
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
900
|
|
|
|
901
|
|
|
$this->assertEquals( 1, $testroot->getChild( 1 )->level ); |
902
|
|
|
$this->assertEquals( 8, $testroot->getChild( 1 )->left ); |
903
|
|
|
$this->assertEquals( 15, $testroot->getChild( 1 )->right ); |
904
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 1 )->getChildren() ) ); |
905
|
|
|
|
906
|
|
|
$this->assertEquals( 2, $testroot->getChild( 1 )->getChild( 0 )->level ); |
907
|
|
|
$this->assertEquals( 9, $testroot->getChild( 1 )->getChild( 0 )->left ); |
908
|
|
|
$this->assertEquals( 14, $testroot->getChild( 1 )->getChild( 0 )->right ); |
909
|
|
|
$this->assertEquals( 2, count( $testroot->getChild( 1 )->getChild( 0 )->getChildren() ) ); |
910
|
|
|
|
911
|
|
|
$this->assertEquals( 3, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->level ); |
912
|
|
|
$this->assertEquals( 10, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->left ); |
913
|
|
|
$this->assertEquals( 11, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->right ); |
914
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
915
|
|
|
|
916
|
|
|
$this->assertEquals( 3, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->level ); |
917
|
|
|
$this->assertEquals( 12, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->left ); |
918
|
|
|
$this->assertEquals( 13, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->right ); |
919
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->getChildren() ) ); |
920
|
|
|
|
921
|
|
|
$this->assertEquals( 1, $testroot->getChild( 2 )->level ); |
922
|
|
|
$this->assertEquals( 16, $testroot->getChild( 2 )->left ); |
923
|
|
|
$this->assertEquals( 17, $testroot->getChild( 2 )->right ); |
924
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChildren() ) ); |
925
|
|
|
} |
926
|
|
|
|
927
|
|
|
|
928
|
|
|
public function testMoveNode8() |
929
|
|
|
{ |
930
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
931
|
|
|
$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
932
|
|
|
|
933
|
|
|
$nodeid = $root->getChild( 1 )->getId(); |
934
|
|
|
$oldparentid = $root->getId(); |
935
|
|
|
$newparentid = $root->getChild( 0 )->getId(); |
936
|
|
|
$refnodeid = null; |
937
|
|
|
|
938
|
|
|
$manager->moveNode( $nodeid, $oldparentid, $newparentid, $refnodeid ); |
939
|
|
|
|
940
|
|
|
|
941
|
|
|
$testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
942
|
|
|
|
943
|
|
|
$this->assertEquals( 0, $testroot->level ); |
944
|
|
|
$this->assertEquals( 1, $testroot->left ); |
945
|
|
|
$this->assertEquals( 18, $testroot->right ); |
946
|
|
|
$this->assertEquals( 2, count( $testroot->getChildren() ) ); |
947
|
|
|
|
948
|
|
|
$this->assertEquals( 1, $testroot->getChild( 0 )->level ); |
949
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->left ); |
950
|
|
|
$this->assertEquals( 15, $testroot->getChild( 0 )->right ); |
951
|
|
|
$this->assertEquals( 2, count( $testroot->getChild( 0 )->getChildren() ) ); |
952
|
|
|
|
953
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level ); |
954
|
|
|
$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left ); |
955
|
|
|
$this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right ); |
956
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
957
|
|
|
|
958
|
|
|
$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level ); |
959
|
|
|
$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left ); |
960
|
|
|
$this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right ); |
961
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
962
|
|
|
|
963
|
|
|
$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 1 )->level ); |
964
|
|
|
$this->assertEquals( 7, $testroot->getChild( 0 )->getChild( 1 )->left ); |
965
|
|
|
$this->assertEquals( 14, $testroot->getChild( 0 )->getChild( 1 )->right ); |
966
|
|
|
$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 1 )->getChildren() ) ); |
967
|
|
|
|
968
|
|
|
$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->level ); |
969
|
|
|
$this->assertEquals( 8, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->left ); |
970
|
|
|
$this->assertEquals( 13, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->right ); |
971
|
|
|
$this->assertEquals( 2, count( $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChildren() ) ); |
972
|
|
|
|
973
|
|
|
$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChild( 0 )->level ); |
974
|
|
|
$this->assertEquals( 9, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChild( 0 )->left ); |
975
|
|
|
$this->assertEquals( 10, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChild( 0 )->right ); |
976
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
977
|
|
|
|
978
|
|
|
$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChild( 1 )->level ); |
979
|
|
|
$this->assertEquals( 11, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChild( 1 )->left ); |
980
|
|
|
$this->assertEquals( 12, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChild( 1 )->right ); |
981
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChild( 1 )->getChildren() ) ); |
982
|
|
|
|
983
|
|
|
$this->assertEquals( 1, $testroot->getChild( 1 )->level ); |
984
|
|
|
$this->assertEquals( 16, $testroot->getChild( 1 )->left ); |
985
|
|
|
$this->assertEquals( 17, $testroot->getChild( 1 )->right ); |
986
|
|
|
$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChildren() ) ); |
987
|
|
|
} |
988
|
|
|
|
989
|
|
|
|
990
|
|
|
public function testMoveNodeException() |
991
|
|
|
{ |
992
|
|
|
$this->config['sql']['move-left'] = ' |
993
|
|
|
UPDATE "mw_tree_test" |
994
|
|
|
SET nleft123 = nleft + ?, level = level + ? |
995
|
|
|
WHERE nleft >= ? AND nleft <= ? |
996
|
|
|
'; |
997
|
|
|
|
998
|
|
|
$this->config['sql']['move-right'] = ' |
999
|
|
|
UPDATE "mw_tree_test" |
1000
|
|
|
SET nright123 = nright + ? |
1001
|
|
|
WHERE nright >= ? AND nright <= ? |
1002
|
|
|
'; |
1003
|
|
|
|
1004
|
|
|
|
1005
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet($this->config, self::$dbm); |
1006
|
|
|
|
1007
|
|
|
$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
1008
|
|
|
|
1009
|
|
|
$nodeid = $root->getChild( 1 )->getId(); |
1010
|
|
|
$oldparentid = $root->getId(); |
1011
|
|
|
$newparentid = $root->getChild( 0 )->getId(); |
1012
|
|
|
|
1013
|
|
|
$this->setExpectedException( '\\Aimeos\\MW\\DB\\Exception' ); |
1014
|
|
|
$manager->moveNode( $nodeid, $oldparentid, $newparentid ); |
1015
|
|
|
} |
1016
|
|
|
|
1017
|
|
|
|
1018
|
|
|
public function testSaveNode() |
1019
|
|
|
{ |
1020
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
1021
|
|
|
$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); |
1022
|
|
|
|
1023
|
|
|
$root->setLabel( 'rooot' ); |
1024
|
|
|
$manager->saveNode( $root ); |
1025
|
|
|
|
1026
|
|
|
$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); |
1027
|
|
|
$this->assertEquals( 'rooot', $root->getLabel() ); |
1028
|
|
|
} |
1029
|
|
|
|
1030
|
|
|
|
1031
|
|
|
public function testSaveNodeException() |
1032
|
|
|
{ |
1033
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm ); |
1034
|
|
|
$node = $manager->createNode(); |
1035
|
|
|
|
1036
|
|
|
$this->setExpectedException( '\\Aimeos\\MW\\Tree\\Exception' ); |
1037
|
|
|
$manager->saveNode($node); |
1038
|
|
|
} |
1039
|
|
|
|
1040
|
|
|
|
1041
|
|
|
public function testSaveNodeException2() |
1042
|
|
|
{ |
1043
|
|
|
$this->config['sql']['update'] = ' |
1044
|
|
|
UPDATE "mw_tree_test" SET label123 = ?, status = ? WHERE id = ? |
1045
|
|
|
'; |
1046
|
|
|
|
1047
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet($this->config, self::$dbm); |
1048
|
|
|
$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); |
1049
|
|
|
|
1050
|
|
|
$root->setLabel( 'rooot' ); |
1051
|
|
|
|
1052
|
|
|
$this->setExpectedException( '\\Aimeos\\MW\\DB\\Exception' ); |
1053
|
|
|
$manager->saveNode( $root ); |
1054
|
|
|
} |
1055
|
|
|
|
1056
|
|
|
|
1057
|
|
|
public function testSetReadOnly() |
1058
|
|
|
{ |
1059
|
|
|
$class = new \ReflectionClass( '\Aimeos\MW\Tree\Manager\DBNestedSet' ); |
1060
|
|
|
$method = $class->getMethod( 'setReadOnly' ); |
1061
|
|
|
$method->setAccessible( true ); |
1062
|
|
|
|
1063
|
|
|
$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet($this->config, self::$dbm); |
1064
|
|
|
|
1065
|
|
|
$method->invokeArgs( $manager, [] ); |
1066
|
|
|
|
1067
|
|
|
$this->assertTrue( $manager->isReadOnly() ); |
1068
|
|
|
} |
1069
|
|
|
|
1070
|
|
|
} |
1071
|
|
|
|