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