1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>. 16 */ 17declare(strict_types=1); 18 19namespace Fisharebest\Webtrees; 20 21/** 22 * Test harness for the class Menu 23 */ 24class MenuTest extends TestCase 25{ 26 /** 27 * @covers \Fisharebest\Webtrees\Menu::__construct 28 * 29 * @return void 30 */ 31 public function testConstructorDefaults(): void 32 { 33 $menu = new Menu('Test!'); 34 35 $this->assertSame('Test!', $menu->getLabel()); 36 $this->assertSame('#', $menu->getLink()); 37 $this->assertSame('', $menu->getClass()); 38 $this->assertSame([], $menu->getAttrs()); 39 $this->assertSame([], $menu->getSubmenus()); 40 } 41 42 /** 43 * @covers \Fisharebest\Webtrees\Menu::__construct 44 * 45 * @return void 46 */ 47 public function testConstructorNonDefaults(): void 48 { 49 $submenus = [new Menu('Submenu')]; 50 $menu = new Menu('Test!', 'link.html', 'link-class', ['foo' => 'bar'], $submenus); 51 52 $this->assertSame('Test!', $menu->getLabel()); 53 $this->assertSame('link.html', $menu->getLink()); 54 $this->assertSame('link-class', $menu->getClass()); 55 $this->assertSame(['foo' => 'bar'], $menu->getAttrs()); 56 $this->assertSame($submenus, $menu->getSubmenus()); 57 } 58 59 /** 60 * @covers \Fisharebest\Webtrees\Menu::getLabel 61 * @covers \Fisharebest\Webtrees\Menu::setLabel 62 * 63 * @return void 64 */ 65 public function testGetterSetterLabel(): void 66 { 67 $menu = new Menu('Test!'); 68 69 $return = $menu->setLabel('Label'); 70 71 $this->assertSame($return, $menu); 72 $this->assertSame('Label', $menu->getLabel()); 73 } 74 75 /** 76 * @covers \Fisharebest\Webtrees\Menu::getLink 77 * @covers \Fisharebest\Webtrees\Menu::setLink 78 * 79 * @return void 80 */ 81 public function testGetterSetterLink(): void 82 { 83 $menu = new Menu('Test!'); 84 85 $return = $menu->setLink('link.html'); 86 87 $this->assertSame($return, $menu); 88 $this->assertSame('link.html', $menu->getLink()); 89 } 90 91 /** 92 * @covers \Fisharebest\Webtrees\Menu::getClass 93 * @covers \Fisharebest\Webtrees\Menu::setClass 94 * 95 * @return void 96 */ 97 public function testGetterSetterId(): void 98 { 99 $menu = new Menu('Test!'); 100 101 $return = $menu->setClass('link-class'); 102 103 $this->assertSame($return, $menu); 104 $this->assertSame('link-class', $menu->getClass()); 105 } 106 107 /** 108 * @covers \Fisharebest\Webtrees\Menu::getAttrs 109 * @covers \Fisharebest\Webtrees\Menu::setAttrs 110 * 111 * @return void 112 */ 113 public function testGetterSetterAttrs(): void 114 { 115 $menu = new Menu('Test!'); 116 117 $return = $menu->setAttrs(['foo' => 'bar']); 118 119 $this->assertSame($return, $menu); 120 $this->assertSame(['foo' => 'bar'], $menu->getAttrs()); 121 } 122 123 /** 124 * @covers \Fisharebest\Webtrees\Menu::getSubmenus 125 * @covers \Fisharebest\Webtrees\Menu::setSubmenus 126 * 127 * @return void 128 */ 129 public function testGetterSetterSubmenus(): void 130 { 131 $menu = new Menu('Test!'); 132 $submenus = [ 133 new Menu('Sub1'), 134 new Menu('Sub2'), 135 ]; 136 137 $return = $menu->setSubmenus($submenus); 138 139 $this->assertSame($return, $menu); 140 $this->assertSame($submenus, $menu->getSubmenus()); 141 } 142} 143