|
|
@@ -90,6 +90,22 @@ class TreeBehaviorTest extends TestCase
|
|
|
'15:16 - 8:Link 8'
|
|
|
];
|
|
|
$this->assertMpttValues($expected, $table);
|
|
|
+
|
|
|
+ $table->removeBehavior('Tree');
|
|
|
+ $table->addBehavior('Tree', ['scope' => ['menu' => 'categories']]);
|
|
|
+ $expected = [
|
|
|
+ ' 1:10 - 9:electronics',
|
|
|
+ '_ 2: 9 - 10:televisions',
|
|
|
+ '__ 3: 4 - 11:tube',
|
|
|
+ '__ 5: 8 - 12:lcd',
|
|
|
+ '___ 6: 7 - 13:plasma',
|
|
|
+ '11:20 - 14:portable',
|
|
|
+ '_12:15 - 15:mp3',
|
|
|
+ '__13:14 - 16:flash',
|
|
|
+ '_16:17 - 17:cd',
|
|
|
+ '_18:19 - 18:radios'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -323,17 +339,49 @@ class TreeBehaviorTest extends TestCase
|
|
|
// top level, won't move
|
|
|
$node = $this->table->moveUp($table->get(1), 10);
|
|
|
$this->assertEquals(['lft' => 1, 'rght' => 10], $node->extract(['lft', 'rght']));
|
|
|
+ $expected = [
|
|
|
+ ' 1:10 - 1:Link 1',
|
|
|
+ '_ 2: 3 - 2:Link 2',
|
|
|
+ '_ 4: 9 - 3:Link 3',
|
|
|
+ '__ 5: 8 - 4:Link 4',
|
|
|
+ '___ 6: 7 - 5:Link 5',
|
|
|
+ '11:14 - 6:Link 6',
|
|
|
+ '_12:13 - 7:Link 7',
|
|
|
+ '15:16 - 8:Link 8'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $table);
|
|
|
|
|
|
// edge cases
|
|
|
$this->assertFalse($this->table->moveUp($table->get(1), 0));
|
|
|
$node = $this->table->moveUp($table->get(1), -10);
|
|
|
$this->assertEquals(['lft' => 1, 'rght' => 10], $node->extract(['lft', 'rght']));
|
|
|
+ $expected = [
|
|
|
+ ' 1:10 - 1:Link 1',
|
|
|
+ '_ 2: 3 - 2:Link 2',
|
|
|
+ '_ 4: 9 - 3:Link 3',
|
|
|
+ '__ 5: 8 - 4:Link 4',
|
|
|
+ '___ 6: 7 - 5:Link 5',
|
|
|
+ '11:14 - 6:Link 6',
|
|
|
+ '_12:13 - 7:Link 7',
|
|
|
+ '15:16 - 8:Link 8'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $table);
|
|
|
|
|
|
// move inner node
|
|
|
$node = $table->moveUp($table->get(3), 1);
|
|
|
$nodes = $table->find('children', ['for' => 1])->all();
|
|
|
- $this->assertEquals([3, 4, 5, 2], $nodes->extract('id')->toArray());
|
|
|
$this->assertEquals(['lft' => 2, 'rght' => 7], $node->extract(['lft', 'rght']));
|
|
|
+ $expected = [
|
|
|
+ ' 1:10 - 1:Link 1',
|
|
|
+ '_ 2: 7 - 3:Link 3',
|
|
|
+ '__ 3: 6 - 4:Link 4',
|
|
|
+ '___ 4: 5 - 5:Link 5',
|
|
|
+ '_ 8: 9 - 2:Link 2',
|
|
|
+ '11:14 - 6:Link 6',
|
|
|
+ '_12:13 - 7:Link 7',
|
|
|
+ '15:16 - 8:Link 8'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -347,6 +395,17 @@ class TreeBehaviorTest extends TestCase
|
|
|
$table->addBehavior('Tree', ['scope' => ['menu' => 'main-menu']]);
|
|
|
$node = $table->moveUp($table->get(5), 1);
|
|
|
$this->assertEquals(['lft' => 6, 'rght' => 7], $node->extract(['lft', 'rght']));
|
|
|
+ $expected = [
|
|
|
+ ' 1:10 - 1:Link 1',
|
|
|
+ '_ 2: 3 - 2:Link 2',
|
|
|
+ '_ 4: 9 - 3:Link 3',
|
|
|
+ '__ 5: 8 - 4:Link 4',
|
|
|
+ '___ 6: 7 - 5:Link 5',
|
|
|
+ '11:14 - 6:Link 6',
|
|
|
+ '_12:13 - 7:Link 7',
|
|
|
+ '15:16 - 8:Link 8'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -359,16 +418,17 @@ class TreeBehaviorTest extends TestCase
|
|
|
$table = TableRegistry::get('MenuLinkTrees');
|
|
|
$table->addBehavior('Tree', ['scope' => ['menu' => 'main-menu']]);
|
|
|
$node = $table->moveUp($table->get(8), true);
|
|
|
- $this->assertEquals(['lft' => 1, 'rght' => 2], $node->extract(['lft', 'rght']));
|
|
|
- $nodes = $table->find()
|
|
|
- ->select(['id'])
|
|
|
- ->where(function ($exp) {
|
|
|
- return $exp->isNull('parent_id');
|
|
|
- })
|
|
|
- ->where(['menu' => 'main-menu'])
|
|
|
- ->order(['lft' => 'ASC'])
|
|
|
- ->all();
|
|
|
- $this->assertEquals([8, 1, 6], $nodes->extract('id')->toArray());
|
|
|
+ $expected = [
|
|
|
+ ' 1: 2 - 8:Link 8',
|
|
|
+ ' 3:12 - 1:Link 1',
|
|
|
+ '_ 4: 5 - 2:Link 2',
|
|
|
+ '_ 6:11 - 3:Link 3',
|
|
|
+ '__ 7:10 - 4:Link 4',
|
|
|
+ '___ 8: 9 - 5:Link 5',
|
|
|
+ '13:16 - 6:Link 6',
|
|
|
+ '_14:15 - 7:Link 7'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -385,15 +445,17 @@ class TreeBehaviorTest extends TestCase
|
|
|
$node->unsetProperty('rght');
|
|
|
$node = $table->moveUp($node, true);
|
|
|
$this->assertEquals(['lft' => 1, 'rght' => 2], $node->extract(['lft', 'rght']));
|
|
|
- $nodes = $table->find()
|
|
|
- ->select(['id'])
|
|
|
- ->where(function ($exp) {
|
|
|
- return $exp->isNull('parent_id');
|
|
|
- })
|
|
|
- ->where(['menu' => 'main-menu'])
|
|
|
- ->order(['lft' => 'ASC'])
|
|
|
- ->all();
|
|
|
- $this->assertEquals([8, 1, 6], $nodes->extract('id')->toArray());
|
|
|
+ $expected = [
|
|
|
+ ' 1: 2 - 8:Link 8',
|
|
|
+ ' 3:12 - 1:Link 1',
|
|
|
+ '_ 4: 5 - 2:Link 2',
|
|
|
+ '_ 6:11 - 3:Link 3',
|
|
|
+ '__ 7:10 - 4:Link 4',
|
|
|
+ '___ 8: 9 - 5:Link 5',
|
|
|
+ '13:16 - 6:Link 6',
|
|
|
+ '_14:15 - 7:Link 7'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -406,17 +468,48 @@ class TreeBehaviorTest extends TestCase
|
|
|
$table = TableRegistry::get('MenuLinkTrees');
|
|
|
$table->addBehavior('Tree', ['scope' => ['menu' => 'main-menu']]);
|
|
|
// latest node, won't move
|
|
|
- $node = $this->table->moveDown($table->get(8), 10);
|
|
|
- $this->assertEquals(['lft' => 21, 'rght' => 22], $node->extract(['lft', 'rght']));
|
|
|
+ $node = $table->moveDown($table->get(8), 10);
|
|
|
+ $this->assertEquals(['lft' => 15, 'rght' => 16], $node->extract(['lft', 'rght']));
|
|
|
+ $expected = [
|
|
|
+ ' 1:10 - 1:Link 1',
|
|
|
+ '_ 2: 3 - 2:Link 2',
|
|
|
+ '_ 4: 9 - 3:Link 3',
|
|
|
+ '__ 5: 8 - 4:Link 4',
|
|
|
+ '___ 6: 7 - 5:Link 5',
|
|
|
+ '11:14 - 6:Link 6',
|
|
|
+ '_12:13 - 7:Link 7',
|
|
|
+ '15:16 - 8:Link 8'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $table);
|
|
|
|
|
|
// edge cases
|
|
|
$this->assertFalse($this->table->moveDown($table->get(8), 0));
|
|
|
+ $expected = [
|
|
|
+ ' 1:10 - 1:Link 1',
|
|
|
+ '_ 2: 3 - 2:Link 2',
|
|
|
+ '_ 4: 9 - 3:Link 3',
|
|
|
+ '__ 5: 8 - 4:Link 4',
|
|
|
+ '___ 6: 7 - 5:Link 5',
|
|
|
+ '11:14 - 6:Link 6',
|
|
|
+ '_12:13 - 7:Link 7',
|
|
|
+ '15:16 - 8:Link 8'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $table);
|
|
|
|
|
|
// move inner node
|
|
|
$node = $table->moveDown($table->get(2), 1);
|
|
|
- $nodes = $table->find('children', ['for' => 1])->all();
|
|
|
- $this->assertEquals([3, 4, 5, 2], $nodes->extract('id')->toArray());
|
|
|
- $this->assertEquals(['lft' => 11, 'rght' => 12], $node->extract(['lft', 'rght']));
|
|
|
+ $this->assertEquals(['lft' => 8, 'rght' => 9], $node->extract(['lft', 'rght']));
|
|
|
+ $expected = [
|
|
|
+ ' 1:10 - 1:Link 1',
|
|
|
+ '_ 2: 7 - 3:Link 3',
|
|
|
+ '__ 3: 6 - 4:Link 4',
|
|
|
+ '___ 4: 5 - 5:Link 5',
|
|
|
+ '_ 8: 9 - 2:Link 2',
|
|
|
+ '11:14 - 6:Link 6',
|
|
|
+ '_12:13 - 7:Link 7',
|
|
|
+ '15:16 - 8:Link 8'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -430,6 +523,17 @@ class TreeBehaviorTest extends TestCase
|
|
|
$table->addBehavior('Tree', ['scope' => ['menu' => 'main-menu']]);
|
|
|
$node = $table->moveDown($table->get(5), 1);
|
|
|
$this->assertEquals(['lft' => 6, 'rght' => 7], $node->extract(['lft', 'rght']));
|
|
|
+ $expected = [
|
|
|
+ ' 1:10 - 1:Link 1',
|
|
|
+ '_ 2: 3 - 2:Link 2',
|
|
|
+ '_ 4: 9 - 3:Link 3',
|
|
|
+ '__ 5: 8 - 4:Link 4',
|
|
|
+ '___ 6: 7 - 5:Link 5',
|
|
|
+ '11:14 - 6:Link 6',
|
|
|
+ '_12:13 - 7:Link 7',
|
|
|
+ '15:16 - 8:Link 8'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -443,15 +547,17 @@ class TreeBehaviorTest extends TestCase
|
|
|
$table->addBehavior('Tree', ['scope' => ['menu' => 'main-menu']]);
|
|
|
$node = $table->moveDown($table->get(1), true);
|
|
|
$this->assertEquals(['lft' => 7, 'rght' => 16], $node->extract(['lft', 'rght']));
|
|
|
- $nodes = $table->find()
|
|
|
- ->select(['id'])
|
|
|
- ->where(function ($exp) {
|
|
|
- return $exp->isNull('parent_id');
|
|
|
- })
|
|
|
- ->where(['menu' => 'main-menu'])
|
|
|
- ->order(['lft' => 'ASC'])
|
|
|
- ->all();
|
|
|
- $this->assertEquals([6, 8, 1], $nodes->extract('id')->toArray());
|
|
|
+ $expected = [
|
|
|
+ ' 1: 4 - 6:Link 6',
|
|
|
+ '_ 2: 3 - 7:Link 7',
|
|
|
+ ' 5: 6 - 8:Link 8',
|
|
|
+ ' 7:16 - 1:Link 1',
|
|
|
+ '_ 8: 9 - 2:Link 2',
|
|
|
+ '_10:15 - 3:Link 3',
|
|
|
+ '__11:14 - 4:Link 4',
|
|
|
+ '___12:13 - 5:Link 5'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -468,27 +574,37 @@ class TreeBehaviorTest extends TestCase
|
|
|
$node->unsetProperty('rght');
|
|
|
$node = $table->moveDown($node, true);
|
|
|
$this->assertEquals(['lft' => 7, 'rght' => 16], $node->extract(['lft', 'rght']));
|
|
|
- $nodes = $table->find()
|
|
|
- ->select(['id'])
|
|
|
- ->where(function ($exp) {
|
|
|
- return $exp->isNull('parent_id');
|
|
|
- })
|
|
|
- ->where(['menu' => 'main-menu'])
|
|
|
- ->order(['lft' => 'ASC'])
|
|
|
- ->all();
|
|
|
- $this->assertEquals([6, 8, 1], $nodes->extract('id')->toArray());
|
|
|
+ $expected = [
|
|
|
+ ' 1: 4 - 6:Link 6',
|
|
|
+ '_ 2: 3 - 7:Link 7',
|
|
|
+ ' 5: 6 - 8:Link 8',
|
|
|
+ ' 7:16 - 1:Link 1',
|
|
|
+ '_ 8: 9 - 2:Link 2',
|
|
|
+ '_10:15 - 3:Link 3',
|
|
|
+ '__11:14 - 4:Link 4',
|
|
|
+ '___12:13 - 5:Link 5'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $table);
|
|
|
}
|
|
|
|
|
|
public function testMoveDownMultiplePositions()
|
|
|
{
|
|
|
$node = $this->table->moveDown($this->table->get(3), 2);
|
|
|
- $result = $this->table
|
|
|
- ->find('children', ['for' => 2, 'direct' => true])
|
|
|
- ->order(['lft' => 'ASC'])
|
|
|
- ->extract('id')
|
|
|
- ->toArray();
|
|
|
-
|
|
|
- $this->assertEquals([4,5,3], $result);
|
|
|
+ $this->assertEquals(['lft' => 7, 'rght' => 8], $node->extract(['lft', 'rght']));
|
|
|
+ $expected = [
|
|
|
+ ' 1:20 - 1:electronics',
|
|
|
+ '_ 2: 9 - 2:televisions',
|
|
|
+ '__ 3: 4 - 4:lcd',
|
|
|
+ '__ 5: 6 - 5:plasma',
|
|
|
+ '__ 7: 8 - 3:tube',
|
|
|
+ '_10:19 - 6:portable',
|
|
|
+ '__11:14 - 7:mp3',
|
|
|
+ '___12:13 - 8:flash',
|
|
|
+ '__15:16 - 9:cd',
|
|
|
+ '__17:18 - 10:radios',
|
|
|
+ '21:22 - 11:alien hardware'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $this->table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -499,11 +615,23 @@ class TreeBehaviorTest extends TestCase
|
|
|
public function testRecover()
|
|
|
{
|
|
|
$table = $this->table;
|
|
|
- $expected = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
$table->updateAll(['lft' => null, 'rght' => null], []);
|
|
|
$table->recover();
|
|
|
- $result = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $this->assertEquals($expected, $result);
|
|
|
+
|
|
|
+ $expected = [
|
|
|
+ ' 1:20 - 1:electronics',
|
|
|
+ '_ 2: 9 - 2:televisions',
|
|
|
+ '__ 3: 4 - 3:tube',
|
|
|
+ '__ 5: 6 - 4:lcd',
|
|
|
+ '__ 7: 8 - 5:plasma',
|
|
|
+ '_10:19 - 6:portable',
|
|
|
+ '__11:14 - 7:mp3',
|
|
|
+ '___12:13 - 8:flash',
|
|
|
+ '__15:16 - 9:cd',
|
|
|
+ '__17:18 - 10:radios',
|
|
|
+ '21:22 - 11:alien hardware'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $this->table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -521,27 +649,37 @@ class TreeBehaviorTest extends TestCase
|
|
|
->hydrate(false)
|
|
|
->toArray();
|
|
|
|
|
|
- $expected2 = $table->find()
|
|
|
- ->where(['menu' => 'categories'])
|
|
|
- ->order('lft')
|
|
|
- ->hydrate(false)
|
|
|
- ->toArray();
|
|
|
|
|
|
$table->updateAll(['lft' => null, 'rght' => null], ['menu' => 'main-menu']);
|
|
|
$table->recover();
|
|
|
- $result = $table->find()
|
|
|
- ->where(['menu' => 'main-menu'])
|
|
|
- ->order('lft')
|
|
|
- ->hydrate(false)
|
|
|
- ->toArray();
|
|
|
- $this->assertEquals($expected, $result);
|
|
|
|
|
|
- $result2 = $table->find()
|
|
|
- ->where(['menu' => 'categories'])
|
|
|
- ->order('lft')
|
|
|
- ->hydrate(false)
|
|
|
- ->toArray();
|
|
|
- $this->assertEquals($expected2, $result2);
|
|
|
+ $expected = [
|
|
|
+ ' 1:10 - 1:Link 1',
|
|
|
+ '_ 2: 3 - 2:Link 2',
|
|
|
+ '_ 4: 9 - 3:Link 3',
|
|
|
+ '__ 5: 8 - 4:Link 4',
|
|
|
+ '___ 6: 7 - 5:Link 5',
|
|
|
+ '11:14 - 6:Link 6',
|
|
|
+ '_12:13 - 7:Link 7',
|
|
|
+ '15:16 - 8:Link 8'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $table);
|
|
|
+
|
|
|
+ $table->removeBehavior('Tree');
|
|
|
+ $table->addBehavior('Tree', ['scope' => ['menu' => 'categories']]);
|
|
|
+ $expected = [
|
|
|
+ ' 1:10 - 9:electronics',
|
|
|
+ '_ 2: 9 - 10:televisions',
|
|
|
+ '__ 3: 4 - 11:tube',
|
|
|
+ '__ 5: 8 - 12:lcd',
|
|
|
+ '___ 6: 7 - 13:plasma',
|
|
|
+ '11:20 - 14:portable',
|
|
|
+ '_12:15 - 15:mp3',
|
|
|
+ '__13:14 - 16:flash',
|
|
|
+ '_16:17 - 17:cd',
|
|
|
+ '_18:19 - 18:radios'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -556,14 +694,25 @@ class TreeBehaviorTest extends TestCase
|
|
|
['name' => 'New Orphan', 'parent_id' => null, 'level' => null],
|
|
|
['markNew' => true]
|
|
|
);
|
|
|
- $expected = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
$this->assertSame($entity, $table->save($entity));
|
|
|
$this->assertEquals(23, $entity->lft);
|
|
|
$this->assertEquals(24, $entity->rght);
|
|
|
|
|
|
- $expected[] = $entity->toArray();
|
|
|
- $results = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $this->assertEquals($expected, $results);
|
|
|
+ $expected = [
|
|
|
+ ' 1:20 - 1:electronics',
|
|
|
+ '_ 2: 9 - 2:televisions',
|
|
|
+ '__ 3: 4 - 3:tube',
|
|
|
+ '__ 5: 6 - 4:lcd',
|
|
|
+ '__ 7: 8 - 5:plasma',
|
|
|
+ '_10:19 - 6:portable',
|
|
|
+ '__11:14 - 7:mp3',
|
|
|
+ '___12:13 - 8:flash',
|
|
|
+ '__15:16 - 9:cd',
|
|
|
+ '__17:18 - 10:radios',
|
|
|
+ '21:22 - 11:alien hardware',
|
|
|
+ '23:24 - 12:New Orphan',
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $this->table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -582,10 +731,21 @@ class TreeBehaviorTest extends TestCase
|
|
|
$this->assertEquals(20, $entity->lft);
|
|
|
$this->assertEquals(21, $entity->rght);
|
|
|
|
|
|
- $result = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $table->recover();
|
|
|
- $expected = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $this->assertEquals($expected, $result);
|
|
|
+ $expected = [
|
|
|
+ ' 1:22 - 1:electronics',
|
|
|
+ '_ 2: 9 - 2:televisions',
|
|
|
+ '__ 3: 4 - 3:tube',
|
|
|
+ '__ 5: 6 - 4:lcd',
|
|
|
+ '__ 7: 8 - 5:plasma',
|
|
|
+ '_10:19 - 6:portable',
|
|
|
+ '__11:14 - 7:mp3',
|
|
|
+ '___12:13 - 8:flash',
|
|
|
+ '__15:16 - 9:cd',
|
|
|
+ '__17:18 - 10:radios',
|
|
|
+ '_20:21 - 12:laptops',
|
|
|
+ '23:24 - 11:alien hardware',
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $this->table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -604,10 +764,21 @@ class TreeBehaviorTest extends TestCase
|
|
|
$this->assertEquals(9, $entity->lft);
|
|
|
$this->assertEquals(10, $entity->rght);
|
|
|
|
|
|
- $results = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $table->recover();
|
|
|
- $expected = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $this->assertEquals($expected, $results);
|
|
|
+ $expected = [
|
|
|
+ ' 1:22 - 1:electronics',
|
|
|
+ '_ 2:11 - 2:televisions',
|
|
|
+ '__ 3: 4 - 3:tube',
|
|
|
+ '__ 5: 6 - 4:lcd',
|
|
|
+ '__ 7: 8 - 5:plasma',
|
|
|
+ '__ 9:10 - 12:laptops',
|
|
|
+ '_12:21 - 6:portable',
|
|
|
+ '__13:16 - 7:mp3',
|
|
|
+ '___14:15 - 8:flash',
|
|
|
+ '__17:18 - 9:cd',
|
|
|
+ '__19:20 - 10:radios',
|
|
|
+ '23:24 - 11:alien hardware'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $this->table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -626,16 +797,15 @@ class TreeBehaviorTest extends TestCase
|
|
|
|
|
|
$expected = [
|
|
|
' 1:20 - 1:electronics',
|
|
|
- '_ 2: 7 - 2:televisions',
|
|
|
- '__ 3: 4 - 3:tube',
|
|
|
- '__ 5: 6 - 4:lcd',
|
|
|
- '_ 8:19 - 6:portable',
|
|
|
- '__ 9:12 - 7:mp3',
|
|
|
- '___10:11 - 8:flash',
|
|
|
- '__13:14 - 9:cd',
|
|
|
- '__15:16 - 10:radios',
|
|
|
- '__17:18 - 5:plasma',
|
|
|
- '___16:17 - 4:lcd',
|
|
|
+ '_ 2:19 - 6:portable',
|
|
|
+ '__ 3: 6 - 7:mp3',
|
|
|
+ '___ 4: 5 - 8:flash',
|
|
|
+ '__ 7: 8 - 9:cd',
|
|
|
+ '__ 9:10 - 10:radios',
|
|
|
+ '__11:18 - 2:televisions',
|
|
|
+ '___12:13 - 3:tube',
|
|
|
+ '___14:15 - 4:lcd',
|
|
|
+ '___16:17 - 5:plasma',
|
|
|
'21:22 - 11:alien hardware'
|
|
|
];
|
|
|
$this->assertMpttValues($expected, $table);
|
|
|
@@ -655,10 +825,20 @@ class TreeBehaviorTest extends TestCase
|
|
|
$this->assertEquals(9, $entity->lft);
|
|
|
$this->assertEquals(18, $entity->rght);
|
|
|
|
|
|
- $result = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $table->recover();
|
|
|
- $expected = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $this->assertEquals($expected, $result);
|
|
|
+ $expected = [
|
|
|
+ ' 1:20 - 1:electronics',
|
|
|
+ '_ 2:19 - 2:televisions',
|
|
|
+ '__ 3: 4 - 3:tube',
|
|
|
+ '__ 5: 6 - 4:lcd',
|
|
|
+ '__ 7: 8 - 5:plasma',
|
|
|
+ '__ 9:18 - 6:portable',
|
|
|
+ '___10:13 - 7:mp3',
|
|
|
+ '____11:12 - 8:flash',
|
|
|
+ '___14:15 - 9:cd',
|
|
|
+ '___16:17 - 10:radios',
|
|
|
+ '21:22 - 11:alien hardware'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $this->table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -675,10 +855,20 @@ class TreeBehaviorTest extends TestCase
|
|
|
$this->assertEquals(9, $entity->lft);
|
|
|
$this->assertEquals(10, $entity->rght);
|
|
|
|
|
|
- $result = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $table->recover();
|
|
|
- $expected = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $this->assertEquals($expected, $result);
|
|
|
+ $expected = [
|
|
|
+ ' 1:20 - 1:electronics',
|
|
|
+ '_ 2:11 - 2:televisions',
|
|
|
+ '__ 3: 4 - 3:tube',
|
|
|
+ '__ 5: 6 - 4:lcd',
|
|
|
+ '__ 7: 8 - 5:plasma',
|
|
|
+ '__ 9:10 - 10:radios',
|
|
|
+ '_12:19 - 6:portable',
|
|
|
+ '__13:16 - 7:mp3',
|
|
|
+ '___14:15 - 8:flash',
|
|
|
+ '__17:18 - 9:cd',
|
|
|
+ '21:22 - 11:alien hardware'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $this->table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -729,10 +919,20 @@ class TreeBehaviorTest extends TestCase
|
|
|
$this->assertEquals(9, $entity->lft);
|
|
|
$this->assertEquals(18, $entity->rght);
|
|
|
|
|
|
- $result = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $table->recover();
|
|
|
- $expected = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $this->assertEquals($expected, $result);
|
|
|
+ $expected = [
|
|
|
+ ' 1:20 - 1:electronics',
|
|
|
+ '_ 2:19 - 2:televisions',
|
|
|
+ '__ 3: 4 - 3:tube',
|
|
|
+ '__ 5: 6 - 4:lcd',
|
|
|
+ '__ 7: 8 - 5:plasma',
|
|
|
+ '__ 9:18 - 6:portable',
|
|
|
+ '___10:13 - 7:mp3',
|
|
|
+ '____11:12 - 8:flash',
|
|
|
+ '___14:15 - 9:cd',
|
|
|
+ '___16:17 - 10:radios',
|
|
|
+ '21:22 - 11:alien hardware'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $this->table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -749,8 +949,19 @@ class TreeBehaviorTest extends TestCase
|
|
|
$this->assertEquals(15, $entity->lft);
|
|
|
$this->assertEquals(22, $entity->rght);
|
|
|
|
|
|
- $result = $table->find()->order('lft')->hydrate(false);
|
|
|
- $expected = [1, 6, 7, 8, 9, 10, 11, 2, 3, 4, 5];
|
|
|
+ $expected = [
|
|
|
+ ' 1:12 - 1:electronics',
|
|
|
+ '_ 2:11 - 6:portable',
|
|
|
+ '__ 3: 6 - 7:mp3',
|
|
|
+ '___ 4: 5 - 8:flash',
|
|
|
+ '__ 7: 8 - 9:cd',
|
|
|
+ '__ 9:10 - 10:radios',
|
|
|
+ '13:14 - 11:alien hardware',
|
|
|
+ '15:22 - 2:televisions',
|
|
|
+ '_16:17 - 3:tube',
|
|
|
+ '_18:19 - 4:lcd',
|
|
|
+ '_20:21 - 5:plasma'
|
|
|
+ ];
|
|
|
$this->assertMpttValues($expected, $table);
|
|
|
}
|
|
|
|
|
|
@@ -770,8 +981,19 @@ class TreeBehaviorTest extends TestCase
|
|
|
$this->assertEquals(15, $entity->lft);
|
|
|
$this->assertEquals(22, $entity->rght);
|
|
|
|
|
|
- $result = $table->find()->order('lft')->hydrate(false);
|
|
|
- $expected = [1, 6, 7, 8, 9, 10, 11, 2, 3, 4, 5];
|
|
|
+ $expected = [
|
|
|
+ ' 1:12 - 1:electronics',
|
|
|
+ '_ 2:11 - 6:portable',
|
|
|
+ '__ 3: 6 - 7:mp3',
|
|
|
+ '___ 4: 5 - 8:flash',
|
|
|
+ '__ 7: 8 - 9:cd',
|
|
|
+ '__ 9:10 - 10:radios',
|
|
|
+ '13:14 - 11:alien hardware',
|
|
|
+ '15:22 - 2:televisions',
|
|
|
+ '_16:17 - 3:tube',
|
|
|
+ '_18:19 - 4:lcd',
|
|
|
+ '_20:21 - 5:plasma'
|
|
|
+ ];
|
|
|
$this->assertMpttValues($expected, $table);
|
|
|
}
|
|
|
|
|
|
@@ -800,10 +1022,20 @@ class TreeBehaviorTest extends TestCase
|
|
|
$table = $this->table;
|
|
|
$entity = $table->get(4);
|
|
|
$this->assertTrue($table->delete($entity));
|
|
|
- $result = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $table->recover();
|
|
|
- $expected = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $this->assertEquals($expected, $result);
|
|
|
+
|
|
|
+ $expected = [
|
|
|
+ ' 1:18 - 1:electronics',
|
|
|
+ '_ 2: 7 - 2:televisions',
|
|
|
+ '__ 3: 4 - 3:tube',
|
|
|
+ '__ 5: 6 - 5:plasma',
|
|
|
+ '_ 8:17 - 6:portable',
|
|
|
+ '__ 9:12 - 7:mp3',
|
|
|
+ '___10:11 - 8:flash',
|
|
|
+ '__13:14 - 9:cd',
|
|
|
+ '__15:16 - 10:radios',
|
|
|
+ '19:20 - 11:alien hardware'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $this->table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -816,10 +1048,16 @@ class TreeBehaviorTest extends TestCase
|
|
|
$table = $this->table;
|
|
|
$entity = $table->get(6);
|
|
|
$this->assertTrue($table->delete($entity));
|
|
|
- $result = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $table->recover();
|
|
|
- $expected = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $this->assertEquals($expected, $result);
|
|
|
+
|
|
|
+ $expected = [
|
|
|
+ ' 1:10 - 1:electronics',
|
|
|
+ '_ 2: 9 - 2:televisions',
|
|
|
+ '__ 3: 4 - 3:tube',
|
|
|
+ '__ 5: 6 - 4:lcd',
|
|
|
+ '__ 7: 8 - 5:plasma',
|
|
|
+ '11:12 - 11:alien hardware'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $this->table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -832,10 +1070,11 @@ class TreeBehaviorTest extends TestCase
|
|
|
$table = $this->table;
|
|
|
$entity = $table->get(1);
|
|
|
$this->assertTrue($table->delete($entity));
|
|
|
- $result = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $table->recover();
|
|
|
- $expected = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $this->assertEquals($expected, $result);
|
|
|
+
|
|
|
+ $expected = [
|
|
|
+ ' 1: 2 - 11:alien hardware'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $this->table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -850,10 +1089,11 @@ class TreeBehaviorTest extends TestCase
|
|
|
$entity->unsetProperty('lft');
|
|
|
$entity->unsetProperty('rght');
|
|
|
$this->assertTrue($table->delete($entity));
|
|
|
- $result = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $table->recover();
|
|
|
- $expected = $table->find()->order('lft')->hydrate(false)->toArray();
|
|
|
- $this->assertEquals($expected, $result);
|
|
|
+
|
|
|
+ $expected = [
|
|
|
+ ' 1: 2 - 11:alien hardware'
|
|
|
+ ];
|
|
|
+ $this->assertMpttValues($expected, $this->table);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1070,7 +1310,7 @@ class TreeBehaviorTest extends TestCase
|
|
|
$displayField = $table->displayField();
|
|
|
|
|
|
$options = [
|
|
|
- 'valuePath' => function($item, $key, $iterator) use ($primaryKey, $displayField) {
|
|
|
+ 'valuePath' => function ($item, $key, $iterator) use ($primaryKey, $displayField) {
|
|
|
return sprintf(
|
|
|
'%s:%s - %s:%s',
|
|
|
str_pad($item->lft, 2, ' ', STR_PAD_LEFT),
|