. */ declare(strict_types=1); namespace Fisharebest\Webtrees; /** * Test harness for the class Menu */ class MenuTest extends \Fisharebest\Webtrees\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->getAttrs()); $this->assertSame([], $menu->getSubmenus()); } /** * Test the constructor with non-default parameters. * * @return void */ public function testConstructorNonDefaults() { $submenus = [new Menu('Submenu')]; $menu = new Menu('Test!', 'link.html', 'link-class', ['foo' => 'bar'], $submenus); $this->assertSame('Test!', $menu->getLabel()); $this->assertSame('link.html', $menu->getLink()); $this->assertSame('link-class', $menu->getClass()); $this->assertSame(['foo' => 'bar'], $menu->getAttrs()); $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 Attrs event. * * @return void */ public function testGetterSetterAttrs() { $menu = new Menu('Test!'); $return = $menu->setAttrs(['foo' => 'bar']); $this->assertSame($return, $menu); $this->assertSame(['foo' => 'bar'], $menu->getAttrs()); } /** * Test the getter/setter for the submenus. * * @return void */ public function testGetterSetterSubmenus() { $menu = new Menu('Test!'); $submenus = [ new Menu('Sub1'), new Menu('Sub2'), ]; $return = $menu->setSubmenus($submenus); $this->assertSame($return, $menu); $this->assertSame($submenus, $menu->getSubmenus()); } /** * Test the list rendering for a simple link. * * @return void */ public function testFormatAsList() { $menu = new Menu('Test!', 'link.html'); $this->assertSame('