xref: /webtrees/tests/app/MenuTest.php (revision 18d7a90d8a3b33b218801c0b68eb1a5140d7b4e7)
1a25f0a04SGreg Roach<?php
2a25f0a04SGreg Roach/**
3a25f0a04SGreg Roach * webtrees: online genealogy
41062a142SGreg Roach * Copyright (C) 2018 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 */
1684e2cf4eSGreg Roachnamespace Fisharebest\Webtrees;
17a25f0a04SGreg Roach
180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Menu;
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    /**
26a25f0a04SGreg Roach     * Prepare the environment for these tests.
2752348eb8SGreg Roach     *
2852348eb8SGreg Roach     * @return void
29a25f0a04SGreg Roach     */
30c1010edaSGreg Roach    public function setUp()
31c1010edaSGreg Roach    {
32a25f0a04SGreg Roach    }
33a25f0a04SGreg Roach
34a25f0a04SGreg Roach    /**
35a25f0a04SGreg Roach     * Test the constructor with default parameters.
36*18d7a90dSGreg Roach     *
37*18d7a90dSGreg Roach     * @return void
38a25f0a04SGreg Roach     */
39c1010edaSGreg Roach    public function testConstructorDefaults()
40c1010edaSGreg Roach    {
41a25f0a04SGreg Roach        $menu = new Menu('Test!');
42a25f0a04SGreg Roach
43a25f0a04SGreg Roach        $this->assertSame('Test!', $menu->getLabel());
44a25f0a04SGreg Roach        $this->assertSame('#', $menu->getLink());
457820e4d7SGreg Roach        $this->assertSame('', $menu->getClass());
4613abd6f3SGreg Roach        $this->assertSame([], $menu->getAttrs());
4713abd6f3SGreg Roach        $this->assertSame([], $menu->getSubmenus());
48a25f0a04SGreg Roach    }
49a25f0a04SGreg Roach
50a25f0a04SGreg Roach    /**
51a25f0a04SGreg Roach     * Test the constructor with non-default parameters.
52*18d7a90dSGreg Roach     *
53*18d7a90dSGreg Roach     * @return void
54a25f0a04SGreg Roach     */
55c1010edaSGreg Roach    public function testConstructorNonDefaults()
56c1010edaSGreg Roach    {
5713abd6f3SGreg Roach        $submenus = [new Menu('Submenu')];
5813abd6f3SGreg Roach        $menu     = new Menu('Test!', 'link.html', 'link-class', ['foo' => 'bar'], $submenus);
59a25f0a04SGreg Roach
60a25f0a04SGreg Roach        $this->assertSame('Test!', $menu->getLabel());
61a25f0a04SGreg Roach        $this->assertSame('link.html', $menu->getLink());
62794c6b5bSGreg Roach        $this->assertSame('link-class', $menu->getClass());
6313abd6f3SGreg Roach        $this->assertSame(['foo' => 'bar'], $menu->getAttrs());
64a25f0a04SGreg Roach        $this->assertSame($submenus, $menu->getSubmenus());
65a25f0a04SGreg Roach    }
66a25f0a04SGreg Roach
67a25f0a04SGreg Roach    /**
68a25f0a04SGreg Roach     * Test the getter/setter for the label.
69*18d7a90dSGreg Roach     *
70*18d7a90dSGreg Roach     * @return void
71a25f0a04SGreg Roach     */
72c1010edaSGreg Roach    public function testGetterSetterLabel()
73c1010edaSGreg Roach    {
74a25f0a04SGreg Roach        $menu = new Menu('Test!');
75a25f0a04SGreg Roach
76a25f0a04SGreg Roach        $return = $menu->setLabel('Label');
77a25f0a04SGreg Roach
78a25f0a04SGreg Roach        $this->assertSame($return, $menu);
79a25f0a04SGreg Roach        $this->assertSame('Label', $menu->getLabel());
80a25f0a04SGreg Roach    }
81a25f0a04SGreg Roach
82a25f0a04SGreg Roach    /**
83a25f0a04SGreg Roach     * Test the getter/setter for the link.
84*18d7a90dSGreg Roach     *
85*18d7a90dSGreg Roach     * @return void
86a25f0a04SGreg Roach     */
87c1010edaSGreg Roach    public function testGetterSetterLink()
88c1010edaSGreg Roach    {
89a25f0a04SGreg Roach        $menu = new Menu('Test!');
90a25f0a04SGreg Roach
91a25f0a04SGreg Roach        $return = $menu->setLink('link.html');
92a25f0a04SGreg Roach
93a25f0a04SGreg Roach        $this->assertSame($return, $menu);
94a25f0a04SGreg Roach        $this->assertSame('link.html', $menu->getLink());
95a25f0a04SGreg Roach    }
96a25f0a04SGreg Roach
97a25f0a04SGreg Roach    /**
98a25f0a04SGreg Roach     * Test the getter/setter for the ID.
99*18d7a90dSGreg Roach     *
100*18d7a90dSGreg Roach     * @return void
101a25f0a04SGreg Roach     */
102c1010edaSGreg Roach    public function testGetterSetterId()
103c1010edaSGreg Roach    {
104a25f0a04SGreg Roach        $menu = new Menu('Test!');
105a25f0a04SGreg Roach
106794c6b5bSGreg Roach        $return = $menu->setClass('link-class');
107a25f0a04SGreg Roach
108a25f0a04SGreg Roach        $this->assertSame($return, $menu);
109794c6b5bSGreg Roach        $this->assertSame('link-class', $menu->getClass());
110a25f0a04SGreg Roach    }
111a25f0a04SGreg Roach
112a25f0a04SGreg Roach    /**
1133cf92ae2SGreg Roach     * Test the getter/setter for the Attrs event.
114*18d7a90dSGreg Roach     *
115*18d7a90dSGreg Roach     * @return void
116a25f0a04SGreg Roach     */
117c1010edaSGreg Roach    public function testGetterSetterAttrs()
118c1010edaSGreg Roach    {
119a25f0a04SGreg Roach        $menu = new Menu('Test!');
120a25f0a04SGreg Roach
12113abd6f3SGreg Roach        $return = $menu->setAttrs(['foo' => 'bar']);
122a25f0a04SGreg Roach
123a25f0a04SGreg Roach        $this->assertSame($return, $menu);
12413abd6f3SGreg Roach        $this->assertSame(['foo' => 'bar'], $menu->getAttrs());
125a25f0a04SGreg Roach    }
126a25f0a04SGreg Roach
127a25f0a04SGreg Roach    /**
128a25f0a04SGreg Roach     * Test the getter/setter for the submenus.
129*18d7a90dSGreg Roach     *
130*18d7a90dSGreg Roach     * @return void
131a25f0a04SGreg Roach     */
132c1010edaSGreg Roach    public function testGetterSetterSubmenus()
133c1010edaSGreg Roach    {
134a25f0a04SGreg Roach        $menu     = new Menu('Test!');
13513abd6f3SGreg Roach        $submenus = [
136a25f0a04SGreg Roach            new Menu('Sub1'),
137a25f0a04SGreg Roach            new Menu('Sub2'),
13813abd6f3SGreg Roach        ];
139a25f0a04SGreg Roach
140a25f0a04SGreg Roach        $return = $menu->setSubmenus($submenus);
141a25f0a04SGreg Roach
142a25f0a04SGreg Roach        $this->assertSame($return, $menu);
143a25f0a04SGreg Roach        $this->assertSame($submenus, $menu->getSubmenus());
144a25f0a04SGreg Roach    }
145a25f0a04SGreg Roach
146a25f0a04SGreg Roach    /**
147a25f0a04SGreg Roach     * Test the list rendering for a simple link.
148*18d7a90dSGreg Roach     *
149*18d7a90dSGreg Roach     * @return void
150a25f0a04SGreg Roach     */
151c1010edaSGreg Roach    public function testFormatAsList()
152c1010edaSGreg Roach    {
153a25f0a04SGreg Roach        $menu = new Menu('Test!', 'link.html');
154a25f0a04SGreg Roach
155794c6b5bSGreg Roach        $this->assertSame('<li class=""><a href="link.html">Test!</a></li>', $menu->getMenuAsList());
156a25f0a04SGreg Roach    }
157a25f0a04SGreg Roach
158a25f0a04SGreg Roach    /**
159a25f0a04SGreg Roach     * Test the list rendering for a simple link with a CSS ID.
160*18d7a90dSGreg Roach     *
161*18d7a90dSGreg Roach     * @return void
162a25f0a04SGreg Roach     */
163c1010edaSGreg Roach    public function testFormatAsListWithClass()
164c1010edaSGreg Roach    {
165794c6b5bSGreg Roach        $menu = new Menu('Test!', 'link.html', 'link-class');
166a25f0a04SGreg Roach
167794c6b5bSGreg Roach        $this->assertSame('<li class="link-class"><a href="link.html">Test!</a></li>', $menu->getMenuAsList());
168a25f0a04SGreg Roach    }
169a25f0a04SGreg Roach
170a25f0a04SGreg Roach    /**
171a25f0a04SGreg Roach     * Test the list rendering for an empty target.
172*18d7a90dSGreg Roach     *
173*18d7a90dSGreg Roach     * @return void
174a25f0a04SGreg Roach     */
175c1010edaSGreg Roach    public function testFormatAsListWithNoTarget()
176c1010edaSGreg Roach    {
177a25f0a04SGreg Roach        $menu = new Menu('Test!', '');
178a25f0a04SGreg Roach
179794c6b5bSGreg 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.
184*18d7a90dSGreg Roach     *
185*18d7a90dSGreg Roach     * @return void
186a25f0a04SGreg Roach     */
187c1010edaSGreg Roach    public function testFormatAsListWithHashTarget()
188c1010edaSGreg Roach    {
189a25f0a04SGreg Roach        $menu = new Menu('Test!');
190a25f0a04SGreg Roach
191794c6b5bSGreg Roach        $this->assertSame('<li class=""><a href="#">Test!</a></li>', $menu->getMenuAsList());
192a25f0a04SGreg Roach    }
193a25f0a04SGreg Roach
194a25f0a04SGreg Roach    /**
195a25f0a04SGreg Roach     * Test the list rendering for an onclick link.
196*18d7a90dSGreg Roach     *
197*18d7a90dSGreg Roach     * @return void
198a25f0a04SGreg Roach     */
199c1010edaSGreg Roach    public function testFormatAsListWithAttrs()
200c1010edaSGreg Roach    {
20113abd6f3SGreg Roach        $menu = new Menu('Test!', '#', '', ['foo' => 'bar']);
202a25f0a04SGreg Roach
2033cf92ae2SGreg Roach        $this->assertSame('<li class=""><a href="#" foo="bar">Test!</a></li>', $menu->getMenuAsList());
204a25f0a04SGreg Roach    }
205a25f0a04SGreg Roach
206a25f0a04SGreg Roach    /**
207a25f0a04SGreg Roach     * Test the list rendering for an onclick link.
208*18d7a90dSGreg Roach     *
209*18d7a90dSGreg Roach     * @return void
210a25f0a04SGreg Roach     */
211c1010edaSGreg Roach    public function testFormatAsListWithAttrsAndId()
212c1010edaSGreg Roach    {
21313abd6f3SGreg Roach        $menu = new Menu('Test!', '#', 'link-class', ['foo' => 'bar']);
214a25f0a04SGreg Roach
2153cf92ae2SGreg Roach        $this->assertSame('<li class="link-class"><a href="#" foo="bar">Test!</a></li>', $menu->getMenuAsList());
216a25f0a04SGreg Roach    }
217a25f0a04SGreg Roach}
218