From 66c27256eac21766ff8e3185cbda8016d5d215e2 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Wed, 1 May 2013 20:15:28 +0530 Subject: [PATCH] Add new test cases to cover different execution paths of Node->hasSiblings() method --- test/classes/navigation/PMA_Node_test.php | 67 ++++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/test/classes/navigation/PMA_Node_test.php b/test/classes/navigation/PMA_Node_test.php index c72c7fcfe3..d9399df212 100644 --- a/test/classes/navigation/PMA_Node_test.php +++ b/test/classes/navigation/PMA_Node_test.php @@ -148,12 +148,75 @@ class Node_test extends PHPUnit_Framework_TestCase $this->assertEquals($child->realParent(), $parent); } - public function testHasSiblings() + /** + * Tests whether Node->hasSiblings() method returns false + * when the node does not have any siblings. + * + * @return void + * @test + */ + public function testHasSiblingsWithNoSiblings() { $parent = PMA_NodeFactory::getInstance(); $child = PMA_NodeFactory::getInstance(); $parent->addChild($child); - $this->assertEquals($child->hasSiblings(), false); + $this->assertEquals(false, $child->hasSiblings()); + } + + /** + * Tests whether Node->hasSiblings() method returns true + * when it actually has siblings. + * + * @return void + * @test + */ + public function testHasSiblingsWithSiblings() + { + $parent = PMA_NodeFactory::getInstance(); + $firstChild = PMA_NodeFactory::getInstance(); + $parent->addChild($firstChild); + $secondChild = PMA_NodeFactory::getInstance(); + $parent->addChild($secondChild); + // Normal case; two Node:NODE type siblings + $this->assertEquals(true, $firstChild->hasSiblings()); + + $parent = PMA_NodeFactory::getInstance(); + $firstChild = PMA_NodeFactory::getInstance(); + $parent->addChild($firstChild); + $secondChild = PMA_NodeFactory::getInstance( + 'Node', 'default', Node::CONTAINER + ); + $parent->addChild($secondChild); + // Empty Node::CONTAINER type node should not be considered in hasSiblings() + $this->assertEquals(false, $firstChild->hasSiblings()); + + $grandChild = PMA_NodeFactory::getInstance(); + $secondChild->addChild($grandChild); + // Node::CONTAINER type nodes with children are counted for hasSiblings() + $this->assertEquals(true, $firstChild->hasSiblings()); + } + + /** + * It is expected that Node->hasSiblings() method always return true + * for Nodes that are 3 levels deep (columns and indexes). + * + * @return void + * @test + */ + public function testHasSiblingsForNodesAtLevelThree() + { + $parent = PMA_NodeFactory::getInstance(); + $child = PMA_NodeFactory::getInstance(); + $parent->addChild($child); + $grandChild = PMA_NodeFactory::getInstance(); + $child->addChild($grandChild); + $greatGrandChild = PMA_NodeFactory::getInstance(); + $grandChild->addChild($greatGrandChild); + + // Should return false for node that are two levels deeps + $this->assertEquals(false, $grandChild->hasSiblings()); + // Should return true for node that are three levels deeps + $this->assertEquals(true, $greatGrandChild->hasSiblings()); } public function testComment()