| @@ 17-140 (lines=124) @@ | ||
| 14 | * @author PaulZi <[email protected]> |
|
| 15 | * @group AlNi |
|
| 16 | */ |
|
| 17 | class AlNiTest extends AutoTreeTraitTestCase |
|
| 18 | { |
|
| 19 | /** |
|
| 20 | * @inheritdoc |
|
| 21 | */ |
|
| 22 | public function getDataSet() |
|
| 23 | { |
|
| 24 | return new \PHPUnit_Extensions_Database_DataSet_ArrayDataSet(require(__DIR__ . '/data/data-ni.php')); |
|
| 25 | } |
|
| 26 | ||
| 27 | public function getModelClass() |
|
| 28 | { |
|
| 29 | return NodeAlNi::className(); |
|
| 30 | } |
|
| 31 | ||
| 32 | public function testMakeRootInsert() |
|
| 33 | { |
|
| 34 | $node = new NodeAlNi(['slug' => 'r']); |
|
| 35 | $this->assertTrue($node->makeRoot()->save()); |
|
| 36 | ||
| 37 | $node->refresh(); |
|
| 38 | $this->assertEquals(null, $node->parent_id); |
|
| 39 | $this->assertEquals(0, $node->lft); |
|
| 40 | $this->assertEquals(2147483647, $node->rgt); |
|
| 41 | $this->assertEquals(0, $node->depth); |
|
| 42 | } |
|
| 43 | ||
| 44 | public function testMakeRootUpdate() |
|
| 45 | { |
|
| 46 | $node = NodeAlNi::findOne(9); |
|
| 47 | $this->assertTrue($node->makeRoot()->save()); |
|
| 48 | ||
| 49 | $node->refresh(); |
|
| 50 | $this->assertEquals(null, $node->parent_id); |
|
| 51 | $this->assertEquals(0, $node->lft); |
|
| 52 | $this->assertEquals(2147483647, $node->rgt); |
|
| 53 | $this->assertEquals(0, $node->depth); |
|
| 54 | } |
|
| 55 | ||
| 56 | public function testPrependTo() |
|
| 57 | { |
|
| 58 | $node = new NodeAlNi(['slug' => 'new']); |
|
| 59 | $this->assertTrue($node->prependTo(NodeAlNi::findOne(1))->save()); |
|
| 60 | ||
| 61 | $node->refresh(); |
|
| 62 | $this->assertEquals(1, $node->parent_id); |
|
| 63 | $this->assertEquals(1, $node->lft); |
|
| 64 | $this->assertEquals(2, $node->rgt); |
|
| 65 | $this->assertEquals(1, $node->depth); |
|
| 66 | } |
|
| 67 | ||
| 68 | public function testPrependToAnotherTree() |
|
| 69 | { |
|
| 70 | $node = NodeAlNi::findOne(30); |
|
| 71 | $this->assertTrue($node->prependTo(NodeAlNi::findOne(4))->save()); |
|
| 72 | ||
| 73 | $node->refresh(); |
|
| 74 | $this->assertEquals(4, $node->parent_id); |
|
| 75 | $this->assertEquals(1091940810, $node->lft); |
|
| 76 | $this->assertEquals(1419523107, $node->rgt); |
|
| 77 | $this->assertEquals(2, $node->depth); |
|
| 78 | } |
|
| 79 | ||
| 80 | public function testAppendTo() |
|
| 81 | { |
|
| 82 | $node = NodeAlNi::findOne(10); |
|
| 83 | $this->assertTrue($node->appendTo(NodeAlNi::findOne(18))->save()); |
|
| 84 | ||
| 85 | $node->refresh(); |
|
| 86 | $this->assertEquals(18, $node->parent_id); |
|
| 87 | $this->assertEquals(1000013, $node->lft); |
|
| 88 | $this->assertEquals(1000024, $node->rgt); |
|
| 89 | $this->assertEquals(4, $node->depth); |
|
| 90 | } |
|
| 91 | ||
| 92 | public function testInsertBefore() |
|
| 93 | { |
|
| 94 | $node = new NodeAlNi(['slug' => 'new']); |
|
| 95 | $this->assertTrue($node->insertBefore(NodeAlNi::findOne(22))->save()); |
|
| 96 | ||
| 97 | $node->refresh(); |
|
| 98 | $this->assertEquals(9, $node->parent_id); |
|
| 99 | $this->assertEquals(300000005, $node->lft); |
|
| 100 | $this->assertEquals(300000006, $node->rgt); |
|
| 101 | $this->assertEquals(3, $node->depth); |
|
| 102 | } |
|
| 103 | ||
| 104 | public function testInsertAfter() |
|
| 105 | { |
|
| 106 | $node = NodeAlNi::findOne(32); |
|
| 107 | $this->assertTrue($node->insertAfter(NodeAlNi::findOne(30))->save()); |
|
| 108 | ||
| 109 | $node->refresh(); |
|
| 110 | $this->assertEquals(26, $node->parent_id); |
|
| 111 | $this->assertEquals(2147483644, $node->lft); |
|
| 112 | $this->assertEquals(2147483646, $node->rgt); |
|
| 113 | $this->assertEquals(1, $node->depth); |
|
| 114 | } |
|
| 115 | ||
| 116 | public function testInsertAfterAnotherTree() |
|
| 117 | { |
|
| 118 | $node = NodeAlNi::findOne(26); |
|
| 119 | $this->assertTrue($node->insertAfter(NodeAlNi::findOne(21))->save()); |
|
| 120 | ||
| 121 | $node->refresh(); |
|
| 122 | $this->assertEquals(9, $node->parent_id); |
|
| 123 | $this->assertEquals(1031907726, $node->lft); |
|
| 124 | $this->assertEquals(1784921473, $node->rgt); |
|
| 125 | $this->assertEquals(3, $node->depth); |
|
| 126 | } |
|
| 127 | ||
| 128 | public function testDelete() |
|
| 129 | { |
|
| 130 | $this->assertEquals(1, NodeAlNi::findOne(30)->delete()); |
|
| 131 | $this->assertEquals(null, NodeAlNi::findOne(30)); |
|
| 132 | } |
|
| 133 | ||
| 134 | public function testDeleteWithChildren() |
|
| 135 | { |
|
| 136 | $this->assertEquals(10, NodeAlNi::findOne(4)->deleteWithChildren()); |
|
| 137 | $this->assertEquals(null, NodeAlNi::findOne(24)); |
|
| 138 | $this->assertEquals(15, NodeAlNi::findOne(1)->deleteWithChildren()); |
|
| 139 | } |
|
| 140 | } |
|
| @@ 17-132 (lines=116) @@ | ||
| 14 | * @author PaulZi <[email protected]> |
|
| 15 | * @group AlNs |
|
| 16 | */ |
|
| 17 | class AlNsTest extends AutoTreeTraitTestCase |
|
| 18 | { |
|
| 19 | public function getModelClass() |
|
| 20 | { |
|
| 21 | return NodeAlNs::className(); |
|
| 22 | } |
|
| 23 | ||
| 24 | public function testMakeRootInsert() |
|
| 25 | { |
|
| 26 | $node = new NodeAlNs(['slug' => 'r']); |
|
| 27 | $this->assertTrue($node->makeRoot()->save()); |
|
| 28 | ||
| 29 | $node->refresh(); |
|
| 30 | $this->assertEquals(null, $node->parent_id); |
|
| 31 | $this->assertEquals(1, $node->lft); |
|
| 32 | $this->assertEquals(2, $node->rgt); |
|
| 33 | $this->assertEquals(0, $node->depth); |
|
| 34 | } |
|
| 35 | ||
| 36 | public function testMakeRootUpdate() |
|
| 37 | { |
|
| 38 | $node = NodeAlNs::findOne(9); |
|
| 39 | $this->assertTrue($node->makeRoot()->save()); |
|
| 40 | ||
| 41 | $node->refresh(); |
|
| 42 | $this->assertEquals(null, $node->parent_id); |
|
| 43 | $this->assertEquals(1, $node->lft); |
|
| 44 | $this->assertEquals(8, $node->rgt); |
|
| 45 | $this->assertEquals(0, $node->depth); |
|
| 46 | } |
|
| 47 | ||
| 48 | public function testPrependTo() |
|
| 49 | { |
|
| 50 | $node = new NodeAlNs(['slug' => 'new']); |
|
| 51 | $this->assertTrue($node->prependTo(NodeAlNs::findOne(1))->save()); |
|
| 52 | ||
| 53 | $node->refresh(); |
|
| 54 | $this->assertEquals(1, $node->parent_id); |
|
| 55 | $this->assertEquals(2, $node->lft); |
|
| 56 | $this->assertEquals(3, $node->rgt); |
|
| 57 | $this->assertEquals(1, $node->depth); |
|
| 58 | } |
|
| 59 | ||
| 60 | public function testPrependToAnotherTree() |
|
| 61 | { |
|
| 62 | $node = NodeAlNs::findOne(30); |
|
| 63 | $this->assertTrue($node->prependTo(NodeAlNs::findOne(4))->save()); |
|
| 64 | ||
| 65 | $node->refresh(); |
|
| 66 | $this->assertEquals(4, $node->parent_id); |
|
| 67 | $this->assertEquals(31, $node->lft); |
|
| 68 | $this->assertEquals(40, $node->rgt); |
|
| 69 | $this->assertEquals(2, $node->depth); |
|
| 70 | } |
|
| 71 | ||
| 72 | public function testAppendTo() |
|
| 73 | { |
|
| 74 | $node = NodeAlNs::findOne(10); |
|
| 75 | $this->assertTrue($node->appendTo(NodeAlNs::findOne(18))->save()); |
|
| 76 | ||
| 77 | $node->refresh(); |
|
| 78 | $this->assertEquals(18, $node->parent_id); |
|
| 79 | $this->assertEquals(23, $node->lft); |
|
| 80 | $this->assertEquals(30, $node->rgt); |
|
| 81 | $this->assertEquals(4, $node->depth); |
|
| 82 | } |
|
| 83 | ||
| 84 | public function testInsertBefore() |
|
| 85 | { |
|
| 86 | $node = new NodeAlNs(['slug' => 'new']); |
|
| 87 | $this->assertTrue($node->insertBefore(NodeAlNs::findOne(22))->save()); |
|
| 88 | ||
| 89 | $node->refresh(); |
|
| 90 | $this->assertEquals(9, $node->parent_id); |
|
| 91 | $this->assertEquals(38, $node->lft); |
|
| 92 | $this->assertEquals(39, $node->rgt); |
|
| 93 | $this->assertEquals(3, $node->depth); |
|
| 94 | } |
|
| 95 | ||
| 96 | public function testInsertAfter() |
|
| 97 | { |
|
| 98 | $node = NodeAlNs::findOne(32); |
|
| 99 | $this->assertTrue($node->insertAfter(NodeAlNs::findOne(30))->save()); |
|
| 100 | ||
| 101 | $node->refresh(); |
|
| 102 | $this->assertEquals(26, $node->parent_id); |
|
| 103 | $this->assertEquals(26, $node->lft); |
|
| 104 | $this->assertEquals(27, $node->rgt); |
|
| 105 | $this->assertEquals(1, $node->depth); |
|
| 106 | } |
|
| 107 | ||
| 108 | public function testInsertAfterAnotherTree() |
|
| 109 | { |
|
| 110 | $node = NodeAlNs::findOne(26); |
|
| 111 | $this->assertTrue($node->insertAfter(NodeAlNs::findOne(21))->save()); |
|
| 112 | ||
| 113 | $node->refresh(); |
|
| 114 | $this->assertEquals(9, $node->parent_id); |
|
| 115 | $this->assertEquals(38, $node->lft); |
|
| 116 | $this->assertEquals(65, $node->rgt); |
|
| 117 | $this->assertEquals(3, $node->depth); |
|
| 118 | } |
|
| 119 | ||
| 120 | public function testDelete() |
|
| 121 | { |
|
| 122 | $this->assertEquals(1, NodeAlNs::findOne(30)->delete()); |
|
| 123 | $this->assertEquals(null, NodeAlNs::findOne(30)); |
|
| 124 | } |
|
| 125 | ||
| 126 | public function testDeleteWithChildren() |
|
| 127 | { |
|
| 128 | $this->assertEquals(10, NodeAlNs::findOne(4)->deleteWithChildren()); |
|
| 129 | $this->assertEquals(null, NodeAlNs::findOne(24)); |
|
| 130 | $this->assertEquals(15, NodeAlNs::findOne(1)->deleteWithChildren()); |
|
| 131 | } |
|
| 132 | } |
|