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