1<?php 2 3/** 4 * webtrees: online genealogy 5 * 'Copyright (C) 2023 webtrees development team 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 */ 17 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees; 21 22/** 23 * Test harness for the class Menu 24 */ 25class MenuTest extends TestCase 26{ 27 /** 28 * @covers \Fisharebest\Webtrees\Menu::__construct 29 * 30 * @return void 31 */ 32 public function testConstructorDefaults(): void 33 { 34 $menu = new Menu('Test!'); 35 36 self::assertSame('Test!', $menu->getLabel()); 37 self::assertSame('#', $menu->getLink()); 38 self::assertSame('', $menu->getClass()); 39 self::assertSame([], $menu->getAttrs()); 40 self::assertSame([], $menu->getSubmenus()); 41 } 42 43 /** 44 * @covers \Fisharebest\Webtrees\Menu::__construct 45 * 46 * @return void 47 */ 48 public function testConstructorNonDefaults(): void 49 { 50 $submenus = [new Menu('Submenu')]; 51 $menu = new Menu('Test!', 'link.html', 'link-class', ['foo' => 'bar'], $submenus); 52 53 self::assertSame('Test!', $menu->getLabel()); 54 self::assertSame('link.html', $menu->getLink()); 55 self::assertSame('link-class', $menu->getClass()); 56 self::assertSame(['foo' => 'bar'], $menu->getAttrs()); 57 self::assertSame($submenus, $menu->getSubmenus()); 58 } 59 60 /** 61 * @covers \Fisharebest\Webtrees\Menu::getLabel 62 * @covers \Fisharebest\Webtrees\Menu::setLabel 63 * 64 * @return void 65 */ 66 public function testGetterSetterLabel(): void 67 { 68 $menu = new Menu('Test!'); 69 70 $return = $menu->setLabel('Label'); 71 72 self::assertSame($return, $menu); 73 self::assertSame('Label', $menu->getLabel()); 74 } 75 76 /** 77 * @covers \Fisharebest\Webtrees\Menu::getLink 78 * @covers \Fisharebest\Webtrees\Menu::setLink 79 * 80 * @return void 81 */ 82 public function testGetterSetterLink(): void 83 { 84 $menu = new Menu('Test!'); 85 86 $return = $menu->setLink('link.html'); 87 88 self::assertSame($return, $menu); 89 self::assertSame('link.html', $menu->getLink()); 90 } 91 92 /** 93 * @covers \Fisharebest\Webtrees\Menu::getClass 94 * @covers \Fisharebest\Webtrees\Menu::setClass 95 * 96 * @return void 97 */ 98 public function testGetterSetterId(): void 99 { 100 $menu = new Menu('Test!'); 101 102 $return = $menu->setClass('link-class'); 103 104 self::assertSame($return, $menu); 105 self::assertSame('link-class', $menu->getClass()); 106 } 107 108 /** 109 * @covers \Fisharebest\Webtrees\Menu::getAttrs 110 * @covers \Fisharebest\Webtrees\Menu::setAttrs 111 * 112 * @return void 113 */ 114 public function testGetterSetterAttrs(): void 115 { 116 $menu = new Menu('Test!'); 117 118 $return = $menu->setAttrs(['foo' => 'bar']); 119 120 self::assertSame($return, $menu); 121 self::assertSame(['foo' => 'bar'], $menu->getAttrs()); 122 } 123 124 /** 125 * @covers \Fisharebest\Webtrees\Menu::getSubmenus 126 * @covers \Fisharebest\Webtrees\Menu::setSubmenus 127 * 128 * @return void 129 */ 130 public function testGetterSetterSubmenus(): void 131 { 132 $menu = new Menu('Test!'); 133 $submenus = [ 134 new Menu('Sub1'), 135 new Menu('Sub2'), 136 ]; 137 138 $return = $menu->setSubmenus($submenus); 139 140 self::assertSame($return, $menu); 141 self::assertSame($submenus, $menu->getSubmenus()); 142 } 143} 144