xref: /webtrees/tests/app/MenuTest.php (revision 794c6b5bab6a53026b81af1c5dd73b8d9e74d406)
1a25f0a04SGreg Roach<?php
2dd04c183SGreg Roachnamespace Fisharebest\Webtrees;
3a25f0a04SGreg Roach
4a25f0a04SGreg Roach/**
5a25f0a04SGreg Roach * webtrees: online genealogy
6a25f0a04SGreg Roach * Copyright (C) 2015 webtrees development team
7a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify
8a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by
9a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or
10a25f0a04SGreg Roach * (at your option) any later version.
11a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful,
12a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
13a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14a25f0a04SGreg Roach * GNU General Public License for more details.
15a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License
16a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
17a25f0a04SGreg Roach */
18a25f0a04SGreg Roach
19a25f0a04SGreg Roachuse PHPUnit_Framework_TestCase;
20a25f0a04SGreg Roach
21a25f0a04SGreg Roach/**
22a25f0a04SGreg Roach * Test harness for the class Menu
23a25f0a04SGreg Roach */
24a25f0a04SGreg Roachclass MenuTest extends PHPUnit_Framework_TestCase {
25a25f0a04SGreg Roach	/**
26a25f0a04SGreg Roach	 * Prepare the environment for these tests.
27a25f0a04SGreg Roach	 *
28a25f0a04SGreg Roach	 * @return void
29a25f0a04SGreg Roach	 */
30a25f0a04SGreg Roach	public function setUp() {
31a25f0a04SGreg Roach	}
32a25f0a04SGreg Roach
33a25f0a04SGreg Roach	/**
34a25f0a04SGreg Roach	 * Test the constructor with default parameters.
35a25f0a04SGreg Roach	 *
36a25f0a04SGreg Roach	 * @return void
37a25f0a04SGreg Roach	 */
38a25f0a04SGreg Roach	public function testConstructorDefaults() {
39a25f0a04SGreg Roach		$menu = new Menu('Test!');
40a25f0a04SGreg Roach
41a25f0a04SGreg Roach		$this->assertSame('Test!', $menu->getLabel());
42a25f0a04SGreg Roach		$this->assertSame('#', $menu->getLink());
43*794c6b5bSGreg Roach		$this->assertSame('', $menu->getCLass());
44a25f0a04SGreg Roach		$this->assertSame('', $menu->getOnclick());
45a25f0a04SGreg Roach		$this->assertSame(array(), $menu->getSubmenus());
46a25f0a04SGreg Roach	}
47a25f0a04SGreg Roach
48a25f0a04SGreg Roach	/**
49a25f0a04SGreg Roach	 * Test the constructor with non-default parameters.
50a25f0a04SGreg Roach	 *
51a25f0a04SGreg Roach	 * @return void
52a25f0a04SGreg Roach	 */
53a25f0a04SGreg Roach	public function testConstructorNonDefaults() {
54a25f0a04SGreg Roach		$submenus = array(new Menu('Submenu'));
55*794c6b5bSGreg Roach		$menu = new Menu('Test!', 'link.html', 'link-class', 'test();', $submenus);
56a25f0a04SGreg Roach
57a25f0a04SGreg Roach		$this->assertSame('Test!', $menu->getLabel());
58a25f0a04SGreg Roach		$this->assertSame('link.html', $menu->getLink());
59*794c6b5bSGreg Roach		$this->assertSame('link-class', $menu->getClass());
60a25f0a04SGreg Roach		$this->assertSame('test();', $menu->getOnclick());
61a25f0a04SGreg Roach		$this->assertSame($submenus, $menu->getSubmenus());
62a25f0a04SGreg Roach	}
63a25f0a04SGreg Roach
64a25f0a04SGreg Roach	/**
65a25f0a04SGreg Roach	 * Test the getter/setter for the label.
66a25f0a04SGreg Roach	 *
67a25f0a04SGreg Roach	 * @return void
68a25f0a04SGreg Roach	 */
69a25f0a04SGreg Roach	public function testGetterSetterLabel() {
70a25f0a04SGreg Roach		$menu = new Menu('Test!');
71a25f0a04SGreg Roach
72a25f0a04SGreg Roach		$return = $menu->setLabel('Label');
73a25f0a04SGreg Roach
74a25f0a04SGreg Roach		$this->assertSame($return, $menu);
75a25f0a04SGreg Roach		$this->assertSame('Label', $menu->getLabel());
76a25f0a04SGreg Roach	}
77a25f0a04SGreg Roach
78a25f0a04SGreg Roach	/**
79a25f0a04SGreg Roach	 * Test the getter/setter for the link.
80a25f0a04SGreg Roach	 *
81a25f0a04SGreg Roach	 * @return void
82a25f0a04SGreg Roach	 */
83a25f0a04SGreg Roach	public function testGetterSetterLink() {
84a25f0a04SGreg Roach		$menu = new Menu('Test!');
85a25f0a04SGreg Roach
86a25f0a04SGreg Roach		$return = $menu->setLink('link.html');
87a25f0a04SGreg Roach
88a25f0a04SGreg Roach		$this->assertSame($return, $menu);
89a25f0a04SGreg Roach		$this->assertSame('link.html', $menu->getLink());
90a25f0a04SGreg Roach	}
91a25f0a04SGreg Roach
92a25f0a04SGreg Roach	/**
93a25f0a04SGreg Roach	 * Test the getter/setter for the ID.
94a25f0a04SGreg Roach	 *
95a25f0a04SGreg Roach	 * @return void
96a25f0a04SGreg Roach	 */
97a25f0a04SGreg Roach	public function testGetterSetterId() {
98a25f0a04SGreg Roach		$menu = new Menu('Test!');
99a25f0a04SGreg Roach
100*794c6b5bSGreg Roach		$return = $menu->setClass('link-class');
101a25f0a04SGreg Roach
102a25f0a04SGreg Roach		$this->assertSame($return, $menu);
103*794c6b5bSGreg Roach		$this->assertSame('link-class', $menu->getClass());
104a25f0a04SGreg Roach	}
105a25f0a04SGreg Roach
106a25f0a04SGreg Roach	/**
107a25f0a04SGreg Roach	 * Test the getter/setter for the Onclick event.
108a25f0a04SGreg Roach	 *
109a25f0a04SGreg Roach	 * @return void
110a25f0a04SGreg Roach	 */
111a25f0a04SGreg Roach	public function testGetterSetterOnclick() {
112a25f0a04SGreg Roach		$menu = new Menu('Test!');
113a25f0a04SGreg Roach
114a25f0a04SGreg Roach		$return = $menu->setOnclick('test();');
115a25f0a04SGreg Roach
116a25f0a04SGreg Roach		$this->assertSame($return, $menu);
117a25f0a04SGreg Roach		$this->assertSame('test();', $menu->getOnclick());
118a25f0a04SGreg Roach	}
119a25f0a04SGreg Roach
120a25f0a04SGreg Roach	/**
121a25f0a04SGreg Roach	 * Test the getter/setter for the submenus.
122a25f0a04SGreg Roach	 *
123a25f0a04SGreg Roach	 * @return void
124a25f0a04SGreg Roach	 */
125a25f0a04SGreg Roach	public function testGetterSetterSubmenus() {
126a25f0a04SGreg Roach		$menu = new Menu('Test!');
127a25f0a04SGreg Roach		$submenus = array(
128a25f0a04SGreg Roach			new Menu('Sub1'),
129a25f0a04SGreg Roach			new Menu('Sub2'),
130a25f0a04SGreg Roach		);
131a25f0a04SGreg Roach
132a25f0a04SGreg Roach		$return = $menu->setSubmenus($submenus);
133a25f0a04SGreg Roach
134a25f0a04SGreg Roach		$this->assertSame($return, $menu);
135a25f0a04SGreg Roach		$this->assertSame($submenus, $menu->getSubmenus());
136a25f0a04SGreg Roach	}
137a25f0a04SGreg Roach
138a25f0a04SGreg Roach	/**
139a25f0a04SGreg Roach	 * Test the string cast.
140a25f0a04SGreg Roach	 *
141a25f0a04SGreg Roach	 * @return void
142a25f0a04SGreg Roach	 */
143a25f0a04SGreg Roach	public function testStringCast() {
144a25f0a04SGreg Roach		$menu = new Menu('Test!');
145a25f0a04SGreg Roach
146a25f0a04SGreg Roach		$this->assertSame((string)$menu, $menu->getMenuAsList());
147a25f0a04SGreg Roach	}
148a25f0a04SGreg Roach
149a25f0a04SGreg Roach	/**
150a25f0a04SGreg Roach	 * Test the list rendering for a simple link.
151a25f0a04SGreg Roach	 *
152a25f0a04SGreg Roach	 * @return void
153a25f0a04SGreg Roach	 */
154a25f0a04SGreg Roach	public function testFormatAsList() {
155a25f0a04SGreg Roach		$menu = new Menu('Test!', 'link.html');
156a25f0a04SGreg Roach
157*794c6b5bSGreg Roach		$this->assertSame('<li class=""><a href="link.html">Test!</a></li>', $menu->getMenuAsList());
158a25f0a04SGreg Roach	}
159a25f0a04SGreg Roach
160a25f0a04SGreg Roach	/**
161a25f0a04SGreg Roach	 * Test the list rendering for a simple link with a CSS ID.
162a25f0a04SGreg Roach	 *
163a25f0a04SGreg Roach	 * @return void
164a25f0a04SGreg Roach	 */
165*794c6b5bSGreg Roach	public function testFormatAsListWithClass() {
166*794c6b5bSGreg Roach		$menu = new Menu('Test!', 'link.html', 'link-class');
167a25f0a04SGreg Roach
168*794c6b5bSGreg Roach		$this->assertSame('<li class="link-class"><a href="link.html">Test!</a></li>', $menu->getMenuAsList());
169a25f0a04SGreg Roach	}
170a25f0a04SGreg Roach
171a25f0a04SGreg Roach	/**
172a25f0a04SGreg Roach	 * Test the list rendering for an empty target.
173a25f0a04SGreg Roach	 *
174a25f0a04SGreg Roach	 * @return void
175a25f0a04SGreg Roach	 */
176a25f0a04SGreg Roach	public function testFormatAsListWithNoTarget() {
177a25f0a04SGreg Roach		$menu = new Menu('Test!', '');
178a25f0a04SGreg Roach
179*794c6b5bSGreg Roach		$this->assertSame('<li class=""><a>Test!</a></li>', $menu->getMenuAsList());
180a25f0a04SGreg Roach	}
181a25f0a04SGreg Roach
182a25f0a04SGreg Roach	/**
183a25f0a04SGreg Roach	 * Test the list rendering for a default (hash) target.
184a25f0a04SGreg Roach	 *
185a25f0a04SGreg Roach	 * @return void
186a25f0a04SGreg Roach	 */
187a25f0a04SGreg Roach	public function testFormatAsListWithHashTarget() {
188a25f0a04SGreg Roach		$menu = new Menu('Test!');
189a25f0a04SGreg Roach
190*794c6b5bSGreg Roach		$this->assertSame('<li class=""><a href="#">Test!</a></li>', $menu->getMenuAsList());
191a25f0a04SGreg Roach	}
192a25f0a04SGreg Roach
193a25f0a04SGreg Roach	/**
194a25f0a04SGreg Roach	 * Test the list rendering for an onclick link.
195a25f0a04SGreg Roach	 *
196a25f0a04SGreg Roach	 * @return void
197a25f0a04SGreg Roach	 */
198a25f0a04SGreg Roach	public function testFormatAsListWithOnclick() {
199a25f0a04SGreg Roach		$menu = new Menu('Test!', '#', '', 'return test();');
200a25f0a04SGreg Roach
201*794c6b5bSGreg Roach		$this->assertSame('<li class=""><a href="#" onclick="return test();">Test!</a></li>', $menu->getMenuAsList());
202a25f0a04SGreg Roach	}
203a25f0a04SGreg Roach
204a25f0a04SGreg Roach	/**
205a25f0a04SGreg Roach	 * Test the list rendering for an onclick link.
206a25f0a04SGreg Roach	 *
207a25f0a04SGreg Roach	 * @return void
208a25f0a04SGreg Roach	 */
209a25f0a04SGreg Roach	public function testFormatAsListWithOnclickAndId() {
210*794c6b5bSGreg Roach		$menu = new Menu('Test!', '#', 'link-class', 'return test();');
211a25f0a04SGreg Roach
212*794c6b5bSGreg Roach		$this->assertSame('<li class="link-class"><a href="#" onclick="return test();">Test!</a></li>', $menu->getMenuAsList());
213a25f0a04SGreg Roach	}
214a25f0a04SGreg Roach}
215