. */ use PHPUnit_Framework_TestCase; /** * Test harness for the class Menu */ class MenuTest extends PHPUnit_Framework_TestCase { /** * Prepare the environment for these tests. */ public function setUp() { } /** * Test the constructor with default parameters. */ public function testConstructorDefaults() { $menu = new Menu('Test!'); $this->assertSame('Test!', $menu->getLabel()); $this->assertSame('#', $menu->getLink()); $this->assertSame('', $menu->getCLass()); $this->assertSame('', $menu->getOnclick()); $this->assertSame(array(), $menu->getSubmenus()); } /** * Test the constructor with non-default parameters. */ public function testConstructorNonDefaults() { $submenus = array(new Menu('Submenu')); $menu = new Menu('Test!', 'link.html', 'link-class', 'test();', $submenus); $this->assertSame('Test!', $menu->getLabel()); $this->assertSame('link.html', $menu->getLink()); $this->assertSame('link-class', $menu->getClass()); $this->assertSame('test();', $menu->getOnclick()); $this->assertSame($submenus, $menu->getSubmenus()); } /** * Test the getter/setter for the label. */ public function testGetterSetterLabel() { $menu = new Menu('Test!'); $return = $menu->setLabel('Label'); $this->assertSame($return, $menu); $this->assertSame('Label', $menu->getLabel()); } /** * Test the getter/setter for the link. */ public function testGetterSetterLink() { $menu = new Menu('Test!'); $return = $menu->setLink('link.html'); $this->assertSame($return, $menu); $this->assertSame('link.html', $menu->getLink()); } /** * Test the getter/setter for the ID. */ public function testGetterSetterId() { $menu = new Menu('Test!'); $return = $menu->setClass('link-class'); $this->assertSame($return, $menu); $this->assertSame('link-class', $menu->getClass()); } /** * Test the getter/setter for the Onclick event. */ public function testGetterSetterOnclick() { $menu = new Menu('Test!'); $return = $menu->setOnclick('test();'); $this->assertSame($return, $menu); $this->assertSame('test();', $menu->getOnclick()); } /** * Test the getter/setter for the submenus. */ public function testGetterSetterSubmenus() { $menu = new Menu('Test!'); $submenus = array( new Menu('Sub1'), new Menu('Sub2'), ); $return = $menu->setSubmenus($submenus); $this->assertSame($return, $menu); $this->assertSame($submenus, $menu->getSubmenus()); } /** * Test the string cast. */ public function testStringCast() { $menu = new Menu('Test!'); $this->assertSame((string) $menu, $menu->getMenuAsList()); } /** * Test the list rendering for a simple link. */ public function testFormatAsList() { $menu = new Menu('Test!', 'link.html'); $this->assertSame('