Passed
Push — master ( ba0f9d...7b9ad2 )
by Aimeos
39:34 queued 23:42
created

testConstructorNoDatabaseManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 2
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Aimeos\MW\Tree\Manager;
4
5
6
class DBNestedSetTest extends \PHPUnit\Framework\TestCase
7
{
8
	private static $dbm;
9
	private $config;
10
11
12
	public static function setUpBeforeClass() : 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 testConstructorNoConfig()
155
	{
156
		$this->expectException( \Aimeos\MW\Tree\Exception::class );
157
		new \Aimeos\MW\Tree\Manager\DBNestedSet( [], self::$dbm->get() );
158
	}
159
160
161
	public function testConstructorNoSqlConfig()
162
	{
163
		unset( $this->config['sql'] );
164
165
		$this->expectException( \Aimeos\MW\Tree\Exception::class );
166
		new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
167
	}
168
169
170
	public function testConstructorMissingSqlConfig()
171
	{
172
		unset( $this->config['sql']['newid'] );
173
174
		$this->expectException( \Aimeos\MW\Tree\Exception::class );
175
		new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
176
	}
177
178
179
	public function testConstructorMissingSearchConfig()
180
	{
181
		unset( $this->config['search']['id'] );
182
183
		$this->expectException( \Aimeos\MW\Tree\Exception::class );
184
		new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
185
	}
186
187
188
	public function testGetSearchAttributes()
189
	{
190
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
191
192
		foreach( $manager->getSearchAttributes() as $attribute ) {
193
			$this->assertInstanceOf( \Aimeos\Base\Criteria\Attribute\Iface::class, $attribute );
194
		}
195
	}
196
197
198
	public function testIsReadOnly()
199
	{
200
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
201
202
		$this->assertFalse( $manager->isReadOnly() );
203
	}
204
205
206
	public function testCreateSearch()
207
	{
208
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
209
210
		$this->assertInstanceOf( \Aimeos\Base\Criteria\Iface::class, $manager->createSearch() );
211
	}
212
213
214
	public function testSearchNodes()
215
	{
216
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
217
		$search = $manager->createSearch();
218
219
220
		$search->setConditions( $search->compare( '==', 'tree.level', 1 ) );
221
		$nodes = $manager->searchNodes( $search );
222
223
		$this->assertEquals( 3, count( $nodes ) );
224
225
		foreach( $nodes as $node ) {
226
			$this->assertInstanceOf( \Aimeos\MW\Tree\Node\Iface::class, $node );
227
		}
228
229
230
		if( ( $node = reset( $nodes ) ) === false ) {
231
			throw new \RuntimeException( 'No node found' );
232
		}
233
234
		$search->setConditions( $search->compare( '==', 'tree.level', 3 ) );
235
		$nodes = $manager->searchNodes( $search, $node->getId() );
236
237
		$this->assertEquals( 1, count( $nodes ) );
238
239
		foreach( $nodes as $node ) {
240
			$this->assertInstanceOf( \Aimeos\MW\Tree\Node\Iface::class, $node );
241
		}
242
	}
243
244
245
	public function testSearchException()
246
	{
247
		$this->config['sql']['search'] = '
248
			SELECT "id", "label", "code", "status", "level", "domain" as "base", "left" AS "left", "right" AS "right"
249
			FROM "mw_tree_test"
250
			WHERE domain123 = ? AND nleft >= ? AND nright <= ? AND :cond
251
		';
252
253
		$this->expectException( \Aimeos\Base\DB\Exception::class );
254
255
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
256
		$manager->searchNodes( $manager->createSearch() );
257
	}
258
259
260
	public function testDeleteNode()
261
	{
262
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
263
264
		$search = $manager->createSearch();
265
		$search->setConditions( $search->compare( '==', 'tree.label', 'l2n2' ) );
266
		$nodes = $manager->searchNodes( $search );
267
		$this->assertEquals( 1, count( $nodes ) );
268
269
		$this->assertInstanceOf( \Aimeos\MW\Tree\Manager\Iface::class, $manager->deleteNode( reset( $nodes )->getId() ) );
270
271
		$search = $manager->createSearch();
272
		$nodes = $manager->searchNodes( $search );
273
		$this->assertEquals( 7, count( $nodes ) );
274
	}
275
276
277
	public function testDeleteNodeException()
278
	{
279
		$this->config['sql']['search'] = '
280
			DELETE FROM "mw_tree_test" WHERE domain = ? AND nleft12 >= ? AND nright <= ?
281
		';
282
283
		$this->expectException( \Aimeos\Base\DB\Exception::class );
284
285
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
286
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE );
287
		$manager->deleteNode( $root->getId() );
288
	}
289
290
291
	public function testGetNode()
292
	{
293
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
294
		$search = $manager->createSearch();
295
296
		$node = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE, $search );
297
298
		$this->assertEquals( 0, $node->level );
299
		$this->assertEquals( 0, count( $node->getChildren() ) );
300
	}
301
302
303
	public function testGetNodeList()
304
	{
305
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
306
307
		$node = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE );
308
		$node = $manager->getNode( $node->getId(), \Aimeos\MW\Tree\Manager\Base::LEVEL_LIST );
309
310
		$this->assertEquals( 3, count( $node->getChildren() ) );
311
		$this->assertEquals( 0, count( $node->getChild( 0 )->getChildren() ) );
312
		$this->assertEquals( 0, count( $node->getChild( 1 )->getChildren() ) );
313
	}
314
315
316
	public function testGetNodeTree()
317
	{
318
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
319
320
		$node = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE );
321
		$node = $manager->getNode( $node->getId(), \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
322
323
		$this->assertEquals( 3, count( $node->getChildren() ) );
324
		$this->assertEquals( 1, count( $node->getChild( 0 )->getChildren() ) );
325
		$this->assertEquals( 1, count( $node->getChild( 0 )->getChild( 0 )->getChildren() ) );
326
		$this->assertEquals( 1, count( $node->getChild( 1 )->getChildren() ) );
327
		$this->assertEquals( 2, count( $node->getChild( 1 )->getChild( 0 )->getChildren() ) );
328
		$this->assertEquals( 0, count( $node->getChild( 2 )->getChildren() ) );
329
	}
330
331
332
	public function testGetNodeTreeCondition()
333
	{
334
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
335
		$filter = $manager->createSearch()->add( 'tree.status', '==', 1 );
336
337
		$node = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE, $filter );
338
339
		$this->assertEquals( 3, count( $node->getChildren() ) );
340
		$this->assertEquals( 0, count( $node->getChild( 0 )->getChildren() ) );
341
		$this->assertEquals( 1, count( $node->getChild( 1 )->getChildren() ) );
342
		$this->assertEquals( 2, count( $node->getChild( 1 )->getChild( 0 )->getChildren() ) );
343
		$this->assertEquals( 0, count( $node->getChild( 2 )->getChildren() ) );
344
	}
345
346
347
	public function testGetPath()
348
	{
349
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
350
351
		$nodes = [];
352
		$nodes[0] = $manager->getNode();
353
		$nodes[1] = $nodes[0]->getChild( 1 );
354
		$nodes[2] = $nodes[1]->getChild( 0 );
355
		$nodes[3] = $nodes[2]->getChild( 1 );
356
357
		$path = $manager->getPath( (string) $nodes[3]->getId() );
358
359
		foreach( $nodes as $node )
360
		{
361
			if( ( $actual = array_shift( $path ) ) === null ) {
362
				throw new \RuntimeException( 'Not enough nodes in path' );
363
			}
364
365
			$this->assertEquals( $node->getId(), $actual->getId() );
366
		}
367
	}
368
369
370
	public function testGetLevelFromConstantException()
371
	{
372
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
373
374
		$this->expectException( \Aimeos\MW\Tree\Exception::class );
375
		$manager->getNode( null, 0 );
376
	}
377
378
379
	public function testInsertNode()
380
	{
381
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
382
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE );
383
384
		$newNode = $manager->createNode();
385
		$newNode->setLabel( 'l1n4' );
386
		$manager->insertNode( $newNode, $root->getId() );
387
388
		$root = $manager->getNode( $root->getId(), \Aimeos\MW\Tree\Manager\Base::LEVEL_LIST );
389
		$this->assertEquals( 4, count( $root->getChildren() ) );
390
		$this->assertEquals( 'l1n4', $root->getChild( 3 )->getLabel() );
391
		$this->assertEquals( $newNode->getId(), $root->getChild( 3 )->getId() );
392
393
		$search = $manager->createSearch();
394
		$search->setConditions( $search->compare( '==', 'tree.label', 'l1n3' ) );
395
		$nodes = $manager->searchNodes( $search );
396
		$this->assertEquals( 1, count( $nodes ) );
397
398
		$newNode->setLabel( 'new l1n3' );
399
		$newNode = $manager->insertNode( $newNode, $root->getId(), reset( $nodes )->getId() );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $root->getId() targeting Aimeos\MW\Tree\Node\Iface::getId() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
400
401
		$root = $manager->getNode( $root->getId(), \Aimeos\MW\Tree\Manager\Base::LEVEL_LIST );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $root->getId() targeting Aimeos\MW\Tree\Node\Iface::getId() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
402
		$this->assertInstanceOf( \Aimeos\MW\Tree\Node\Iface::class, $newNode );
403
		$this->assertEquals( 5, count( $root->getChildren() ) );
404
		$this->assertEquals( 'l1n2', $root->getChild( 1 )->getLabel() );
405
		$this->assertEquals( 'new l1n3', $root->getChild( 2 )->getLabel() );
406
		$this->assertEquals( 'l1n3', $root->getChild( 3 )->getLabel() );
407
		$this->assertEquals( 'l1n4', $root->getChild( 4 )->getLabel() );
408
	}
409
410
411
	public function testInsertNodeException()
412
	{
413
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
414
		$newNode = $manager->createNode();
415
416
		$this->expectException( \Aimeos\MW\Tree\Exception::class );
417
		$manager->insertNode( $newNode, -1 );
418
	}
419
420
421
	public function testInsertNodeRoot()
422
	{
423
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
424
425
		$newNode = $manager->createNode();
426
		$newNode->setCode( 'root3' );
427
		$newNode->setLabel( 'Root 3' );
428
429
		$this->assertInstanceOf( \Aimeos\MW\Tree\Node\Iface::class, $manager->insertNode( $newNode ) );
430
431
		$root = $manager->getNode( $newNode->getId() );
432
		$this->assertEquals( 'Root 3', $root->getLabel() );
433
		$this->assertEquals( 21, $root->left );
434
		$this->assertEquals( 22, $root->right );
435
	}
436
437
438
	public function testMoveNodeNoParent()
439
	{
440
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
441
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
442
443
		$nodeid = $root->getChild( 0 )->getChild( 0 )->getChild( 0 )->getId();
444
		$oldparentid = $root->getChild( 0 )->getChild( 0 )->getId();
445
446
		$result = $manager->moveNode( (string) $nodeid, $oldparentid, null );
447
		$this->assertInstanceOf( \Aimeos\MW\Tree\Manager\Iface::class, $result );
448
449
		$testroot = $manager->getNode( $nodeid, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
450
451
		$this->assertEquals( 0, $testroot->level );
452
		$this->assertEquals( 19, $testroot->left );
453
		$this->assertEquals( 20, $testroot->right );
454
		$this->assertEquals( 0, count( $testroot->getChildren() ) );
455
	}
456
457
458
	public function testMoveNodeSameParent()
459
	{
460
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
461
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
462
463
		$nodeid = $root->getChild( 0 )->getId();
464
		$oldparentid = $root->getId();
465
466
		$manager->moveNode( (string) $nodeid, $oldparentid, $oldparentid );
467
		$manager->moveNode( (string) $nodeid, $oldparentid, $oldparentid );
468
469
		$testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
470
471
		$this->assertEquals( 'l1n1', $testroot->getChild( 2 )->label );
472
		$this->assertEquals( 1, $testroot->getChild( 2 )->level );
473
		$this->assertEquals( 12, $testroot->getChild( 2 )->left );
474
		$this->assertEquals( 17, $testroot->getChild( 2 )->right );
475
		$this->assertEquals( 1, count( $testroot->getChild( 2 )->getChildren() ) );
476
	}
477
478
479
	public function testMoveNode1()
480
	{
481
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
482
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
483
484
		$nodeid = $root->getChild( 0 )->getChild( 0 )->getChild( 0 )->getId();
485
		$oldparentid = $root->getChild( 0 )->getChild( 0 )->getId();
486
		$newparentid = $root->getChild( 0 )->getId();
487
		$refnodeid = null;
488
489
		$manager->moveNode( (string) $nodeid, $oldparentid, $newparentid, $refnodeid );
490
491
		$testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
492
493
		$this->assertEquals( 0, $testroot->level );
494
		$this->assertEquals( 1, $testroot->left );
495
		$this->assertEquals( 18, $testroot->right );
496
		$this->assertEquals( 3, count( $testroot->getChildren() ) );
497
498
		$this->assertEquals( 1, $testroot->getChild( 0 )->level );
499
		$this->assertEquals( 2, $testroot->getChild( 0 )->left );
500
		$this->assertEquals( 7, $testroot->getChild( 0 )->right );
501
		$this->assertEquals( 2, count( $testroot->getChild( 0 )->getChildren() ) );
502
503
		$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level );
504
		$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left );
505
		$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->right );
506
		$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) );
507
508
		$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 1 )->level );
509
		$this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 1 )->left );
510
		$this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 1 )->right );
511
		$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 1 )->getChildren() ) );
512
513
		$this->assertEquals( 1, $testroot->getChild( 1 )->level );
514
		$this->assertEquals( 8, $testroot->getChild( 1 )->left );
515
		$this->assertEquals( 15, $testroot->getChild( 1 )->right );
516
		$this->assertEquals( 1, count( $testroot->getChild( 1 )->getChildren() ) );
517
518
		$this->assertEquals( 2, $testroot->getChild( 1 )->getChild( 0 )->level );
519
		$this->assertEquals( 9, $testroot->getChild( 1 )->getChild( 0 )->left );
520
		$this->assertEquals( 14, $testroot->getChild( 1 )->getChild( 0 )->right );
521
		$this->assertEquals( 2, count( $testroot->getChild( 1 )->getChild( 0 )->getChildren() ) );
522
523
		$this->assertEquals( 3, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->level );
524
		$this->assertEquals( 10, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->left );
525
		$this->assertEquals( 11, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->right );
526
		$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->getChildren() ) );
527
528
		$this->assertEquals( 3, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->level );
529
		$this->assertEquals( 12, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->left );
530
		$this->assertEquals( 13, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->right );
531
		$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->getChildren() ) );
532
533
		$this->assertEquals( 1, $testroot->getChild( 2 )->level );
534
		$this->assertEquals( 16, $testroot->getChild( 2 )->left );
535
		$this->assertEquals( 17, $testroot->getChild( 2 )->right );
536
		$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChildren() ) );
537
	}
538
539
540
	public function testMoveNode2()
541
	{
542
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
543
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
544
545
		$nodeid = $root->getChild( 1 )->getChild( 0 )->getId();
546
		$oldparentid = $root->getChild( 1 )->getId();
547
		$newparentid = $root->getId();
548
		$refnodeid = $root->getChild( 1 )->getId();
549
550
		$manager->moveNode( (string) $nodeid, $oldparentid, $newparentid, $refnodeid );
551
552
		$testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
553
554
		$this->assertEquals( 0, $testroot->level );
555
		$this->assertEquals( 1, $testroot->left );
556
		$this->assertEquals( 18, $testroot->right );
557
		$this->assertEquals( 4, count( $testroot->getChildren() ) );
558
559
		$this->assertEquals( 1, $testroot->getChild( 0 )->level );
560
		$this->assertEquals( 2, $testroot->getChild( 0 )->left );
561
		$this->assertEquals( 7, $testroot->getChild( 0 )->right );
562
		$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChildren() ) );
563
564
		$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level );
565
		$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left );
566
		$this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right );
567
		$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) );
568
569
		$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level );
570
		$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left );
571
		$this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right );
572
		$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) );
573
574
		$this->assertEquals( 1, $testroot->getChild( 1 )->level );
575
		$this->assertEquals( 8, $testroot->getChild( 1 )->left );
576
		$this->assertEquals( 13, $testroot->getChild( 1 )->right );
577
		$this->assertEquals( 2, count( $testroot->getChild( 1 )->getChildren() ) );
578
579
		$this->assertEquals( 2, $testroot->getChild( 1 )->getChild( 0 )->level );
580
		$this->assertEquals( 9, $testroot->getChild( 1 )->getChild( 0 )->left );
581
		$this->assertEquals( 10, $testroot->getChild( 1 )->getChild( 0 )->right );
582
		$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChildren() ) );
583
584
		$this->assertEquals( 2, $testroot->getChild( 1 )->getChild( 1 )->level );
585
		$this->assertEquals( 11, $testroot->getChild( 1 )->getChild( 1 )->left );
586
		$this->assertEquals( 12, $testroot->getChild( 1 )->getChild( 1 )->right );
587
		$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 1 )->getChildren() ) );
588
589
		$this->assertEquals( 1, $testroot->getChild( 2 )->level );
590
		$this->assertEquals( 14, $testroot->getChild( 2 )->left );
591
		$this->assertEquals( 15, $testroot->getChild( 2 )->right );
592
		$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChildren() ) );
593
594
		$this->assertEquals( 1, $testroot->getChild( 3 )->level );
595
		$this->assertEquals( 16, $testroot->getChild( 3 )->left );
596
		$this->assertEquals( 17, $testroot->getChild( 3 )->right );
597
		$this->assertEquals( 0, count( $testroot->getChild( 3 )->getChildren() ) );
598
	}
599
600
601
	public function testMoveNode3()
602
	{
603
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
604
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
605
606
		$nodeid = $root->getChild( 1 )->getChild( 0 )->getId();
607
		$oldparentid = $root->getChild( 1 )->getId();
608
		$newparentid = $root->getId();
609
		$refnodeid = $root->getChild( 2 )->getId();
610
611
		$manager->moveNode( (string) $nodeid, $oldparentid, $newparentid, $refnodeid );
612
613
		$testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
614
615
		$this->assertEquals( 0, $testroot->level );
616
		$this->assertEquals( 1, $testroot->left );
617
		$this->assertEquals( 18, $testroot->right );
618
		$this->assertEquals( 4, count( $testroot->getChildren() ) );
619
620
		$this->assertEquals( 1, $testroot->getChild( 0 )->level );
621
		$this->assertEquals( 2, $testroot->getChild( 0 )->left );
622
		$this->assertEquals( 7, $testroot->getChild( 0 )->right );
623
		$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChildren() ) );
624
625
		$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level );
626
		$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left );
627
		$this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right );
628
		$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) );
629
630
		$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level );
631
		$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left );
632
		$this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right );
633
		$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) );
634
635
		$this->assertEquals( 1, $testroot->getChild( 1 )->level );
636
		$this->assertEquals( 8, $testroot->getChild( 1 )->left );
637
		$this->assertEquals( 9, $testroot->getChild( 1 )->right );
638
		$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChildren() ) );
639
640
		$this->assertEquals( 1, $testroot->getChild( 2 )->level );
641
		$this->assertEquals( 10, $testroot->getChild( 2 )->left );
642
		$this->assertEquals( 15, $testroot->getChild( 2 )->right );
643
		$this->assertEquals( 2, count( $testroot->getChild( 2 )->getChildren() ) );
644
645
		$this->assertEquals( 2, $testroot->getChild( 2 )->getChild( 0 )->level );
646
		$this->assertEquals( 11, $testroot->getChild( 2 )->getChild( 0 )->left );
647
		$this->assertEquals( 12, $testroot->getChild( 2 )->getChild( 0 )->right );
648
		$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChild( 0 )->getChildren() ) );
649
650
		$this->assertEquals( 2, $testroot->getChild( 2 )->getChild( 1 )->level );
651
		$this->assertEquals( 13, $testroot->getChild( 2 )->getChild( 1 )->left );
652
		$this->assertEquals( 14, $testroot->getChild( 2 )->getChild( 1 )->right );
653
		$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChild( 1 )->getChildren() ) );
654
655
		$this->assertEquals( 1, $testroot->getChild( 3 )->level );
656
		$this->assertEquals( 16, $testroot->getChild( 3 )->left );
657
		$this->assertEquals( 17, $testroot->getChild( 3 )->right );
658
		$this->assertEquals( 0, count( $testroot->getChild( 3 )->getChildren() ) );
659
	}
660
661
662
	public function testMoveNode4()
663
	{
664
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
665
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
666
667
		$nodeid = $root->getChild( 1 )->getChild( 0 )->getId();
668
		$oldparentid = $root->getChild( 1 )->getId();
669
		$newparentid = $root->getId();
670
		$refnodeid = null;
671
672
		$manager->moveNode( (string) $nodeid, $oldparentid, $newparentid, $refnodeid );
673
674
		$testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
675
676
		$this->assertEquals( 0, $testroot->level );
677
		$this->assertEquals( 1, $testroot->left );
678
		$this->assertEquals( 18, $testroot->right );
679
		$this->assertEquals( 4, count( $testroot->getChildren() ) );
680
681
		$this->assertEquals( 1, $testroot->getChild( 0 )->level );
682
		$this->assertEquals( 2, $testroot->getChild( 0 )->left );
683
		$this->assertEquals( 7, $testroot->getChild( 0 )->right );
684
		$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChildren() ) );
685
686
		$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level );
687
		$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left );
688
		$this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right );
689
		$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) );
690
691
		$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level );
692
		$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left );
693
		$this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right );
694
		$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) );
695
696
		$this->assertEquals( 1, $testroot->getChild( 1 )->level );
697
		$this->assertEquals( 8, $testroot->getChild( 1 )->left );
698
		$this->assertEquals( 9, $testroot->getChild( 1 )->right );
699
		$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChildren() ) );
700
701
		$this->assertEquals( 1, $testroot->getChild( 2 )->level );
702
		$this->assertEquals( 10, $testroot->getChild( 2 )->left );
703
		$this->assertEquals( 11, $testroot->getChild( 2 )->right );
704
		$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChildren() ) );
705
706
		$this->assertEquals( 1, $testroot->getChild( 3 )->level );
707
		$this->assertEquals( 12, $testroot->getChild( 3 )->left );
708
		$this->assertEquals( 17, $testroot->getChild( 3 )->right );
709
		$this->assertEquals( 2, count( $testroot->getChild( 3 )->getChildren() ) );
710
711
		$this->assertEquals( 2, $testroot->getChild( 3 )->getChild( 0 )->level );
712
		$this->assertEquals( 13, $testroot->getChild( 3 )->getChild( 0 )->left );
713
		$this->assertEquals( 14, $testroot->getChild( 3 )->getChild( 0 )->right );
714
		$this->assertEquals( 0, count( $testroot->getChild( 3 )->getChild( 0 )->getChildren() ) );
715
716
		$this->assertEquals( 2, $testroot->getChild( 3 )->getChild( 1 )->level );
717
		$this->assertEquals( 15, $testroot->getChild( 3 )->getChild( 1 )->left );
718
		$this->assertEquals( 16, $testroot->getChild( 3 )->getChild( 1 )->right );
719
		$this->assertEquals( 0, count( $testroot->getChild( 3 )->getChild( 1 )->getChildren() ) );
720
	}
721
722
723
	public function testMoveNode5()
724
	{
725
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
726
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
727
728
		$nodeid = $root->getChild( 1 )->getChild( 0 )->getId();
729
		$oldparentid = $root->getChild( 1 )->getId();
730
		$newparentid = $root->getChild( 2 )->getId();
731
		$refnodeid = null;
732
733
		$manager->moveNode( (string) $nodeid, $oldparentid, $newparentid, $refnodeid );
734
735
		$testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
736
737
		$this->assertEquals( 0, $testroot->level );
738
		$this->assertEquals( 1, $testroot->left );
739
		$this->assertEquals( 18, $testroot->right );
740
		$this->assertEquals( 3, count( $testroot->getChildren() ) );
741
742
		$this->assertEquals( 1, $testroot->getChild( 0 )->level );
743
		$this->assertEquals( 2, $testroot->getChild( 0 )->left );
744
		$this->assertEquals( 7, $testroot->getChild( 0 )->right );
745
		$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChildren() ) );
746
747
		$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level );
748
		$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left );
749
		$this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right );
750
		$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) );
751
752
		$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level );
753
		$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left );
754
		$this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right );
755
		$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) );
756
757
		$this->assertEquals( 1, $testroot->getChild( 1 )->level );
758
		$this->assertEquals( 8, $testroot->getChild( 1 )->left );
759
		$this->assertEquals( 9, $testroot->getChild( 1 )->right );
760
		$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChildren() ) );
761
762
		$this->assertEquals( 1, $testroot->getChild( 2 )->level );
763
		$this->assertEquals( 10, $testroot->getChild( 2 )->left );
764
		$this->assertEquals( 17, $testroot->getChild( 2 )->right );
765
		$this->assertEquals( 1, count( $testroot->getChild( 2 )->getChildren() ) );
766
767
		$this->assertEquals( 2, $testroot->getChild( 2 )->getChild( 0 )->level );
768
		$this->assertEquals( 11, $testroot->getChild( 2 )->getChild( 0 )->left );
769
		$this->assertEquals( 16, $testroot->getChild( 2 )->getChild( 0 )->right );
770
		$this->assertEquals( 2, count( $testroot->getChild( 2 )->getChild( 0 )->getChildren() ) );
771
772
		$this->assertEquals( 3, $testroot->getChild( 2 )->getChild( 0 )->getChild( 0 )->level );
773
		$this->assertEquals( 12, $testroot->getChild( 2 )->getChild( 0 )->getChild( 0 )->left );
774
		$this->assertEquals( 13, $testroot->getChild( 2 )->getChild( 0 )->getChild( 0 )->right );
775
		$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChild( 0 )->getChild( 0 )->getChildren() ) );
776
777
		$this->assertEquals( 3, $testroot->getChild( 2 )->getChild( 0 )->getChild( 1 )->level );
778
		$this->assertEquals( 14, $testroot->getChild( 2 )->getChild( 0 )->getChild( 1 )->left );
779
		$this->assertEquals( 15, $testroot->getChild( 2 )->getChild( 0 )->getChild( 1 )->right );
780
		$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChild( 0 )->getChild( 1 )->getChildren() ) );
781
	}
782
783
784
	public function testMoveNode6()
785
	{
786
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
787
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
788
789
		$nodeid = $root->getChild( 1 )->getChild( 0 )->getId();
790
		$oldparentid = $root->getChild( 1 )->getId();
791
		$newparentid = $root->getId();
792
		$refnodeid = $root->getChild( 2 )->getId();
793
794
		$manager->moveNode( (string) $nodeid, $oldparentid, $newparentid, $refnodeid );
795
796
797
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
798
799
		$nodeid = $root->getChild( 2 )->getId();
800
		$oldparentid = $root->getId();
801
		$newparentid = $root->getChild( 1 )->getId();
802
		$refnodeid = null;
803
804
		$manager->moveNode( $nodeid, $oldparentid, $newparentid, $refnodeid );
0 ignored issues
show
Bug introduced by
It seems like $nodeid can also be of type null; however, parameter $id of Aimeos\MW\Tree\Manager\DBNestedSet::moveNode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

804
		$manager->moveNode( /** @scrutinizer ignore-type */ $nodeid, $oldparentid, $newparentid, $refnodeid );
Loading history...
805
806
807
		$testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
808
809
		$this->assertEquals( 0, $testroot->level );
810
		$this->assertEquals( 1, $testroot->left );
811
		$this->assertEquals( 18, $testroot->right );
812
		$this->assertEquals( 3, count( $testroot->getChildren() ) );
813
814
		$this->assertEquals( 1, $testroot->getChild( 0 )->level );
815
		$this->assertEquals( 2, $testroot->getChild( 0 )->left );
816
		$this->assertEquals( 7, $testroot->getChild( 0 )->right );
817
		$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChildren() ) );
818
819
		$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level );
820
		$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left );
821
		$this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right );
822
		$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) );
823
824
		$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level );
825
		$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left );
826
		$this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right );
827
		$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) );
828
829
		$this->assertEquals( 1, $testroot->getChild( 1 )->level );
830
		$this->assertEquals( 8, $testroot->getChild( 1 )->left );
831
		$this->assertEquals( 15, $testroot->getChild( 1 )->right );
832
		$this->assertEquals( 1, count( $testroot->getChild( 1 )->getChildren() ) );
833
834
		$this->assertEquals( 2, $testroot->getChild( 1 )->getChild( 0 )->level );
835
		$this->assertEquals( 9, $testroot->getChild( 1 )->getChild( 0 )->left );
836
		$this->assertEquals( 14, $testroot->getChild( 1 )->getChild( 0 )->right );
837
		$this->assertEquals( 2, count( $testroot->getChild( 1 )->getChild( 0 )->getChildren() ) );
838
839
		$this->assertEquals( 3, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->level );
840
		$this->assertEquals( 10, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->left );
841
		$this->assertEquals( 11, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->right );
842
		$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->getChildren() ) );
843
844
		$this->assertEquals( 3, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->level );
845
		$this->assertEquals( 12, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->left );
846
		$this->assertEquals( 13, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->right );
847
		$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->getChildren() ) );
848
849
		$this->assertEquals( 1, $testroot->getChild( 2 )->level );
850
		$this->assertEquals( 16, $testroot->getChild( 2 )->left );
851
		$this->assertEquals( 17, $testroot->getChild( 2 )->right );
852
		$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChildren() ) );
853
	}
854
855
856
	public function testMoveNode7()
857
	{
858
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
859
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
860
861
		$nodeid = $root->getChild( 1 )->getChild( 0 )->getId();
862
		$oldparentid = $root->getChild( 1 )->getId();
863
		$newparentid = $root->getId();
864
		$refnodeid = $root->getChild( 1 )->getId();
865
866
		$manager->moveNode( (string) $nodeid, $oldparentid, $newparentid, $refnodeid );
867
868
869
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
870
871
		$nodeid = $root->getChild( 1 )->getId();
872
		$oldparentid = $root->getId();
873
		$newparentid = $root->getChild( 2 )->getId();
874
		$refnodeid = null;
875
876
		$manager->moveNode( $nodeid, $oldparentid, $newparentid, $refnodeid );
0 ignored issues
show
Bug introduced by
It seems like $nodeid can also be of type null; however, parameter $id of Aimeos\MW\Tree\Manager\DBNestedSet::moveNode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

876
		$manager->moveNode( /** @scrutinizer ignore-type */ $nodeid, $oldparentid, $newparentid, $refnodeid );
Loading history...
877
878
879
		$testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
880
881
		$this->assertEquals( 0, $testroot->level );
882
		$this->assertEquals( 1, $testroot->left );
883
		$this->assertEquals( 18, $testroot->right );
884
		$this->assertEquals( 3, count( $testroot->getChildren() ) );
885
886
		$this->assertEquals( 1, $testroot->getChild( 0 )->level );
887
		$this->assertEquals( 2, $testroot->getChild( 0 )->left );
888
		$this->assertEquals( 7, $testroot->getChild( 0 )->right );
889
		$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChildren() ) );
890
891
		$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level );
892
		$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left );
893
		$this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right );
894
		$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) );
895
896
		$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level );
897
		$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left );
898
		$this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right );
899
		$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) );
900
901
		$this->assertEquals( 1, $testroot->getChild( 1 )->level );
902
		$this->assertEquals( 8, $testroot->getChild( 1 )->left );
903
		$this->assertEquals( 15, $testroot->getChild( 1 )->right );
904
		$this->assertEquals( 1, count( $testroot->getChild( 1 )->getChildren() ) );
905
906
		$this->assertEquals( 2, $testroot->getChild( 1 )->getChild( 0 )->level );
907
		$this->assertEquals( 9, $testroot->getChild( 1 )->getChild( 0 )->left );
908
		$this->assertEquals( 14, $testroot->getChild( 1 )->getChild( 0 )->right );
909
		$this->assertEquals( 2, count( $testroot->getChild( 1 )->getChild( 0 )->getChildren() ) );
910
911
		$this->assertEquals( 3, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->level );
912
		$this->assertEquals( 10, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->left );
913
		$this->assertEquals( 11, $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->right );
914
		$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChild( 0 )->getChildren() ) );
915
916
		$this->assertEquals( 3, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->level );
917
		$this->assertEquals( 12, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->left );
918
		$this->assertEquals( 13, $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->right );
919
		$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChild( 0 )->getChild( 1 )->getChildren() ) );
920
921
		$this->assertEquals( 1, $testroot->getChild( 2 )->level );
922
		$this->assertEquals( 16, $testroot->getChild( 2 )->left );
923
		$this->assertEquals( 17, $testroot->getChild( 2 )->right );
924
		$this->assertEquals( 0, count( $testroot->getChild( 2 )->getChildren() ) );
925
	}
926
927
928
	public function testMoveNode8()
929
	{
930
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
931
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
932
933
		$nodeid = $root->getChild( 1 )->getId();
934
		$oldparentid = $root->getId();
935
		$newparentid = $root->getChild( 0 )->getId();
936
		$refnodeid = null;
937
938
		$manager->moveNode( (string) $nodeid, $oldparentid, $newparentid, $refnodeid );
939
940
941
		$testroot = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
942
943
		$this->assertEquals( 0, $testroot->level );
944
		$this->assertEquals( 1, $testroot->left );
945
		$this->assertEquals( 18, $testroot->right );
946
		$this->assertEquals( 2, count( $testroot->getChildren() ) );
947
948
		$this->assertEquals( 1, $testroot->getChild( 0 )->level );
949
		$this->assertEquals( 2, $testroot->getChild( 0 )->left );
950
		$this->assertEquals( 15, $testroot->getChild( 0 )->right );
951
		$this->assertEquals( 2, count( $testroot->getChild( 0 )->getChildren() ) );
952
953
		$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 0 )->level );
954
		$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->left );
955
		$this->assertEquals( 6, $testroot->getChild( 0 )->getChild( 0 )->right );
956
		$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 0 )->getChildren() ) );
957
958
		$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->level );
959
		$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->left );
960
		$this->assertEquals( 5, $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->right );
961
		$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 0 )->getChild( 0 )->getChildren() ) );
962
963
		$this->assertEquals( 2, $testroot->getChild( 0 )->getChild( 1 )->level );
964
		$this->assertEquals( 7, $testroot->getChild( 0 )->getChild( 1 )->left );
965
		$this->assertEquals( 14, $testroot->getChild( 0 )->getChild( 1 )->right );
966
		$this->assertEquals( 1, count( $testroot->getChild( 0 )->getChild( 1 )->getChildren() ) );
967
968
		$this->assertEquals( 3, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->level );
969
		$this->assertEquals( 8, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->left );
970
		$this->assertEquals( 13, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->right );
971
		$this->assertEquals( 2, count( $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChildren() ) );
972
973
		$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChild( 0 )->level );
974
		$this->assertEquals( 9, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChild( 0 )->left );
975
		$this->assertEquals( 10, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChild( 0 )->right );
976
		$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChild( 0 )->getChildren() ) );
977
978
		$this->assertEquals( 4, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChild( 1 )->level );
979
		$this->assertEquals( 11, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChild( 1 )->left );
980
		$this->assertEquals( 12, $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChild( 1 )->right );
981
		$this->assertEquals( 0, count( $testroot->getChild( 0 )->getChild( 1 )->getChild( 0 )->getChild( 1 )->getChildren() ) );
982
983
		$this->assertEquals( 1, $testroot->getChild( 1 )->level );
984
		$this->assertEquals( 16, $testroot->getChild( 1 )->left );
985
		$this->assertEquals( 17, $testroot->getChild( 1 )->right );
986
		$this->assertEquals( 0, count( $testroot->getChild( 1 )->getChildren() ) );
987
	}
988
989
990
	public function testMoveNodeException()
991
	{
992
		$this->config['sql']['move-left'] = '
993
			UPDATE "mw_tree_test"
994
			SET nleft123 = nleft + ?, level = level + ?
995
			WHERE nleft >= ? AND nleft <= ?
996
		';
997
998
		$this->config['sql']['move-right'] = '
999
			UPDATE "mw_tree_test"
1000
			SET nright123 = nright + ?
1001
			WHERE nright >= ? AND nright <= ?
1002
		';
1003
1004
1005
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
1006
1007
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
1008
1009
		$nodeid = $root->getChild( 1 )->getId();
1010
		$oldparentid = $root->getId();
1011
		$newparentid = $root->getChild( 0 )->getId();
1012
1013
		$this->expectException( \Aimeos\Base\DB\Exception::class );
1014
		$manager->moveNode( (string) $nodeid, $oldparentid, $newparentid );
1015
	}
1016
1017
1018
	public function testSaveNode()
1019
	{
1020
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
1021
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE );
1022
1023
		$root->setLabel( 'rooot' );
1024
		$result = $manager->saveNode( $root );
1025
1026
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE );
1027
		$this->assertInstanceOf( \Aimeos\MW\Tree\Node\Iface::class, $result );
1028
		$this->assertEquals( 'rooot', $root->getLabel() );
1029
	}
1030
1031
1032
	public function testSaveNodeException()
1033
	{
1034
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
1035
		$node = $manager->createNode();
1036
1037
		$this->expectException( \Aimeos\MW\Tree\Exception::class );
1038
		$manager->saveNode( $node );
1039
	}
1040
1041
1042
	public function testSaveNodeException2()
1043
	{
1044
		$this->config['sql']['update'] = '
1045
			UPDATE "mw_tree_test" SET label123 = ?, status = ? WHERE id = ?
1046
		';
1047
1048
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
1049
		$root = $manager->getNode( null, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE );
1050
1051
		$root->setLabel( 'rooot' );
1052
1053
		$this->expectException( \Aimeos\Base\DB\Exception::class );
1054
		$manager->saveNode( $root );
1055
	}
1056
1057
1058
	public function testSetReadOnly()
1059
	{
1060
		$class = new \ReflectionClass( \Aimeos\MW\Tree\Manager\DBNestedSet::class );
1061
		$method = $class->getMethod( 'setReadOnly' );
1062
		$method->setAccessible( true );
1063
1064
		$manager = new \Aimeos\MW\Tree\Manager\DBNestedSet( $this->config, self::$dbm->get() );
1065
1066
		$method->invokeArgs( $manager, [] );
1067
1068
		$this->assertTrue( $manager->isReadOnly() );
1069
	}
1070
1071
}
1072