/** * Returns the parent node of the current node or null when there is no parent. * * @return AbstractRenderNode|null */ public function getParent() { $unitMap = $this->relatedTree->getUnitMap(); $parentId = $this->getParentId(); if (isset($parentId)) { return $unitMap[$parentId]; } else { return null; } }
/** * @test * @group rendering * @group small * @group dev */ public function test_normalTree() { // // ARRANGE // // Prepare module info storage $moduleInfos = $this->getModuleInfo(); $moduleInfoStorage = new ArrayBasedModuleInfoStorage($moduleInfos); // Children Level 2 $l2 = array(); $l2['id'] = 'UNIT-d4f8dd99-c7b7-48a4-825c-856976138a08-UNIT'; $l2['name'] = 'SimpleTestUnit'; $l2['moduleId'] = 'MODUL-86a089bd-9d94-440c-b409-6d0be21836d2-MODUL'; // Children Level 1 $l1 = array(); $l1['id'] = 'UNIT-b91b7599-76ae-4b29-85dc-6656720a816d-UNIT'; $l1['name'] = 'SimpleTestUnit'; $l1['moduleId'] = 'MODUL-d5268b2c-08b5-4e95-8fe4-9f4e96d50688-MODUL'; $l1['children'] = array($l2); $l1_2 = array(); $l1_2['id'] = 'UNIT-d81a34f2-02df-4f1c-80a3-d949e7848cef-UNIT'; $l1_2['name'] = 'SimpleTestUnit'; $l1_2['moduleId'] = 'MODUL-23c3113e-31ee-42a9-b653-c82e79e77aa5-MODUL'; // Prepare Content $content = array(); $content['id'] = 'UNIT-78667474-aa5c-498c-bcc0-046277bd153b-UNIT'; $content['name'] = 'SimpleTestUnit'; $content['moduleId'] = 'MODUL-86a089bd-9d94-440c-b409-6d0be21836d2-MODUL'; $content['children'] = array($l1, $l1_2); // // ACT // $nodeFactory = new Test1NodeFactory($moduleInfoStorage); $nodeTree = new NodeTree($content, $nodeFactory); // // ASSERT // $createNodeObjectCalls = $nodeFactory->getCreateNodeObjectCalls(); $this->assertEquals(4, count($createNodeObjectCalls)); $lastCall = $createNodeObjectCalls[3]; $this->assertEquals($l1_2, $lastCall[0]); $this->assertNotNull($lastCall[1]); $this->assertEquals($content['id'], $lastCall[2]); $lastNode = $lastCall['return']; $this->assertEmpty($lastNode->getChildren()); $thirdCall = $createNodeObjectCalls[2]; $this->assertEquals($l2, $thirdCall[0]); $this->assertNotNull($thirdCall[1]); $this->assertEquals($l1['id'], $thirdCall[2]); $thirdNode = $thirdCall['return']; $this->assertEmpty($thirdNode->getChildren()); $secondCall = $createNodeObjectCalls[1]; $this->assertEquals($l1, $secondCall[0]); $this->assertNotNull($secondCall[1]); $this->assertEquals($content['id'], $secondCall[2]); $secondNode = $secondCall['return']; $this->assertEquals(array($thirdNode), $secondNode->getChildren()); // Root Node $firstCall = $createNodeObjectCalls[0]; $this->assertEquals($content, $firstCall[0]); $this->assertNotNull($firstCall[1]); $this->assertNull($firstCall[2]); $rootNode = $firstCall['return']; $this->assertEquals(array($secondNode, $lastNode), $rootNode->getChildren()); $root = $nodeTree->getRootNode(); $unit = $root->getUnit()->toArray(); $this->assertEquals($content['moduleId'], $unit['moduleId']); $root = $nodeTree->getRootNode(); $l1Nodes = $root->getChildren(); $l1unit = $l1Nodes[0]->getUnit()->toArray(); $this->assertEquals($l1['moduleId'], $l1unit['moduleId']); $root = $nodeTree->getRootNode(); $l1Nodes = $root->getChildren(); $l1_2unit = $l1Nodes[1]->getUnit()->toArray(); $this->assertEquals($l1_2['moduleId'], $l1_2unit['moduleId']); $l1Node = $l1Nodes[0]; $l2Nodes = $l1Node->getChildren(); $l2unit = $l2Nodes[0]->getUnit()->toArray(); $this->assertEquals($l2['moduleId'], $l2unit['moduleId']); $this->assertEquals($createNodeObjectCalls[0]['return'], $nodeTree->getRootNode()); $this->assertEquals(4, count($nodeTree->getUnitMap())); }