function testGetParents() { $menu = new OA_Admin_Menu(); $sections = $this->generateSections(20, 1); //build hierarchy $menu->add($sections[0]); $parentId = $sections[0]->getId(); for ($i = 1; $i < count($sections); $i++) { $menu->addTo($parentId, $sections[$i]); $parentId = $sections[$i]->getId(); } //get parent of a non existent section $parents = $menu->getParentSections("some-nonexistent-section-id"); $this->assertNotNull($parents); $this->assertEqual(0, count($parents)); //get parent of first level section (should be null) $parents = $menu->getParentSections($sections[0]->getId()); $this->assertNotNull($parents); $this->assertEqual(0, count($parents)); //get other parents for ($i = 1; $i < count($sections); $i++) { $parents = null; $parents = $menu->getParentSections($sections[$i]->getId()); $this->assertNotNull($parents); $this->assertEqual($i, count($parents)); $expectedParents = array_slice($sections, 0, $i); $this->assertSectionListsEqual($expectedParents, $parents); } }