| Total Complexity | 53 |
| Total Lines | 1085 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| 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 | |||
| 16 | if( !( self::$dbm instanceof \Aimeos\Base\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->get(); |
||
| 34 | |||
| 35 | foreach( $schema->toSQL( $conn->getRawObject()->getDatabasePlatform() ) as $sql ) { |
||
| 36 | $conn->create( $sql )->execute()->finish(); |
||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | |||
| 41 | public static function tearDownAfterClass() : void |
||
| 42 | { |
||
| 43 | if( self::$dbm instanceof \Aimeos\Base\DB\Manager\DBAL ) |
||
| 44 | { |
||
| 45 | $conn = self::$dbm->get(); |
||
| 46 | $conn->create( 'DROP TABLE "mw_tree_test"' )->execute()->finish(); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | |||
| 51 | protected function setUp() : void |
||
| 52 | { |
||
| 53 | if( !( self::$dbm instanceof \Aimeos\Base\DB\Manager\DBAL ) ) { |
||
| 54 | $this->markTestSkipped( 'No DBAL database manager configured' ); |
||
| 55 | } |
||
| 56 | |||
| 57 | $this->config = []; |
||
| 58 | |||
| 59 | $this->config['search'] = array( |
||
| 60 | 'id' => array( 'label' => 'Tree node ID', 'code' => 'tree.id', 'internalcode' => 'node.id', 'type' => 'integer', 'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT ), |
||
| 61 | 'parentid' => array( 'label' => 'Tree node parent id', 'code' => 'tree.parentid', 'internalcode' => 'node.parentid', 'type' => 'integer', 'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT ), |
||
| 62 | 'label' => array( 'label' => 'Tree node name', 'code' => 'tree.label', 'internalcode' => 'node.label', 'type' => 'string', 'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR ), |
||
| 63 | 'code' => array( 'label' => 'Tree node code', 'code' => 'tree.code', 'internalcode' => 'node.code', 'type' => 'string', 'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR ), |
||
| 64 | 'status' => array( 'label' => 'Tree node status', 'code' => 'tree.status', 'internalcode' => 'node.status', 'type' => 'boolean', 'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT ), |
||
| 65 | 'level' => array( 'label' => 'Tree node level', 'code' => 'tree.level', 'internalcode' => 'node.level', 'type' => 'integer', 'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT ), |
||
| 66 | 'left' => array( 'label' => 'Tree node left number', 'code' => 'tree.left', 'internalcode' => 'node.nleft', 'type' => 'integer', 'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT ), |
||
| 67 | 'right' => array( 'label' => 'Tree node right number', 'code' => 'tree.right', 'internalcode' => 'node.nright', 'type' => 'integer', 'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT ), |
||
| 68 | |||
| 69 | ); |
||
| 70 | |||
| 71 | $this->config['sql'] = array( |
||
| 72 | 'delete' => ' |
||
| 73 | DELETE FROM "mw_tree_test" WHERE nleft >= ? AND nright <= ? |
||
| 74 | ', |
||
| 75 | 'get' => ' |
||
| 76 | SELECT |
||
| 77 | node."id", node."label", node."code", node."status", node."level", |
||
| 78 | node."parentid", node."nleft" AS "left", node."nright" AS "right" |
||
| 79 | FROM "mw_tree_test" AS parent, "mw_tree_test" AS node |
||
| 80 | WHERE |
||
| 81 | node.nleft >= parent.nleft AND node.nleft <= parent.nright |
||
| 82 | AND parent.id = ? AND node.level <= parent.level + ? |
||
| 83 | AND :cond |
||
| 84 | ORDER BY node.nleft |
||
| 85 | ', |
||
| 86 | 'insert' => ' |
||
| 87 | INSERT INTO "mw_tree_test" ( label, code, status, parentid, level, nleft, nright ) VALUES ( ?, ?, ?, ?, ?, ?, ? ) |
||
| 88 | ', |
||
| 89 | 'move-left' => ' |
||
| 90 | UPDATE "mw_tree_test" |
||
| 91 | SET nleft = nleft + ?, level = level + ? |
||
| 92 | WHERE nleft >= ? AND nleft <= ? |
||
| 93 | ', |
||
| 94 | 'move-right' => ' |
||
| 95 | UPDATE "mw_tree_test" |
||
| 96 | SET nright = nright + ? |
||
| 97 | WHERE nright >= ? AND nright <= ? |
||
| 98 | ', |
||
| 99 | 'search' => ' |
||
| 100 | SELECT "id", "label", "code", "status", "level", "nleft" AS "left", "nright" AS "right" |
||
| 101 | FROM "mw_tree_test" AS node |
||
| 102 | WHERE nleft >= ? AND nright <= ? AND :cond |
||
| 103 | ORDER BY :order |
||
| 104 | ', |
||
| 105 | 'update' => ' |
||
| 106 | UPDATE "mw_tree_test" SET label = ?, code = ?, status = ? WHERE id = ? |
||
| 107 | ', |
||
| 108 | 'update-parentid' => ' |
||
| 109 | UPDATE "mw_tree_test" SET parentid = ? WHERE id = ? |
||
| 110 | ', |
||
| 111 | 'transstart' => 'BEGIN', |
||
| 112 | 'transcommit' => 'COMMIT', |
||
| 113 | 'transrollback' => 'ROLLBACK', |
||
| 114 | ); |
||
| 115 | |||
| 116 | switch( \TestHelper::getConfig()->get( 'resource/db/adapter' ) ) |
||
| 117 | { |
||
| 118 | case 'mysql': $this->config['sql']['newid'] = 'SELECT LAST_INSERT_ID()'; break; |
||
| 119 | case 'pgsql': $this->config['sql']['newid'] = 'SELECT lastval()'; break; |
||
| 120 | default: |
||
| 121 | $this->markTestSkipped( 'Only for MySQL and PostgreSQL' ); |
||
| 122 | } |
||
| 123 | |||
| 124 | |||
| 125 | $conn = self::$dbm->get(); |
||
| 126 | |||
| 127 | $sql = 'INSERT INTO "mw_tree_test" (parentid, status, label, code, level, nleft, nright) VALUES (0, 1, \'root\', \'root\', 0, 1, 18)'; |
||
| 128 | $conn->create( $sql )->execute()->finish(); |
||
| 129 | |||
| 130 | $sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (1, \'l1n1\', \'l1n1\', 1, 2, 7)'; |
||
| 131 | $conn->create( $sql )->execute()->finish(); |
||
| 132 | |||
| 133 | $sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (0, \'l2n1\', \'l2n1\', 2, 3, 6)'; |
||
| 134 | $conn->create( $sql )->execute()->finish(); |
||
| 135 | |||
| 136 | $sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (1, \'l3n1\', \'l3n1\', 3, 4, 5)'; |
||
| 137 | $conn->create( $sql )->execute()->finish(); |
||
| 138 | |||
| 139 | $sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (1, \'l1n2\', \'l1n2\', 1, 8, 15)'; |
||
| 140 | $conn->create( $sql )->execute()->finish(); |
||
| 141 | |||
| 142 | $sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (1, \'l2n2\', \'l2n2\', 2, 9, 14)'; |
||
| 143 | $conn->create( $sql )->execute()->finish(); |
||
| 144 | |||
| 145 | $sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (1, \'l3n2\', \'l3n2\', 3, 10, 11)'; |
||
| 146 | $conn->create( $sql )->execute()->finish(); |
||
| 147 | |||
| 148 | $sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (1, \'l3n3\', \'l3n3\', 3, 12, 13)'; |
||
| 149 | $conn->create( $sql )->execute()->finish(); |
||
| 150 | |||
| 151 | $sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (1, \'l1n3\', \'l1n3\', 1, 16, 17)'; |
||
| 152 | $conn->create( $sql )->execute()->finish(); |
||
| 153 | |||
| 154 | $sql = 'INSERT INTO "mw_tree_test" (status, label, code, level, nleft, nright) VALUES (1, \'root2\', \'root2\', 0, 19, 20)'; |
||
| 155 | $conn->create( $sql )->execute()->finish(); |
||
| 156 | } |
||
| 157 | |||
| 158 | |||
| 159 | protected function tearDown() : void |
||
| 160 | { |
||
| 161 | if( self::$dbm instanceof \Aimeos\Base\DB\Manager\DBAL ) |
||
| 162 | { |
||
| 163 | $conn = self::$dbm->get(); |
||
| 164 | $conn->create( 'DELETE FROM "mw_tree_test"' )->execute()->finish(); |
||
| 165 | } |
||
| 166 | } |
||
| 167 | |||
| 168 | |||
| 169 | public function testConstructorNoDatabaseManager() |
||
| 170 | { |
||
| 171 | $this->expectException( \Aimeos\MW\Tree\Exception::class ); |
||
| 172 | new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, null ); |
||
| 173 | } |
||
| 174 | |||
| 175 | |||
| 176 | public function testConstructorNoConfig() |
||
| 177 | { |
||
| 178 | $this->expectException( \Aimeos\MW\Tree\Exception::class ); |
||
| 179 | new \Aimeos\MW\Tree\Manager\DBNestedSet( [], self::$dbm->get() ); |
||
| 180 | } |
||
| 181 | |||
| 182 | |||
| 183 | public function testConstructorNoSqlConfig() |
||
| 184 | { |
||
| 185 | unset( $this->config['sql'] ); |
||
| 186 | |||
| 187 | $this->expectException( \Aimeos\MW\Tree\Exception::class ); |
||
| 188 | new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 189 | } |
||
| 190 | |||
| 191 | |||
| 192 | public function testConstructorMissingSqlConfig() |
||
| 198 | } |
||
| 199 | |||
| 200 | |||
| 201 | public function testConstructorMissingSearchConfig() |
||
| 202 | { |
||
| 203 | unset( $this->config['search']['id'] ); |
||
| 204 | |||
| 205 | $this->expectException( \Aimeos\MW\Tree\Exception::class ); |
||
| 206 | new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 207 | } |
||
| 208 | |||
| 209 | |||
| 210 | public function testGetSearchAttributes() |
||
| 211 | { |
||
| 212 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 213 | |||
| 214 | foreach( $manager->getSearchAttributes() as $attribute ) { |
||
| 215 | $this->assertInstanceOf( \Aimeos\Base\Criteria\Attribute\Iface::class, $attribute ); |
||
| 216 | } |
||
| 217 | } |
||
| 218 | |||
| 219 | |||
| 220 | public function testIsReadOnly() |
||
| 221 | { |
||
| 222 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 223 | |||
| 224 | $this->assertFalse( $manager->isReadOnly() ); |
||
| 225 | } |
||
| 226 | |||
| 227 | |||
| 228 | public function testCreateSearch() |
||
| 229 | { |
||
| 230 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 231 | |||
| 232 | $this->assertInstanceOf( \Aimeos\Base\Criteria\Iface::class, $manager->createSearch() ); |
||
| 233 | } |
||
| 234 | |||
| 235 | |||
| 236 | public function testSearchNodes() |
||
| 237 | { |
||
| 238 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 239 | $search = $manager->createSearch(); |
||
| 240 | |||
| 241 | |||
| 242 | $search->setConditions( $search->compare( '==', 'tree.level', 1 ) ); |
||
| 243 | $nodes = $manager->searchNodes( $search ); |
||
| 244 | |||
| 245 | $this->assertEquals( 3, count( $nodes ) ); |
||
| 246 | |||
| 247 | foreach( $nodes as $node ) { |
||
| 248 | $this->assertInstanceOf( \Aimeos\MW\Tree\Node\Iface::class, $node ); |
||
| 249 | } |
||
| 250 | |||
| 251 | |||
| 252 | if( ( $node = reset( $nodes ) ) === false ) { |
||
| 253 | throw new \RuntimeException( 'No node found' ); |
||
| 254 | } |
||
| 255 | |||
| 256 | $search->setConditions( $search->compare( '==', 'tree.level', 3 ) ); |
||
| 257 | $nodes = $manager->searchNodes( $search, $node->getId() ); |
||
| 258 | |||
| 259 | $this->assertEquals( 1, count( $nodes ) ); |
||
| 260 | |||
| 261 | foreach( $nodes as $node ) { |
||
| 262 | $this->assertInstanceOf( \Aimeos\MW\Tree\Node\Iface::class, $node ); |
||
| 263 | } |
||
| 264 | } |
||
| 265 | |||
| 266 | |||
| 267 | public function testSearchException() |
||
| 279 | } |
||
| 280 | |||
| 281 | |||
| 282 | public function testDeleteNode() |
||
| 283 | { |
||
| 284 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 285 | |||
| 286 | $search = $manager->createSearch(); |
||
| 287 | $search->setConditions( $search->compare( '==', 'tree.label', 'l2n2' ) ); |
||
| 288 | $nodes = $manager->searchNodes( $search ); |
||
| 289 | $this->assertEquals( 1, count( $nodes ) ); |
||
| 290 | |||
| 291 | $this->assertInstanceOf( \Aimeos\MW\Tree\Manager\Iface::class, $manager->deleteNode( reset( $nodes )->getId() ) ); |
||
| 292 | |||
| 293 | $search = $manager->createSearch(); |
||
| 294 | $nodes = $manager->searchNodes( $search ); |
||
| 295 | $this->assertEquals( 7, count( $nodes ) ); |
||
| 296 | } |
||
| 297 | |||
| 298 | |||
| 299 | public function testDeleteNodeException() |
||
| 310 | } |
||
| 311 | |||
| 312 | |||
| 313 | public function testGetNode() |
||
| 314 | { |
||
| 315 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 316 | $search = $manager->createSearch(); |
||
| 317 | |||
| 318 | $node = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE, $search ); |
||
| 319 | |||
| 320 | $this->assertEquals( 0, $node->level ); |
||
| 321 | $this->assertEquals( 0, count( $node->getChildren() ) ); |
||
| 322 | } |
||
| 323 | |||
| 324 | |||
| 325 | public function testGetNodeList() |
||
| 335 | } |
||
| 336 | |||
| 337 | |||
| 338 | public function testGetNodeTree() |
||
| 351 | } |
||
| 352 | |||
| 353 | |||
| 354 | public function testGetNodeTreeCondition() |
||
| 355 | { |
||
| 356 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 357 | $filter = $manager->createSearch()->add( 'tree.status', '==', 1 ); |
||
| 358 | |||
| 359 | $node = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE, $filter ); |
||
| 360 | |||
| 361 | $this->assertEquals( 3, count( $node->getChildren() ) ); |
||
| 362 | $this->assertEquals( 0, count( $node->getChild( 0 )->getChildren() ) ); |
||
| 363 | $this->assertEquals( 1, count( $node->getChild( 1 )->getChildren() ) ); |
||
| 364 | $this->assertEquals( 2, count( $node->getChild( 1 )->getChild( 0 )->getChildren() ) ); |
||
| 365 | $this->assertEquals( 0, count( $node->getChild( 2 )->getChildren() ) ); |
||
| 366 | } |
||
| 367 | |||
| 368 | |||
| 369 | public function testGetPath() |
||
| 370 | { |
||
| 371 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 372 | |||
| 373 | $nodes = []; |
||
| 374 | $nodes[0] = $manager->getNode(); |
||
| 375 | $nodes[1] = $nodes[0]->getChild( 1 ); |
||
| 376 | $nodes[2] = $nodes[1]->getChild( 0 ); |
||
| 377 | $nodes[3] = $nodes[2]->getChild( 1 ); |
||
| 378 | |||
| 379 | $path = $manager->getPath( (string) $nodes[3]->getId() ); |
||
| 380 | |||
| 381 | foreach( $nodes as $node ) |
||
| 382 | { |
||
| 383 | if( ( $actual = array_shift( $path ) ) === null ) { |
||
| 384 | throw new \RuntimeException( 'Not enough nodes in path' ); |
||
| 385 | } |
||
| 386 | |||
| 387 | $this->assertEquals( $node->getId(), $actual->getId() ); |
||
| 388 | } |
||
| 389 | } |
||
| 390 | |||
| 391 | |||
| 392 | public function testGetLevelFromConstantException() |
||
| 393 | { |
||
| 394 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 395 | |||
| 396 | $this->expectException( \Aimeos\MW\Tree\Exception::class ); |
||
| 397 | $manager->getNode( null, 0 ); |
||
| 398 | } |
||
| 399 | |||
| 400 | |||
| 401 | public function testInsertNode() |
||
| 402 | { |
||
| 403 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 404 | $root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); |
||
| 405 | |||
| 406 | $newNode = $manager->createNode(); |
||
| 407 | $newNode->setLabel( 'l1n4' ); |
||
| 408 | $manager->insertNode( $newNode, $root->getId() ); |
||
| 409 | |||
| 410 | $root = $manager->getNode( $root->getId(), \Aimeos\MW\Tree\Manager\Base::LEVEL_LIST ); |
||
| 411 | $this->assertEquals( 4, count( $root->getChildren() ) ); |
||
| 412 | $this->assertEquals( 'l1n4', $root->getChild( 3 )->getLabel() ); |
||
| 413 | $this->assertEquals( $newNode->getId(), $root->getChild( 3 )->getId() ); |
||
| 414 | |||
| 415 | $search = $manager->createSearch(); |
||
| 416 | $search->setConditions( $search->compare( '==', 'tree.label', 'l1n3' ) ); |
||
| 417 | $nodes = $manager->searchNodes( $search ); |
||
| 418 | $this->assertEquals( 1, count( $nodes ) ); |
||
| 419 | |||
| 420 | $newNode->setLabel( 'new l1n3' ); |
||
| 421 | $newNode = $manager->insertNode( $newNode, $root->getId(), reset( $nodes )->getId() ); |
||
|
|
|||
| 422 | |||
| 423 | $root = $manager->getNode( $root->getId(), \Aimeos\MW\Tree\Manager\Base::LEVEL_LIST ); |
||
| 424 | $this->assertInstanceOf( \Aimeos\MW\Tree\Node\Iface::class, $newNode ); |
||
| 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->get() ); |
||
| 436 | $newNode = $manager->createNode(); |
||
| 437 | |||
| 438 | $this->expectException( \Aimeos\MW\Tree\Exception::class ); |
||
| 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->get() ); |
||
| 446 | |||
| 447 | $newNode = $manager->createNode(); |
||
| 448 | $newNode->setCode( 'root3' ); |
||
| 449 | $newNode->setLabel( 'Root 3' ); |
||
| 450 | |||
| 451 | $this->assertInstanceOf( \Aimeos\MW\Tree\Node\Iface::class, $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->get() ); |
||
| 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 | $result = $manager->moveNode( (string) $nodeid, $oldparentid, null ); |
||
| 469 | $this->assertInstanceOf( \Aimeos\MW\Tree\Manager\Iface::class, $result ); |
||
| 470 | |||
| 471 | $testroot = $manager->getNode( $nodeid, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
||
| 472 | |||
| 473 | $this->assertEquals( 0, $testroot->level ); |
||
| 474 | $this->assertEquals( 19, $testroot->left ); |
||
| 475 | $this->assertEquals( 20, $testroot->right ); |
||
| 476 | $this->assertEquals( 0, count( $testroot->getChildren() ) ); |
||
| 477 | } |
||
| 478 | |||
| 479 | |||
| 480 | public function testMoveNodeSameParent() |
||
| 481 | { |
||
| 482 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 483 | $root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
||
| 484 | |||
| 485 | $nodeid = $root->getChild( 0 )->getId(); |
||
| 486 | $oldparentid = $root->getId(); |
||
| 487 | |||
| 488 | $manager->moveNode( (string) $nodeid, $oldparentid, $oldparentid ); |
||
| 489 | $manager->moveNode( (string) $nodeid, $oldparentid, $oldparentid ); |
||
| 490 | |||
| 491 | $testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
||
| 492 | |||
| 493 | $this->assertEquals( 'l1n1', $testroot->getChild( 2 )->label ); |
||
| 494 | $this->assertEquals( 1, $testroot->getChild( 2 )->level ); |
||
| 495 | $this->assertEquals( 12, $testroot->getChild( 2 )->left ); |
||
| 496 | $this->assertEquals( 17, $testroot->getChild( 2 )->right ); |
||
| 497 | $this->assertEquals( 1, count( $testroot->getChild( 2 )->getChildren() ) ); |
||
| 498 | } |
||
| 499 | |||
| 500 | |||
| 501 | public function testMoveNode1() |
||
| 502 | { |
||
| 503 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 504 | $root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
||
| 505 | |||
| 506 | $nodeid = $root->getChild( 0 )->getChild( 0 )->getChild( 0 )->getId(); |
||
| 507 | $oldparentid = $root->getChild( 0 )->getChild( 0 )->getId(); |
||
| 508 | $newparentid = $root->getChild( 0 )->getId(); |
||
| 509 | $refnodeid = null; |
||
| 510 | |||
| 511 | $manager->moveNode( (string) $nodeid, $oldparentid, $newparentid, $refnodeid ); |
||
| 512 | |||
| 513 | $testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
||
| 514 | |||
| 515 | $this->assertEquals( 0, $testroot->level ); |
||
| 516 | $this->assertEquals( 1, $testroot->left ); |
||
| 517 | $this->assertEquals( 18, $testroot->right ); |
||
| 518 | $this->assertEquals( 3, count( $testroot->getChildren() ) ); |
||
| 519 | |||
| 520 | $this->assertEquals( 1, $testroot->getChild( 0 )->level ); |
||
| 521 | $this->assertEquals( 2, $testroot->getChild( 0 )->left ); |
||
| 522 | $this->assertEquals( 7, $testroot->getChild( 0 )->right ); |
||
| 523 | $this->assertEquals( 2, count( $testroot->getChild( 0 )->getChildren() ) ); |
||
| 524 | |||
| 525 | $this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level ); |
||
| 526 | $this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left ); |
||
| 527 | $this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->right ); |
||
| 528 | $this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
||
| 529 | |||
| 530 | $this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 1 )->level ); |
||
| 531 | $this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 1 )->left ); |
||
| 532 | $this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 1 )->right ); |
||
| 533 | $this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 1 )->getChildren() ) ); |
||
| 534 | |||
| 535 | $this->assertEquals( 1, $testroot->getChild( 1 )->level ); |
||
| 536 | $this->assertEquals( 8, $testroot->getChild( 1 )->left ); |
||
| 537 | $this->assertEquals( 15, $testroot->getChild( 1 )->right ); |
||
| 538 | $this->assertEquals( 1, count( $testroot->getChild( 1 )->getChildren() ) ); |
||
| 539 | |||
| 540 | $this->assertEquals( 2, $testroot->getChild( 1 )->getChild( 0 )->level ); |
||
| 541 | $this->assertEquals( 9, $testroot->getChild( 1 )->getChild( 0 )->left ); |
||
| 542 | $this->assertEquals( 14, $testroot->getChild( 1 )->getChild( 0 )->right ); |
||
| 543 | $this->assertEquals( 2, count( $testroot->getChild( 1 )->getChild( 0 )->getChildren() ) ); |
||
| 544 | |||
| 545 | $this->assertEquals( 3, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->level ); |
||
| 546 | $this->assertEquals( 10, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->left ); |
||
| 547 | $this->assertEquals( 11, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->right ); |
||
| 548 | $this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
||
| 549 | |||
| 550 | $this->assertEquals( 3, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->level ); |
||
| 551 | $this->assertEquals( 12, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->left ); |
||
| 552 | $this->assertEquals( 13, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->right ); |
||
| 553 | $this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->getChildren() ) ); |
||
| 554 | |||
| 555 | $this->assertEquals( 1, $testroot->getChild( 2 )->level ); |
||
| 556 | $this->assertEquals( 16, $testroot->getChild( 2 )->left ); |
||
| 557 | $this->assertEquals( 17, $testroot->getChild( 2 )->right ); |
||
| 558 | $this->assertEquals( 0, count( $testroot->getChild( 2 )->getChildren() ) ); |
||
| 559 | } |
||
| 560 | |||
| 561 | |||
| 562 | public function testMoveNode2() |
||
| 563 | { |
||
| 564 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 565 | $root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
||
| 566 | |||
| 567 | $nodeid = $root->getChild( 1 )->getChild( 0 )->getId(); |
||
| 568 | $oldparentid = $root->getChild( 1 )->getId(); |
||
| 569 | $newparentid = $root->getId(); |
||
| 570 | $refnodeid = $root->getChild( 1 )->getId(); |
||
| 571 | |||
| 572 | $manager->moveNode( (string) $nodeid, $oldparentid, $newparentid, $refnodeid ); |
||
| 573 | |||
| 574 | $testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
||
| 575 | |||
| 576 | $this->assertEquals( 0, $testroot->level ); |
||
| 577 | $this->assertEquals( 1, $testroot->left ); |
||
| 578 | $this->assertEquals( 18, $testroot->right ); |
||
| 579 | $this->assertEquals( 4, count( $testroot->getChildren() ) ); |
||
| 580 | |||
| 581 | $this->assertEquals( 1, $testroot->getChild( 0 )->level ); |
||
| 582 | $this->assertEquals( 2, $testroot->getChild( 0 )->left ); |
||
| 583 | $this->assertEquals( 7, $testroot->getChild( 0 )->right ); |
||
| 584 | $this->assertEquals( 1, count( $testroot->getChild( 0 )->getChildren() ) ); |
||
| 585 | |||
| 586 | $this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level ); |
||
| 587 | $this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left ); |
||
| 588 | $this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right ); |
||
| 589 | $this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
||
| 590 | |||
| 591 | $this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level ); |
||
| 592 | $this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left ); |
||
| 593 | $this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right ); |
||
| 594 | $this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
||
| 595 | |||
| 596 | $this->assertEquals( 1, $testroot->getChild( 1 )->level ); |
||
| 597 | $this->assertEquals( 8, $testroot->getChild( 1 )->left ); |
||
| 598 | $this->assertEquals( 13, $testroot->getChild( 1 )->right ); |
||
| 599 | $this->assertEquals( 2, count( $testroot->getChild( 1 )->getChildren() ) ); |
||
| 600 | |||
| 601 | $this->assertEquals( 2, $testroot->getChild( 1 )->getChild( 0 )->level ); |
||
| 602 | $this->assertEquals( 9, $testroot->getChild( 1 )->getChild( 0 )->left ); |
||
| 603 | $this->assertEquals( 10, $testroot->getChild( 1 )->getChild( 0 )->right ); |
||
| 604 | $this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChildren() ) ); |
||
| 605 | |||
| 606 | $this->assertEquals( 2, $testroot->getChild( 1 )->getChild( 1 )->level ); |
||
| 607 | $this->assertEquals( 11, $testroot->getChild( 1 )->getChild( 1 )->left ); |
||
| 608 | $this->assertEquals( 12, $testroot->getChild( 1 )->getChild( 1 )->right ); |
||
| 609 | $this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 1 )->getChildren() ) ); |
||
| 610 | |||
| 611 | $this->assertEquals( 1, $testroot->getChild( 2 )->level ); |
||
| 612 | $this->assertEquals( 14, $testroot->getChild( 2 )->left ); |
||
| 613 | $this->assertEquals( 15, $testroot->getChild( 2 )->right ); |
||
| 614 | $this->assertEquals( 0, count( $testroot->getChild( 2 )->getChildren() ) ); |
||
| 615 | |||
| 616 | $this->assertEquals( 1, $testroot->getChild( 3 )->level ); |
||
| 617 | $this->assertEquals( 16, $testroot->getChild( 3 )->left ); |
||
| 618 | $this->assertEquals( 17, $testroot->getChild( 3 )->right ); |
||
| 619 | $this->assertEquals( 0, count( $testroot->getChild( 3 )->getChildren() ) ); |
||
| 620 | } |
||
| 621 | |||
| 622 | |||
| 623 | public function testMoveNode3() |
||
| 624 | { |
||
| 625 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 626 | $root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
||
| 627 | |||
| 628 | $nodeid = $root->getChild( 1 )->getChild( 0 )->getId(); |
||
| 629 | $oldparentid = $root->getChild( 1 )->getId(); |
||
| 630 | $newparentid = $root->getId(); |
||
| 631 | $refnodeid = $root->getChild( 2 )->getId(); |
||
| 632 | |||
| 633 | $manager->moveNode( (string) $nodeid, $oldparentid, $newparentid, $refnodeid ); |
||
| 634 | |||
| 635 | $testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
||
| 636 | |||
| 637 | $this->assertEquals( 0, $testroot->level ); |
||
| 638 | $this->assertEquals( 1, $testroot->left ); |
||
| 639 | $this->assertEquals( 18, $testroot->right ); |
||
| 640 | $this->assertEquals( 4, count( $testroot->getChildren() ) ); |
||
| 641 | |||
| 642 | $this->assertEquals( 1, $testroot->getChild( 0 )->level ); |
||
| 643 | $this->assertEquals( 2, $testroot->getChild( 0 )->left ); |
||
| 644 | $this->assertEquals( 7, $testroot->getChild( 0 )->right ); |
||
| 645 | $this->assertEquals( 1, count( $testroot->getChild( 0 )->getChildren() ) ); |
||
| 646 | |||
| 647 | $this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level ); |
||
| 648 | $this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left ); |
||
| 649 | $this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right ); |
||
| 650 | $this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
||
| 651 | |||
| 652 | $this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level ); |
||
| 653 | $this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left ); |
||
| 654 | $this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right ); |
||
| 655 | $this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
||
| 656 | |||
| 657 | $this->assertEquals( 1, $testroot->getChild( 1 )->level ); |
||
| 658 | $this->assertEquals( 8, $testroot->getChild( 1 )->left ); |
||
| 659 | $this->assertEquals( 9, $testroot->getChild( 1 )->right ); |
||
| 660 | $this->assertEquals( 0, count( $testroot->getChild( 1 )->getChildren() ) ); |
||
| 661 | |||
| 662 | $this->assertEquals( 1, $testroot->getChild( 2 )->level ); |
||
| 663 | $this->assertEquals( 10, $testroot->getChild( 2 )->left ); |
||
| 664 | $this->assertEquals( 15, $testroot->getChild( 2 )->right ); |
||
| 665 | $this->assertEquals( 2, count( $testroot->getChild( 2 )->getChildren() ) ); |
||
| 666 | |||
| 667 | $this->assertEquals( 2, $testroot->getChild( 2 )->getChild( 0 )->level ); |
||
| 668 | $this->assertEquals( 11, $testroot->getChild( 2 )->getChild( 0 )->left ); |
||
| 669 | $this->assertEquals( 12, $testroot->getChild( 2 )->getChild( 0 )->right ); |
||
| 670 | $this->assertEquals( 0, count( $testroot->getChild( 2 )->getChild( 0 )->getChildren() ) ); |
||
| 671 | |||
| 672 | $this->assertEquals( 2, $testroot->getChild( 2 )->getChild( 1 )->level ); |
||
| 673 | $this->assertEquals( 13, $testroot->getChild( 2 )->getChild( 1 )->left ); |
||
| 674 | $this->assertEquals( 14, $testroot->getChild( 2 )->getChild( 1 )->right ); |
||
| 675 | $this->assertEquals( 0, count( $testroot->getChild( 2 )->getChild( 1 )->getChildren() ) ); |
||
| 676 | |||
| 677 | $this->assertEquals( 1, $testroot->getChild( 3 )->level ); |
||
| 678 | $this->assertEquals( 16, $testroot->getChild( 3 )->left ); |
||
| 679 | $this->assertEquals( 17, $testroot->getChild( 3 )->right ); |
||
| 680 | $this->assertEquals( 0, count( $testroot->getChild( 3 )->getChildren() ) ); |
||
| 681 | } |
||
| 682 | |||
| 683 | |||
| 684 | public function testMoveNode4() |
||
| 685 | { |
||
| 686 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 687 | $root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
||
| 688 | |||
| 689 | $nodeid = $root->getChild( 1 )->getChild( 0 )->getId(); |
||
| 690 | $oldparentid = $root->getChild( 1 )->getId(); |
||
| 691 | $newparentid = $root->getId(); |
||
| 692 | $refnodeid = null; |
||
| 693 | |||
| 694 | $manager->moveNode( (string) $nodeid, $oldparentid, $newparentid, $refnodeid ); |
||
| 695 | |||
| 696 | $testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
||
| 697 | |||
| 698 | $this->assertEquals( 0, $testroot->level ); |
||
| 699 | $this->assertEquals( 1, $testroot->left ); |
||
| 700 | $this->assertEquals( 18, $testroot->right ); |
||
| 701 | $this->assertEquals( 4, count( $testroot->getChildren() ) ); |
||
| 702 | |||
| 703 | $this->assertEquals( 1, $testroot->getChild( 0 )->level ); |
||
| 704 | $this->assertEquals( 2, $testroot->getChild( 0 )->left ); |
||
| 705 | $this->assertEquals( 7, $testroot->getChild( 0 )->right ); |
||
| 706 | $this->assertEquals( 1, count( $testroot->getChild( 0 )->getChildren() ) ); |
||
| 707 | |||
| 708 | $this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level ); |
||
| 709 | $this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left ); |
||
| 710 | $this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right ); |
||
| 711 | $this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
||
| 712 | |||
| 713 | $this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level ); |
||
| 714 | $this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left ); |
||
| 715 | $this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right ); |
||
| 716 | $this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
||
| 717 | |||
| 718 | $this->assertEquals( 1, $testroot->getChild( 1 )->level ); |
||
| 719 | $this->assertEquals( 8, $testroot->getChild( 1 )->left ); |
||
| 720 | $this->assertEquals( 9, $testroot->getChild( 1 )->right ); |
||
| 721 | $this->assertEquals( 0, count( $testroot->getChild( 1 )->getChildren() ) ); |
||
| 722 | |||
| 723 | $this->assertEquals( 1, $testroot->getChild( 2 )->level ); |
||
| 724 | $this->assertEquals( 10, $testroot->getChild( 2 )->left ); |
||
| 725 | $this->assertEquals( 11, $testroot->getChild( 2 )->right ); |
||
| 726 | $this->assertEquals( 0, count( $testroot->getChild( 2 )->getChildren() ) ); |
||
| 727 | |||
| 728 | $this->assertEquals( 1, $testroot->getChild( 3 )->level ); |
||
| 729 | $this->assertEquals( 12, $testroot->getChild( 3 )->left ); |
||
| 730 | $this->assertEquals( 17, $testroot->getChild( 3 )->right ); |
||
| 731 | $this->assertEquals( 2, count( $testroot->getChild( 3 )->getChildren() ) ); |
||
| 732 | |||
| 733 | $this->assertEquals( 2, $testroot->getChild( 3 )->getChild( 0 )->level ); |
||
| 734 | $this->assertEquals( 13, $testroot->getChild( 3 )->getChild( 0 )->left ); |
||
| 735 | $this->assertEquals( 14, $testroot->getChild( 3 )->getChild( 0 )->right ); |
||
| 736 | $this->assertEquals( 0, count( $testroot->getChild( 3 )->getChild( 0 )->getChildren() ) ); |
||
| 737 | |||
| 738 | $this->assertEquals( 2, $testroot->getChild( 3 )->getChild( 1 )->level ); |
||
| 739 | $this->assertEquals( 15, $testroot->getChild( 3 )->getChild( 1 )->left ); |
||
| 740 | $this->assertEquals( 16, $testroot->getChild( 3 )->getChild( 1 )->right ); |
||
| 741 | $this->assertEquals( 0, count( $testroot->getChild( 3 )->getChild( 1 )->getChildren() ) ); |
||
| 742 | } |
||
| 743 | |||
| 744 | |||
| 745 | public function testMoveNode5() |
||
| 746 | { |
||
| 747 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 748 | $root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
||
| 749 | |||
| 750 | $nodeid = $root->getChild( 1 )->getChild( 0 )->getId(); |
||
| 751 | $oldparentid = $root->getChild( 1 )->getId(); |
||
| 752 | $newparentid = $root->getChild( 2 )->getId(); |
||
| 753 | $refnodeid = null; |
||
| 754 | |||
| 755 | $manager->moveNode( (string) $nodeid, $oldparentid, $newparentid, $refnodeid ); |
||
| 756 | |||
| 757 | $testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
||
| 758 | |||
| 759 | $this->assertEquals( 0, $testroot->level ); |
||
| 760 | $this->assertEquals( 1, $testroot->left ); |
||
| 761 | $this->assertEquals( 18, $testroot->right ); |
||
| 762 | $this->assertEquals( 3, count( $testroot->getChildren() ) ); |
||
| 763 | |||
| 764 | $this->assertEquals( 1, $testroot->getChild( 0 )->level ); |
||
| 765 | $this->assertEquals( 2, $testroot->getChild( 0 )->left ); |
||
| 766 | $this->assertEquals( 7, $testroot->getChild( 0 )->right ); |
||
| 767 | $this->assertEquals( 1, count( $testroot->getChild( 0 )->getChildren() ) ); |
||
| 768 | |||
| 769 | $this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level ); |
||
| 770 | $this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left ); |
||
| 771 | $this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right ); |
||
| 772 | $this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
||
| 773 | |||
| 774 | $this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level ); |
||
| 775 | $this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left ); |
||
| 776 | $this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right ); |
||
| 777 | $this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
||
| 778 | |||
| 779 | $this->assertEquals( 1, $testroot->getChild( 1 )->level ); |
||
| 780 | $this->assertEquals( 8, $testroot->getChild( 1 )->left ); |
||
| 781 | $this->assertEquals( 9, $testroot->getChild( 1 )->right ); |
||
| 782 | $this->assertEquals( 0, count( $testroot->getChild( 1 )->getChildren() ) ); |
||
| 783 | |||
| 784 | $this->assertEquals( 1, $testroot->getChild( 2 )->level ); |
||
| 785 | $this->assertEquals( 10, $testroot->getChild( 2 )->left ); |
||
| 786 | $this->assertEquals( 17, $testroot->getChild( 2 )->right ); |
||
| 787 | $this->assertEquals( 1, count( $testroot->getChild( 2 )->getChildren() ) ); |
||
| 788 | |||
| 789 | $this->assertEquals( 2, $testroot->getChild( 2 )->getChild( 0 )->level ); |
||
| 790 | $this->assertEquals( 11, $testroot->getChild( 2 )->getChild( 0 )->left ); |
||
| 791 | $this->assertEquals( 16, $testroot->getChild( 2 )->getChild( 0 )->right ); |
||
| 792 | $this->assertEquals( 2, count( $testroot->getChild( 2 )->getChild( 0 )->getChildren() ) ); |
||
| 793 | |||
| 794 | $this->assertEquals( 3, $testroot->getChild( 2 )->getChild( 0 )->getChild( 0 )->level ); |
||
| 795 | $this->assertEquals( 12, $testroot->getChild( 2 )->getChild( 0 )->getChild( 0 )->left ); |
||
| 796 | $this->assertEquals( 13, $testroot->getChild( 2 )->getChild( 0 )->getChild( 0 )->right ); |
||
| 797 | $this->assertEquals( 0, count( $testroot->getChild( 2 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
||
| 798 | |||
| 799 | $this->assertEquals( 3, $testroot->getChild( 2 )->getChild( 0 )->getChild( 1 )->level ); |
||
| 800 | $this->assertEquals( 14, $testroot->getChild( 2 )->getChild( 0 )->getChild( 1 )->left ); |
||
| 801 | $this->assertEquals( 15, $testroot->getChild( 2 )->getChild( 0 )->getChild( 1 )->right ); |
||
| 802 | $this->assertEquals( 0, count( $testroot->getChild( 2 )->getChild( 0 )->getChild( 1 )->getChildren() ) ); |
||
| 803 | } |
||
| 804 | |||
| 805 | |||
| 806 | public function testMoveNode6() |
||
| 875 | } |
||
| 876 | |||
| 877 | |||
| 878 | public function testMoveNode7() |
||
| 879 | { |
||
| 880 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 881 | $root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
||
| 882 | |||
| 883 | $nodeid = $root->getChild( 1 )->getChild( 0 )->getId(); |
||
| 884 | $oldparentid = $root->getChild( 1 )->getId(); |
||
| 885 | $newparentid = $root->getId(); |
||
| 886 | $refnodeid = $root->getChild( 1 )->getId(); |
||
| 887 | |||
| 888 | $manager->moveNode( (string) $nodeid, $oldparentid, $newparentid, $refnodeid ); |
||
| 889 | |||
| 890 | |||
| 891 | $root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
||
| 892 | |||
| 893 | $nodeid = $root->getChild( 1 )->getId(); |
||
| 894 | $oldparentid = $root->getId(); |
||
| 895 | $newparentid = $root->getChild( 2 )->getId(); |
||
| 896 | $refnodeid = null; |
||
| 897 | |||
| 898 | $manager->moveNode( $nodeid, $oldparentid, $newparentid, $refnodeid ); |
||
| 899 | |||
| 900 | |||
| 901 | $testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
||
| 902 | |||
| 903 | $this->assertEquals( 0, $testroot->level ); |
||
| 904 | $this->assertEquals( 1, $testroot->left ); |
||
| 905 | $this->assertEquals( 18, $testroot->right ); |
||
| 906 | $this->assertEquals( 3, count( $testroot->getChildren() ) ); |
||
| 907 | |||
| 908 | $this->assertEquals( 1, $testroot->getChild( 0 )->level ); |
||
| 909 | $this->assertEquals( 2, $testroot->getChild( 0 )->left ); |
||
| 910 | $this->assertEquals( 7, $testroot->getChild( 0 )->right ); |
||
| 911 | $this->assertEquals( 1, count( $testroot->getChild( 0 )->getChildren() ) ); |
||
| 912 | |||
| 913 | $this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level ); |
||
| 914 | $this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left ); |
||
| 915 | $this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right ); |
||
| 916 | $this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
||
| 917 | |||
| 918 | $this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level ); |
||
| 919 | $this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left ); |
||
| 920 | $this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right ); |
||
| 921 | $this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
||
| 922 | |||
| 923 | $this->assertEquals( 1, $testroot->getChild( 1 )->level ); |
||
| 924 | $this->assertEquals( 8, $testroot->getChild( 1 )->left ); |
||
| 925 | $this->assertEquals( 15, $testroot->getChild( 1 )->right ); |
||
| 926 | $this->assertEquals( 1, count( $testroot->getChild( 1 )->getChildren() ) ); |
||
| 927 | |||
| 928 | $this->assertEquals( 2, $testroot->getChild( 1 )->getChild( 0 )->level ); |
||
| 929 | $this->assertEquals( 9, $testroot->getChild( 1 )->getChild( 0 )->left ); |
||
| 930 | $this->assertEquals( 14, $testroot->getChild( 1 )->getChild( 0 )->right ); |
||
| 931 | $this->assertEquals( 2, count( $testroot->getChild( 1 )->getChild( 0 )->getChildren() ) ); |
||
| 932 | |||
| 933 | $this->assertEquals( 3, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->level ); |
||
| 934 | $this->assertEquals( 10, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->left ); |
||
| 935 | $this->assertEquals( 11, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->right ); |
||
| 936 | $this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->getChildren() ) ); |
||
| 937 | |||
| 938 | $this->assertEquals( 3, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->level ); |
||
| 939 | $this->assertEquals( 12, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->left ); |
||
| 940 | $this->assertEquals( 13, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->right ); |
||
| 941 | $this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->getChildren() ) ); |
||
| 942 | |||
| 943 | $this->assertEquals( 1, $testroot->getChild( 2 )->level ); |
||
| 944 | $this->assertEquals( 16, $testroot->getChild( 2 )->left ); |
||
| 945 | $this->assertEquals( 17, $testroot->getChild( 2 )->right ); |
||
| 946 | $this->assertEquals( 0, count( $testroot->getChild( 2 )->getChildren() ) ); |
||
| 947 | } |
||
| 948 | |||
| 949 | |||
| 950 | public function testMoveNode8() |
||
| 1009 | } |
||
| 1010 | |||
| 1011 | |||
| 1012 | public function testMoveNodeException() |
||
| 1013 | { |
||
| 1014 | $this->config['sql']['move-left'] = ' |
||
| 1015 | UPDATE "mw_tree_test" |
||
| 1016 | SET nleft123 = nleft + ?, level = level + ? |
||
| 1017 | WHERE nleft >= ? AND nleft <= ? |
||
| 1018 | '; |
||
| 1019 | |||
| 1020 | $this->config['sql']['move-right'] = ' |
||
| 1021 | UPDATE "mw_tree_test" |
||
| 1022 | SET nright123 = nright + ? |
||
| 1023 | WHERE nright >= ? AND nright <= ? |
||
| 1024 | '; |
||
| 1025 | |||
| 1026 | |||
| 1027 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 1028 | |||
| 1029 | $root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
||
| 1030 | |||
| 1031 | $nodeid = $root->getChild( 1 )->getId(); |
||
| 1032 | $oldparentid = $root->getId(); |
||
| 1033 | $newparentid = $root->getChild( 0 )->getId(); |
||
| 1034 | |||
| 1035 | $this->expectException( \Aimeos\Base\DB\Exception::class ); |
||
| 1036 | $manager->moveNode( (string) $nodeid, $oldparentid, $newparentid ); |
||
| 1037 | } |
||
| 1038 | |||
| 1039 | |||
| 1040 | public function testSaveNode() |
||
| 1051 | } |
||
| 1052 | |||
| 1053 | |||
| 1054 | public function testSaveNodeException() |
||
| 1055 | { |
||
| 1056 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 1057 | $node = $manager->createNode(); |
||
| 1058 | |||
| 1059 | $this->expectException( \Aimeos\MW\Tree\Exception::class ); |
||
| 1060 | $manager->saveNode( $node ); |
||
| 1061 | } |
||
| 1062 | |||
| 1063 | |||
| 1064 | public function testSaveNodeException2() |
||
| 1065 | { |
||
| 1066 | $this->config['sql']['update'] = ' |
||
| 1067 | UPDATE "mw_tree_test" SET label123 = ?, status = ? WHERE id = ? |
||
| 1068 | '; |
||
| 1069 | |||
| 1070 | $manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() ); |
||
| 1071 | $root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); |
||
| 1072 | |||
| 1073 | $root->setLabel( 'rooot' ); |
||
| 1074 | |||
| 1075 | $this->expectException( \Aimeos\Base\DB\Exception::class ); |
||
| 1076 | $manager->saveNode( $root ); |
||
| 1077 | } |
||
| 1078 | |||
| 1079 | |||
| 1080 | public function testSetReadOnly() |
||
| 1091 | } |
||
| 1092 | |||
| 1093 | } |
||
| 1094 |
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.