. */ declare(strict_types=1); namespace Fisharebest\Webtrees; /** * Test harness for the class Menu */ class MenuTest extends TestCase { /** * @covers \Fisharebest\Webtrees\Menu::__construct */ public function testConstructorDefaults(): void { $menu = new Menu('Test!'); self::assertSame('Test!', $menu->getLabel()); self::assertSame('#', $menu->getLink()); self::assertSame('', $menu->getClass()); self::assertSame([], $menu->getAttrs()); self::assertSame([], $menu->getSubmenus()); } /** * @covers \Fisharebest\Webtrees\Menu::__construct */ public function testConstructorNonDefaults(): void { $submenus = [new Menu('Submenu')]; $menu = new Menu('Test!', 'link.html', 'link-class', ['foo' => 'bar'], $submenus); self::assertSame('Test!', $menu->getLabel()); self::assertSame('link.html', $menu->getLink()); self::assertSame('link-class', $menu->getClass()); self::assertSame(['foo' => 'bar'], $menu->getAttrs()); self::assertSame($submenus, $menu->getSubmenus()); } /** * @covers \Fisharebest\Webtrees\Menu::getLabel * @covers \Fisharebest\Webtrees\Menu::setLabel */ public function testGetterSetterLabel(): void { $menu = new Menu('Test!'); $return = $menu->setLabel('Label'); self::assertSame($return, $menu); self::assertSame('Label', $menu->getLabel()); } /** * @covers \Fisharebest\Webtrees\Menu::getLink * @covers \Fisharebest\Webtrees\Menu::setLink */ public function testGetterSetterLink(): void { $menu = new Menu('Test!'); $return = $menu->setLink('link.html'); self::assertSame($return, $menu); self::assertSame('link.html', $menu->getLink()); } /** * @covers \Fisharebest\Webtrees\Menu::getClass * @covers \Fisharebest\Webtrees\Menu::setClass */ public function testGetterSetterId(): void { $menu = new Menu('Test!'); $return = $menu->setClass('link-class'); self::assertSame($return, $menu); self::assertSame('link-class', $menu->getClass()); } /** * @covers \Fisharebest\Webtrees\Menu::getAttrs * @covers \Fisharebest\Webtrees\Menu::setAttrs */ public function testGetterSetterAttrs(): void { $menu = new Menu('Test!'); $return = $menu->setAttrs(['foo' => 'bar']); self::assertSame($return, $menu); self::assertSame(['foo' => 'bar'], $menu->getAttrs()); } /** * @covers \Fisharebest\Webtrees\Menu::getSubmenus * @covers \Fisharebest\Webtrees\Menu::setSubmenus */ public function testGetterSetterSubmenus(): void { $menu = new Menu('Test!'); $submenus = [ new Menu('Sub1'), new Menu('Sub2'), ]; $return = $menu->setSubmenus($submenus); self::assertSame($return, $menu); self::assertSame($submenus, $menu->getSubmenus()); } }