xref: /webtrees/tests/app/MenuTest.php (revision e7f56f2af615447ab1a7646851f88b465ace9e04)
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 */
16*e7f56f2aSGreg Roachdeclare(strict_types=1);
17*e7f56f2aSGreg Roach
1884e2cf4eSGreg Roachnamespace Fisharebest\Webtrees;
19a25f0a04SGreg Roach
200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Menu;
21a25f0a04SGreg Roach
22a25f0a04SGreg Roach/**
23a25f0a04SGreg Roach * Test harness for the class Menu
24a25f0a04SGreg Roach */
2584e2cf4eSGreg Roachclass MenuTest extends \Fisharebest\Webtrees\TestCase
26c1010edaSGreg Roach{
27a25f0a04SGreg Roach    /**
28a25f0a04SGreg Roach     * Prepare the environment for these tests.
2952348eb8SGreg Roach     *
3052348eb8SGreg Roach     * @return void
31a25f0a04SGreg Roach     */
32c1010edaSGreg Roach    public function setUp()
33c1010edaSGreg Roach    {
34a25f0a04SGreg Roach    }
35a25f0a04SGreg Roach
36a25f0a04SGreg Roach    /**
37a25f0a04SGreg Roach     * Test the constructor with default parameters.
3818d7a90dSGreg Roach     *
3918d7a90dSGreg Roach     * @return void
40a25f0a04SGreg Roach     */
41c1010edaSGreg Roach    public function testConstructorDefaults()
42c1010edaSGreg Roach    {
43a25f0a04SGreg Roach        $menu = new Menu('Test!');
44a25f0a04SGreg Roach
45a25f0a04SGreg Roach        $this->assertSame('Test!', $menu->getLabel());
46a25f0a04SGreg Roach        $this->assertSame('#', $menu->getLink());
477820e4d7SGreg Roach        $this->assertSame('', $menu->getClass());
4813abd6f3SGreg Roach        $this->assertSame([], $menu->getAttrs());
4913abd6f3SGreg Roach        $this->assertSame([], $menu->getSubmenus());
50a25f0a04SGreg Roach    }
51a25f0a04SGreg Roach
52a25f0a04SGreg Roach    /**
53a25f0a04SGreg Roach     * Test the constructor with non-default parameters.
5418d7a90dSGreg Roach     *
5518d7a90dSGreg Roach     * @return void
56a25f0a04SGreg Roach     */
57c1010edaSGreg Roach    public function testConstructorNonDefaults()
58c1010edaSGreg Roach    {
5913abd6f3SGreg Roach        $submenus = [new Menu('Submenu')];
6013abd6f3SGreg Roach        $menu     = new Menu('Test!', 'link.html', 'link-class', ['foo' => 'bar'], $submenus);
61a25f0a04SGreg Roach
62a25f0a04SGreg Roach        $this->assertSame('Test!', $menu->getLabel());
63a25f0a04SGreg Roach        $this->assertSame('link.html', $menu->getLink());
64794c6b5bSGreg Roach        $this->assertSame('link-class', $menu->getClass());
6513abd6f3SGreg Roach        $this->assertSame(['foo' => 'bar'], $menu->getAttrs());
66a25f0a04SGreg Roach        $this->assertSame($submenus, $menu->getSubmenus());
67a25f0a04SGreg Roach    }
68a25f0a04SGreg Roach
69a25f0a04SGreg Roach    /**
70a25f0a04SGreg Roach     * Test the getter/setter for the label.
7118d7a90dSGreg Roach     *
7218d7a90dSGreg Roach     * @return void
73a25f0a04SGreg Roach     */
74c1010edaSGreg Roach    public function testGetterSetterLabel()
75c1010edaSGreg Roach    {
76a25f0a04SGreg Roach        $menu = new Menu('Test!');
77a25f0a04SGreg Roach
78a25f0a04SGreg Roach        $return = $menu->setLabel('Label');
79a25f0a04SGreg Roach
80a25f0a04SGreg Roach        $this->assertSame($return, $menu);
81a25f0a04SGreg Roach        $this->assertSame('Label', $menu->getLabel());
82a25f0a04SGreg Roach    }
83a25f0a04SGreg Roach
84a25f0a04SGreg Roach    /**
85a25f0a04SGreg Roach     * Test the getter/setter for the link.
8618d7a90dSGreg Roach     *
8718d7a90dSGreg Roach     * @return void
88a25f0a04SGreg Roach     */
89c1010edaSGreg Roach    public function testGetterSetterLink()
90c1010edaSGreg Roach    {
91a25f0a04SGreg Roach        $menu = new Menu('Test!');
92a25f0a04SGreg Roach
93a25f0a04SGreg Roach        $return = $menu->setLink('link.html');
94a25f0a04SGreg Roach
95a25f0a04SGreg Roach        $this->assertSame($return, $menu);
96a25f0a04SGreg Roach        $this->assertSame('link.html', $menu->getLink());
97a25f0a04SGreg Roach    }
98a25f0a04SGreg Roach
99a25f0a04SGreg Roach    /**
100a25f0a04SGreg Roach     * Test the getter/setter for the ID.
10118d7a90dSGreg Roach     *
10218d7a90dSGreg Roach     * @return void
103a25f0a04SGreg Roach     */
104c1010edaSGreg Roach    public function testGetterSetterId()
105c1010edaSGreg Roach    {
106a25f0a04SGreg Roach        $menu = new Menu('Test!');
107a25f0a04SGreg Roach
108794c6b5bSGreg Roach        $return = $menu->setClass('link-class');
109a25f0a04SGreg Roach
110a25f0a04SGreg Roach        $this->assertSame($return, $menu);
111794c6b5bSGreg Roach        $this->assertSame('link-class', $menu->getClass());
112a25f0a04SGreg Roach    }
113a25f0a04SGreg Roach
114a25f0a04SGreg Roach    /**
1153cf92ae2SGreg Roach     * Test the getter/setter for the Attrs event.
11618d7a90dSGreg Roach     *
11718d7a90dSGreg Roach     * @return void
118a25f0a04SGreg Roach     */
119c1010edaSGreg Roach    public function testGetterSetterAttrs()
120c1010edaSGreg Roach    {
121a25f0a04SGreg Roach        $menu = new Menu('Test!');
122a25f0a04SGreg Roach
12313abd6f3SGreg Roach        $return = $menu->setAttrs(['foo' => 'bar']);
124a25f0a04SGreg Roach
125a25f0a04SGreg Roach        $this->assertSame($return, $menu);
12613abd6f3SGreg Roach        $this->assertSame(['foo' => 'bar'], $menu->getAttrs());
127a25f0a04SGreg Roach    }
128a25f0a04SGreg Roach
129a25f0a04SGreg Roach    /**
130a25f0a04SGreg Roach     * Test the getter/setter for the submenus.
13118d7a90dSGreg Roach     *
13218d7a90dSGreg Roach     * @return void
133a25f0a04SGreg Roach     */
134c1010edaSGreg Roach    public function testGetterSetterSubmenus()
135c1010edaSGreg Roach    {
136a25f0a04SGreg Roach        $menu     = new Menu('Test!');
13713abd6f3SGreg Roach        $submenus = [
138a25f0a04SGreg Roach            new Menu('Sub1'),
139a25f0a04SGreg Roach            new Menu('Sub2'),
14013abd6f3SGreg Roach        ];
141a25f0a04SGreg Roach
142a25f0a04SGreg Roach        $return = $menu->setSubmenus($submenus);
143a25f0a04SGreg Roach
144a25f0a04SGreg Roach        $this->assertSame($return, $menu);
145a25f0a04SGreg Roach        $this->assertSame($submenus, $menu->getSubmenus());
146a25f0a04SGreg Roach    }
147a25f0a04SGreg Roach
148a25f0a04SGreg Roach    /**
149a25f0a04SGreg Roach     * Test the list rendering for a simple link.
15018d7a90dSGreg Roach     *
15118d7a90dSGreg Roach     * @return void
152a25f0a04SGreg Roach     */
153c1010edaSGreg Roach    public function testFormatAsList()
154c1010edaSGreg Roach    {
155a25f0a04SGreg Roach        $menu = new Menu('Test!', 'link.html');
156a25f0a04SGreg Roach
157794c6b5bSGreg 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.
16218d7a90dSGreg Roach     *
16318d7a90dSGreg Roach     * @return void
164a25f0a04SGreg Roach     */
165c1010edaSGreg Roach    public function testFormatAsListWithClass()
166c1010edaSGreg Roach    {
167794c6b5bSGreg Roach        $menu = new Menu('Test!', 'link.html', 'link-class');
168a25f0a04SGreg Roach
169794c6b5bSGreg Roach        $this->assertSame('<li class="link-class"><a href="link.html">Test!</a></li>', $menu->getMenuAsList());
170a25f0a04SGreg Roach    }
171a25f0a04SGreg Roach
172a25f0a04SGreg Roach    /**
173a25f0a04SGreg Roach     * Test the list rendering for an empty target.
17418d7a90dSGreg Roach     *
17518d7a90dSGreg Roach     * @return void
176a25f0a04SGreg Roach     */
177c1010edaSGreg Roach    public function testFormatAsListWithNoTarget()
178c1010edaSGreg Roach    {
179a25f0a04SGreg Roach        $menu = new Menu('Test!', '');
180a25f0a04SGreg Roach
181794c6b5bSGreg Roach        $this->assertSame('<li class=""><a>Test!</a></li>', $menu->getMenuAsList());
182a25f0a04SGreg Roach    }
183a25f0a04SGreg Roach
184a25f0a04SGreg Roach    /**
185a25f0a04SGreg Roach     * Test the list rendering for a default (hash) target.
18618d7a90dSGreg Roach     *
18718d7a90dSGreg Roach     * @return void
188a25f0a04SGreg Roach     */
189c1010edaSGreg Roach    public function testFormatAsListWithHashTarget()
190c1010edaSGreg Roach    {
191a25f0a04SGreg Roach        $menu = new Menu('Test!');
192a25f0a04SGreg Roach
193794c6b5bSGreg Roach        $this->assertSame('<li class=""><a href="#">Test!</a></li>', $menu->getMenuAsList());
194a25f0a04SGreg Roach    }
195a25f0a04SGreg Roach
196a25f0a04SGreg Roach    /**
197a25f0a04SGreg Roach     * Test the list rendering for an onclick link.
19818d7a90dSGreg Roach     *
19918d7a90dSGreg Roach     * @return void
200a25f0a04SGreg Roach     */
201c1010edaSGreg Roach    public function testFormatAsListWithAttrs()
202c1010edaSGreg Roach    {
20313abd6f3SGreg Roach        $menu = new Menu('Test!', '#', '', ['foo' => 'bar']);
204a25f0a04SGreg Roach
2053cf92ae2SGreg Roach        $this->assertSame('<li class=""><a href="#" foo="bar">Test!</a></li>', $menu->getMenuAsList());
206a25f0a04SGreg Roach    }
207a25f0a04SGreg Roach
208a25f0a04SGreg Roach    /**
209a25f0a04SGreg Roach     * Test the list rendering for an onclick link.
21018d7a90dSGreg Roach     *
21118d7a90dSGreg Roach     * @return void
212a25f0a04SGreg Roach     */
213c1010edaSGreg Roach    public function testFormatAsListWithAttrsAndId()
214c1010edaSGreg Roach    {
21513abd6f3SGreg Roach        $menu = new Menu('Test!', '#', 'link-class', ['foo' => 'bar']);
216a25f0a04SGreg Roach
2173cf92ae2SGreg Roach        $this->assertSame('<li class="link-class"><a href="#" foo="bar">Test!</a></li>', $menu->getMenuAsList());
218a25f0a04SGreg Roach    }
219a25f0a04SGreg Roach}
220