. */ use PHPUnit_Framework_TestCase; /** * Test harness for the class Menu */ class MenuTest extends PHPUnit_Framework_TestCase { /** * Prepare the environment for these tests. * * @return void */ public function setUp() { } /** * Test the constructor with default parameters. * * @return void */ 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. * * @return void */ 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. * * @return void */ 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. * * @return void */ 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. * * @return void */ 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. * * @return void */ 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. * * @return void */ 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. * * @return void */ public function testStringCast() { $menu = new Menu('Test!'); $this->assertSame((string)$menu, $menu->getMenuAsList()); } /** * Test the list rendering for a simple link. * * @return void */ public function testFormatAsList() { $menu = new Menu('Test!', 'link.html'); $this->assertSame('
  • Test!
  • ', $menu->getMenuAsList()); } /** * Test the list rendering for a simple link with a CSS ID. * * @return void */ public function testFormatAsListWithClass() { $menu = new Menu('Test!', 'link.html', 'link-class'); $this->assertSame('', $menu->getMenuAsList()); } /** * Test the list rendering for an empty target. * * @return void */ public function testFormatAsListWithNoTarget() { $menu = new Menu('Test!', ''); $this->assertSame('
  • Test!
  • ', $menu->getMenuAsList()); } /** * Test the list rendering for a default (hash) target. * * @return void */ public function testFormatAsListWithHashTarget() { $menu = new Menu('Test!'); $this->assertSame('
  • Test!
  • ', $menu->getMenuAsList()); } /** * Test the list rendering for an onclick link. * * @return void */ public function testFormatAsListWithOnclick() { $menu = new Menu('Test!', '#', '', 'return test();'); $this->assertSame('
  • Test!
  • ', $menu->getMenuAsList()); } /** * Test the list rendering for an onclick link. * * @return void */ public function testFormatAsListWithOnclickAndId() { $menu = new Menu('Test!', '#', 'link-class', 'return test();'); $this->assertSame('', $menu->getMenuAsList()); } }