1a25f0a04SGreg Roach<?php 2a25f0a04SGreg Roach/** 3a25f0a04SGreg Roach * webtrees: online genealogy 48fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team 5a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify 6a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by 7a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or 8a25f0a04SGreg Roach * (at your option) any later version. 9a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful, 10a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 11a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12a25f0a04SGreg Roach * GNU General Public License for more details. 13a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License 14a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 15a25f0a04SGreg Roach */ 16e7f56f2aSGreg Roachdeclare(strict_types=1); 17e7f56f2aSGreg Roach 1884e2cf4eSGreg Roachnamespace Fisharebest\Webtrees; 19a25f0a04SGreg Roach 20a25f0a04SGreg Roach/** 21a25f0a04SGreg Roach * Test harness for the class Menu 22a25f0a04SGreg Roach */ 2384e2cf4eSGreg Roachclass MenuTest extends \Fisharebest\Webtrees\TestCase 24c1010edaSGreg Roach{ 25a25f0a04SGreg Roach /** 26*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::__construct 2718d7a90dSGreg Roach * 2818d7a90dSGreg Roach * @return void 29a25f0a04SGreg Roach */ 30*9b802b22SGreg Roach public function testConstructorDefaults(): void 31c1010edaSGreg Roach { 32a25f0a04SGreg Roach $menu = new Menu('Test!'); 33a25f0a04SGreg Roach 34a25f0a04SGreg Roach $this->assertSame('Test!', $menu->getLabel()); 35a25f0a04SGreg Roach $this->assertSame('#', $menu->getLink()); 367820e4d7SGreg Roach $this->assertSame('', $menu->getClass()); 3713abd6f3SGreg Roach $this->assertSame([], $menu->getAttrs()); 3813abd6f3SGreg Roach $this->assertSame([], $menu->getSubmenus()); 39a25f0a04SGreg Roach } 40a25f0a04SGreg Roach 41a25f0a04SGreg Roach /** 42*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::__construct 4318d7a90dSGreg Roach * 4418d7a90dSGreg Roach * @return void 45a25f0a04SGreg Roach */ 46*9b802b22SGreg Roach public function testConstructorNonDefaults(): void 47c1010edaSGreg Roach { 4813abd6f3SGreg Roach $submenus = [new Menu('Submenu')]; 4913abd6f3SGreg Roach $menu = new Menu('Test!', 'link.html', 'link-class', ['foo' => 'bar'], $submenus); 50a25f0a04SGreg Roach 51a25f0a04SGreg Roach $this->assertSame('Test!', $menu->getLabel()); 52a25f0a04SGreg Roach $this->assertSame('link.html', $menu->getLink()); 53794c6b5bSGreg Roach $this->assertSame('link-class', $menu->getClass()); 5413abd6f3SGreg Roach $this->assertSame(['foo' => 'bar'], $menu->getAttrs()); 55a25f0a04SGreg Roach $this->assertSame($submenus, $menu->getSubmenus()); 56a25f0a04SGreg Roach } 57a25f0a04SGreg Roach 58a25f0a04SGreg Roach /** 59*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::getLabel 60*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::setLabel 6118d7a90dSGreg Roach * 6218d7a90dSGreg Roach * @return void 63a25f0a04SGreg Roach */ 64*9b802b22SGreg Roach public function testGetterSetterLabel(): void 65c1010edaSGreg Roach { 66a25f0a04SGreg Roach $menu = new Menu('Test!'); 67a25f0a04SGreg Roach 68a25f0a04SGreg Roach $return = $menu->setLabel('Label'); 69a25f0a04SGreg Roach 70a25f0a04SGreg Roach $this->assertSame($return, $menu); 71a25f0a04SGreg Roach $this->assertSame('Label', $menu->getLabel()); 72a25f0a04SGreg Roach } 73a25f0a04SGreg Roach 74a25f0a04SGreg Roach /** 75*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::getLink 76*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::setLink 7718d7a90dSGreg Roach * 7818d7a90dSGreg Roach * @return void 79a25f0a04SGreg Roach */ 80*9b802b22SGreg Roach public function testGetterSetterLink(): void 81c1010edaSGreg Roach { 82a25f0a04SGreg Roach $menu = new Menu('Test!'); 83a25f0a04SGreg Roach 84a25f0a04SGreg Roach $return = $menu->setLink('link.html'); 85a25f0a04SGreg Roach 86a25f0a04SGreg Roach $this->assertSame($return, $menu); 87a25f0a04SGreg Roach $this->assertSame('link.html', $menu->getLink()); 88a25f0a04SGreg Roach } 89a25f0a04SGreg Roach 90a25f0a04SGreg Roach /** 91*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::getClass 92*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::setClass 9318d7a90dSGreg Roach * 9418d7a90dSGreg Roach * @return void 95a25f0a04SGreg Roach */ 96*9b802b22SGreg Roach public function testGetterSetterId(): void 97c1010edaSGreg Roach { 98a25f0a04SGreg Roach $menu = new Menu('Test!'); 99a25f0a04SGreg Roach 100794c6b5bSGreg Roach $return = $menu->setClass('link-class'); 101a25f0a04SGreg Roach 102a25f0a04SGreg Roach $this->assertSame($return, $menu); 103794c6b5bSGreg Roach $this->assertSame('link-class', $menu->getClass()); 104a25f0a04SGreg Roach } 105a25f0a04SGreg Roach 106a25f0a04SGreg Roach /** 107*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::getAttrs 108*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::setAttrs 10918d7a90dSGreg Roach * 11018d7a90dSGreg Roach * @return void 111a25f0a04SGreg Roach */ 112*9b802b22SGreg Roach public function testGetterSetterAttrs(): void 113c1010edaSGreg Roach { 114a25f0a04SGreg Roach $menu = new Menu('Test!'); 115a25f0a04SGreg Roach 11613abd6f3SGreg Roach $return = $menu->setAttrs(['foo' => 'bar']); 117a25f0a04SGreg Roach 118a25f0a04SGreg Roach $this->assertSame($return, $menu); 11913abd6f3SGreg Roach $this->assertSame(['foo' => 'bar'], $menu->getAttrs()); 120a25f0a04SGreg Roach } 121a25f0a04SGreg Roach 122a25f0a04SGreg Roach /** 123*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::getSubmenus 124*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::setSubmenus 12518d7a90dSGreg Roach * 12618d7a90dSGreg Roach * @return void 127a25f0a04SGreg Roach */ 128*9b802b22SGreg Roach public function testGetterSetterSubmenus(): void 129c1010edaSGreg Roach { 130a25f0a04SGreg Roach $menu = new Menu('Test!'); 13113abd6f3SGreg Roach $submenus = [ 132a25f0a04SGreg Roach new Menu('Sub1'), 133a25f0a04SGreg Roach new Menu('Sub2'), 13413abd6f3SGreg Roach ]; 135a25f0a04SGreg Roach 136a25f0a04SGreg Roach $return = $menu->setSubmenus($submenus); 137a25f0a04SGreg Roach 138a25f0a04SGreg Roach $this->assertSame($return, $menu); 139a25f0a04SGreg Roach $this->assertSame($submenus, $menu->getSubmenus()); 140a25f0a04SGreg Roach } 141a25f0a04SGreg Roach 142a25f0a04SGreg Roach /** 143*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::getMenuAsList 14418d7a90dSGreg Roach * 14518d7a90dSGreg Roach * @return void 146a25f0a04SGreg Roach */ 147*9b802b22SGreg Roach public function testFormatAsList(): void 148c1010edaSGreg Roach { 149a25f0a04SGreg Roach $menu = new Menu('Test!', 'link.html'); 150a25f0a04SGreg Roach 151794c6b5bSGreg Roach $this->assertSame('<li class=""><a href="link.html">Test!</a></li>', $menu->getMenuAsList()); 152a25f0a04SGreg Roach } 153a25f0a04SGreg Roach 154a25f0a04SGreg Roach /** 155*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::getMenuAsList 15618d7a90dSGreg Roach * 15718d7a90dSGreg Roach * @return void 158a25f0a04SGreg Roach */ 159*9b802b22SGreg Roach public function testFormatAsListWithClass(): void 160c1010edaSGreg Roach { 161794c6b5bSGreg Roach $menu = new Menu('Test!', 'link.html', 'link-class'); 162a25f0a04SGreg Roach 163794c6b5bSGreg Roach $this->assertSame('<li class="link-class"><a href="link.html">Test!</a></li>', $menu->getMenuAsList()); 164a25f0a04SGreg Roach } 165a25f0a04SGreg Roach 166a25f0a04SGreg Roach /** 167*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::getMenuAsList 16818d7a90dSGreg Roach * 16918d7a90dSGreg Roach * @return void 170a25f0a04SGreg Roach */ 171*9b802b22SGreg Roach public function testFormatAsListWithNoTarget(): void 172c1010edaSGreg Roach { 173a25f0a04SGreg Roach $menu = new Menu('Test!', ''); 174a25f0a04SGreg Roach 175794c6b5bSGreg Roach $this->assertSame('<li class=""><a>Test!</a></li>', $menu->getMenuAsList()); 176a25f0a04SGreg Roach } 177a25f0a04SGreg Roach 178a25f0a04SGreg Roach /** 179*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::getMenuAsList 18018d7a90dSGreg Roach * 18118d7a90dSGreg Roach * @return void 182a25f0a04SGreg Roach */ 183*9b802b22SGreg Roach public function testFormatAsListWithHashTarget(): void 184c1010edaSGreg Roach { 185a25f0a04SGreg Roach $menu = new Menu('Test!'); 186a25f0a04SGreg Roach 187794c6b5bSGreg Roach $this->assertSame('<li class=""><a href="#">Test!</a></li>', $menu->getMenuAsList()); 188a25f0a04SGreg Roach } 189a25f0a04SGreg Roach 190a25f0a04SGreg Roach /** 191*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::getMenuAsList 19218d7a90dSGreg Roach * 19318d7a90dSGreg Roach * @return void 194a25f0a04SGreg Roach */ 195*9b802b22SGreg Roach public function testFormatAsListWithAttrs(): void 196c1010edaSGreg Roach { 19713abd6f3SGreg Roach $menu = new Menu('Test!', '#', '', ['foo' => 'bar']); 198a25f0a04SGreg Roach 1993cf92ae2SGreg Roach $this->assertSame('<li class=""><a href="#" foo="bar">Test!</a></li>', $menu->getMenuAsList()); 200a25f0a04SGreg Roach } 201a25f0a04SGreg Roach 202a25f0a04SGreg Roach /** 203*9b802b22SGreg Roach * @covers \Fisharebest\Webtrees\Menu::getMenuAsList 20418d7a90dSGreg Roach * 20518d7a90dSGreg Roach * @return void 206a25f0a04SGreg Roach */ 207*9b802b22SGreg Roach public function testFormatAsListWithAttrsAndId(): void 208c1010edaSGreg Roach { 20913abd6f3SGreg Roach $menu = new Menu('Test!', '#', 'link-class', ['foo' => 'bar']); 210a25f0a04SGreg Roach 2113cf92ae2SGreg Roach $this->assertSame('<li class="link-class"><a href="#" foo="bar">Test!</a></li>', $menu->getMenuAsList()); 212a25f0a04SGreg Roach } 213a25f0a04SGreg Roach} 214