xref: /webtrees/tests/app/MenuTest.php (revision 6bdf767435631ad1dc27ec1ffd855d43dbdce907)
1a25f0a04SGreg Roach<?php
2a25f0a04SGreg Roach
3a25f0a04SGreg Roach/**
4a25f0a04SGreg Roach * webtrees: online genealogy
5*6bdf7674SGreg Roach * Copyright (C) 2017 webtrees development team
6a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify
7a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by
8a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9a25f0a04SGreg Roach * (at your option) any later version.
10a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful,
11a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13a25f0a04SGreg Roach * GNU General Public License for more details.
14a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License
15a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
16a25f0a04SGreg Roach */
17a25f0a04SGreg Roach
180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Menu;
19a25f0a04SGreg Roach
20a25f0a04SGreg Roach/**
21a25f0a04SGreg Roach * Test harness for the class Menu
22a25f0a04SGreg Roach */
23db7d25eeSGreg Roachclass MenuTest extends \PHPUnit_Framework_TestCase {
24a25f0a04SGreg Roach	/**
25a25f0a04SGreg Roach	 * Prepare the environment for these tests.
26a25f0a04SGreg Roach	 */
27a25f0a04SGreg Roach	public function setUp() {
28a25f0a04SGreg Roach	}
29a25f0a04SGreg Roach
30a25f0a04SGreg Roach	/**
31a25f0a04SGreg Roach	 * Test the constructor with default parameters.
32a25f0a04SGreg Roach	 */
33a25f0a04SGreg Roach	public function testConstructorDefaults() {
34a25f0a04SGreg Roach		$menu = new Menu('Test!');
35a25f0a04SGreg Roach
36a25f0a04SGreg Roach		$this->assertSame('Test!', $menu->getLabel());
37a25f0a04SGreg Roach		$this->assertSame('#', $menu->getLink());
387820e4d7SGreg Roach		$this->assertSame('', $menu->getClass());
3913abd6f3SGreg Roach		$this->assertSame([], $menu->getAttrs());
4013abd6f3SGreg Roach		$this->assertSame([], $menu->getSubmenus());
41a25f0a04SGreg Roach	}
42a25f0a04SGreg Roach
43a25f0a04SGreg Roach	/**
44a25f0a04SGreg Roach	 * Test the constructor with non-default parameters.
45a25f0a04SGreg Roach	 */
46a25f0a04SGreg Roach	public function testConstructorNonDefaults() {
4713abd6f3SGreg Roach		$submenus = [new Menu('Submenu')];
4813abd6f3SGreg Roach		$menu     = new Menu('Test!', 'link.html', 'link-class', ['foo' => 'bar'], $submenus);
49a25f0a04SGreg Roach
50a25f0a04SGreg Roach		$this->assertSame('Test!', $menu->getLabel());
51a25f0a04SGreg Roach		$this->assertSame('link.html', $menu->getLink());
52794c6b5bSGreg Roach		$this->assertSame('link-class', $menu->getClass());
5313abd6f3SGreg Roach		$this->assertSame(['foo' => 'bar'], $menu->getAttrs());
54a25f0a04SGreg Roach		$this->assertSame($submenus, $menu->getSubmenus());
55a25f0a04SGreg Roach	}
56a25f0a04SGreg Roach
57a25f0a04SGreg Roach	/**
58a25f0a04SGreg Roach	 * Test the getter/setter for the label.
59a25f0a04SGreg Roach	 */
60a25f0a04SGreg Roach	public function testGetterSetterLabel() {
61a25f0a04SGreg Roach		$menu = new Menu('Test!');
62a25f0a04SGreg Roach
63a25f0a04SGreg Roach		$return = $menu->setLabel('Label');
64a25f0a04SGreg Roach
65a25f0a04SGreg Roach		$this->assertSame($return, $menu);
66a25f0a04SGreg Roach		$this->assertSame('Label', $menu->getLabel());
67a25f0a04SGreg Roach	}
68a25f0a04SGreg Roach
69a25f0a04SGreg Roach	/**
70a25f0a04SGreg Roach	 * Test the getter/setter for the link.
71a25f0a04SGreg Roach	 */
72a25f0a04SGreg Roach	public function testGetterSetterLink() {
73a25f0a04SGreg Roach		$menu = new Menu('Test!');
74a25f0a04SGreg Roach
75a25f0a04SGreg Roach		$return = $menu->setLink('link.html');
76a25f0a04SGreg Roach
77a25f0a04SGreg Roach		$this->assertSame($return, $menu);
78a25f0a04SGreg Roach		$this->assertSame('link.html', $menu->getLink());
79a25f0a04SGreg Roach	}
80a25f0a04SGreg Roach
81a25f0a04SGreg Roach	/**
82a25f0a04SGreg Roach	 * Test the getter/setter for the ID.
83a25f0a04SGreg Roach	 */
84a25f0a04SGreg Roach	public function testGetterSetterId() {
85a25f0a04SGreg Roach		$menu = new Menu('Test!');
86a25f0a04SGreg Roach
87794c6b5bSGreg Roach		$return = $menu->setClass('link-class');
88a25f0a04SGreg Roach
89a25f0a04SGreg Roach		$this->assertSame($return, $menu);
90794c6b5bSGreg Roach		$this->assertSame('link-class', $menu->getClass());
91a25f0a04SGreg Roach	}
92a25f0a04SGreg Roach
93a25f0a04SGreg Roach	/**
943cf92ae2SGreg Roach	 * Test the getter/setter for the Attrs event.
95a25f0a04SGreg Roach	 */
963cf92ae2SGreg Roach	public function testGetterSetterAttrs() {
97a25f0a04SGreg Roach		$menu = new Menu('Test!');
98a25f0a04SGreg Roach
9913abd6f3SGreg Roach		$return = $menu->setAttrs(['foo' => 'bar']);
100a25f0a04SGreg Roach
101a25f0a04SGreg Roach		$this->assertSame($return, $menu);
10213abd6f3SGreg Roach		$this->assertSame(['foo' => 'bar'], $menu->getAttrs());
103a25f0a04SGreg Roach	}
104a25f0a04SGreg Roach
105a25f0a04SGreg Roach	/**
106a25f0a04SGreg Roach	 * Test the getter/setter for the submenus.
107a25f0a04SGreg Roach	 */
108a25f0a04SGreg Roach	public function testGetterSetterSubmenus() {
109a25f0a04SGreg Roach		$menu     = new Menu('Test!');
11013abd6f3SGreg Roach		$submenus = [
111a25f0a04SGreg Roach			new Menu('Sub1'),
112a25f0a04SGreg Roach			new Menu('Sub2'),
11313abd6f3SGreg Roach		];
114a25f0a04SGreg Roach
115a25f0a04SGreg Roach		$return = $menu->setSubmenus($submenus);
116a25f0a04SGreg Roach
117a25f0a04SGreg Roach		$this->assertSame($return, $menu);
118a25f0a04SGreg Roach		$this->assertSame($submenus, $menu->getSubmenus());
119a25f0a04SGreg Roach	}
120a25f0a04SGreg Roach
121a25f0a04SGreg Roach	/**
122a25f0a04SGreg Roach	 * Test the string cast.
123a25f0a04SGreg Roach	 */
124a25f0a04SGreg Roach	public function testStringCast() {
125a25f0a04SGreg Roach		$menu = new Menu('Test!');
126a25f0a04SGreg Roach
127a25f0a04SGreg Roach		$this->assertSame((string) $menu, $menu->getMenuAsList());
128a25f0a04SGreg Roach	}
129a25f0a04SGreg Roach
130a25f0a04SGreg Roach	/**
131a25f0a04SGreg Roach	 * Test the list rendering for a simple link.
132a25f0a04SGreg Roach	 */
133a25f0a04SGreg Roach	public function testFormatAsList() {
134a25f0a04SGreg Roach		$menu = new Menu('Test!', 'link.html');
135a25f0a04SGreg Roach
136794c6b5bSGreg Roach		$this->assertSame('<li class=""><a href="link.html">Test!</a></li>', $menu->getMenuAsList());
137a25f0a04SGreg Roach	}
138a25f0a04SGreg Roach
139a25f0a04SGreg Roach	/**
140a25f0a04SGreg Roach	 * Test the list rendering for a simple link with a CSS ID.
141a25f0a04SGreg Roach	 */
142794c6b5bSGreg Roach	public function testFormatAsListWithClass() {
143794c6b5bSGreg Roach		$menu = new Menu('Test!', 'link.html', 'link-class');
144a25f0a04SGreg Roach
145794c6b5bSGreg Roach		$this->assertSame('<li class="link-class"><a href="link.html">Test!</a></li>', $menu->getMenuAsList());
146a25f0a04SGreg Roach	}
147a25f0a04SGreg Roach
148a25f0a04SGreg Roach	/**
149a25f0a04SGreg Roach	 * Test the list rendering for an empty target.
150a25f0a04SGreg Roach	 */
151a25f0a04SGreg Roach	public function testFormatAsListWithNoTarget() {
152a25f0a04SGreg Roach		$menu = new Menu('Test!', '');
153a25f0a04SGreg Roach
154794c6b5bSGreg Roach		$this->assertSame('<li class=""><a>Test!</a></li>', $menu->getMenuAsList());
155a25f0a04SGreg Roach	}
156a25f0a04SGreg Roach
157a25f0a04SGreg Roach	/**
158a25f0a04SGreg Roach	 * Test the list rendering for a default (hash) target.
159a25f0a04SGreg Roach	 */
160a25f0a04SGreg Roach	public function testFormatAsListWithHashTarget() {
161a25f0a04SGreg Roach		$menu = new Menu('Test!');
162a25f0a04SGreg Roach
163794c6b5bSGreg Roach		$this->assertSame('<li class=""><a href="#">Test!</a></li>', $menu->getMenuAsList());
164a25f0a04SGreg Roach	}
165a25f0a04SGreg Roach
166a25f0a04SGreg Roach	/**
167a25f0a04SGreg Roach	 * Test the list rendering for an onclick link.
168a25f0a04SGreg Roach	 */
1693cf92ae2SGreg Roach	public function testFormatAsListWithAttrs() {
17013abd6f3SGreg Roach		$menu = new Menu('Test!', '#', '', ['foo' => 'bar']);
171a25f0a04SGreg Roach
1723cf92ae2SGreg Roach		$this->assertSame('<li class=""><a href="#" foo="bar">Test!</a></li>', $menu->getMenuAsList());
173a25f0a04SGreg Roach	}
174a25f0a04SGreg Roach
175a25f0a04SGreg Roach	/**
176a25f0a04SGreg Roach	 * Test the list rendering for an onclick link.
177a25f0a04SGreg Roach	 */
1783cf92ae2SGreg Roach	public function testFormatAsListWithAttrsAndId() {
17913abd6f3SGreg Roach		$menu = new Menu('Test!', '#', 'link-class', ['foo' => 'bar']);
180a25f0a04SGreg Roach
1813cf92ae2SGreg Roach		$this->assertSame('<li class="link-class"><a href="#" foo="bar">Test!</a></li>', $menu->getMenuAsList());
182a25f0a04SGreg Roach	}
183a25f0a04SGreg Roach}
184