xref: /webtrees/tests/app/MenuTest.php (revision 52348eb8c11b06a8488e13475e6561273832716a)
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.
27*52348eb8SGreg Roach     *
28*52348eb8SGreg 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.
36a25f0a04SGreg Roach     */
37c1010edaSGreg Roach    public function testConstructorDefaults()
38c1010edaSGreg Roach    {
39a25f0a04SGreg Roach        $menu = new Menu('Test!');
40a25f0a04SGreg Roach
41a25f0a04SGreg Roach        $this->assertSame('Test!', $menu->getLabel());
42a25f0a04SGreg Roach        $this->assertSame('#', $menu->getLink());
437820e4d7SGreg Roach        $this->assertSame('', $menu->getClass());
4413abd6f3SGreg Roach        $this->assertSame([], $menu->getAttrs());
4513abd6f3SGreg Roach        $this->assertSame([], $menu->getSubmenus());
46a25f0a04SGreg Roach    }
47a25f0a04SGreg Roach
48a25f0a04SGreg Roach    /**
49a25f0a04SGreg Roach     * Test the constructor with non-default parameters.
50a25f0a04SGreg Roach     */
51c1010edaSGreg Roach    public function testConstructorNonDefaults()
52c1010edaSGreg Roach    {
5313abd6f3SGreg Roach        $submenus = [new Menu('Submenu')];
5413abd6f3SGreg Roach        $menu     = new Menu('Test!', 'link.html', 'link-class', ['foo' => 'bar'], $submenus);
55a25f0a04SGreg Roach
56a25f0a04SGreg Roach        $this->assertSame('Test!', $menu->getLabel());
57a25f0a04SGreg Roach        $this->assertSame('link.html', $menu->getLink());
58794c6b5bSGreg Roach        $this->assertSame('link-class', $menu->getClass());
5913abd6f3SGreg Roach        $this->assertSame(['foo' => 'bar'], $menu->getAttrs());
60a25f0a04SGreg Roach        $this->assertSame($submenus, $menu->getSubmenus());
61a25f0a04SGreg Roach    }
62a25f0a04SGreg Roach
63a25f0a04SGreg Roach    /**
64a25f0a04SGreg Roach     * Test the getter/setter for the label.
65a25f0a04SGreg Roach     */
66c1010edaSGreg Roach    public function testGetterSetterLabel()
67c1010edaSGreg Roach    {
68a25f0a04SGreg Roach        $menu = new Menu('Test!');
69a25f0a04SGreg Roach
70a25f0a04SGreg Roach        $return = $menu->setLabel('Label');
71a25f0a04SGreg Roach
72a25f0a04SGreg Roach        $this->assertSame($return, $menu);
73a25f0a04SGreg Roach        $this->assertSame('Label', $menu->getLabel());
74a25f0a04SGreg Roach    }
75a25f0a04SGreg Roach
76a25f0a04SGreg Roach    /**
77a25f0a04SGreg Roach     * Test the getter/setter for the link.
78a25f0a04SGreg Roach     */
79c1010edaSGreg Roach    public function testGetterSetterLink()
80c1010edaSGreg Roach    {
81a25f0a04SGreg Roach        $menu = new Menu('Test!');
82a25f0a04SGreg Roach
83a25f0a04SGreg Roach        $return = $menu->setLink('link.html');
84a25f0a04SGreg Roach
85a25f0a04SGreg Roach        $this->assertSame($return, $menu);
86a25f0a04SGreg Roach        $this->assertSame('link.html', $menu->getLink());
87a25f0a04SGreg Roach    }
88a25f0a04SGreg Roach
89a25f0a04SGreg Roach    /**
90a25f0a04SGreg Roach     * Test the getter/setter for the ID.
91a25f0a04SGreg Roach     */
92c1010edaSGreg Roach    public function testGetterSetterId()
93c1010edaSGreg Roach    {
94a25f0a04SGreg Roach        $menu = new Menu('Test!');
95a25f0a04SGreg Roach
96794c6b5bSGreg Roach        $return = $menu->setClass('link-class');
97a25f0a04SGreg Roach
98a25f0a04SGreg Roach        $this->assertSame($return, $menu);
99794c6b5bSGreg Roach        $this->assertSame('link-class', $menu->getClass());
100a25f0a04SGreg Roach    }
101a25f0a04SGreg Roach
102a25f0a04SGreg Roach    /**
1033cf92ae2SGreg Roach     * Test the getter/setter for the Attrs event.
104a25f0a04SGreg Roach     */
105c1010edaSGreg Roach    public function testGetterSetterAttrs()
106c1010edaSGreg Roach    {
107a25f0a04SGreg Roach        $menu = new Menu('Test!');
108a25f0a04SGreg Roach
10913abd6f3SGreg Roach        $return = $menu->setAttrs(['foo' => 'bar']);
110a25f0a04SGreg Roach
111a25f0a04SGreg Roach        $this->assertSame($return, $menu);
11213abd6f3SGreg Roach        $this->assertSame(['foo' => 'bar'], $menu->getAttrs());
113a25f0a04SGreg Roach    }
114a25f0a04SGreg Roach
115a25f0a04SGreg Roach    /**
116a25f0a04SGreg Roach     * Test the getter/setter for the submenus.
117a25f0a04SGreg Roach     */
118c1010edaSGreg Roach    public function testGetterSetterSubmenus()
119c1010edaSGreg Roach    {
120a25f0a04SGreg Roach        $menu     = new Menu('Test!');
12113abd6f3SGreg Roach        $submenus = [
122a25f0a04SGreg Roach            new Menu('Sub1'),
123a25f0a04SGreg Roach            new Menu('Sub2'),
12413abd6f3SGreg Roach        ];
125a25f0a04SGreg Roach
126a25f0a04SGreg Roach        $return = $menu->setSubmenus($submenus);
127a25f0a04SGreg Roach
128a25f0a04SGreg Roach        $this->assertSame($return, $menu);
129a25f0a04SGreg Roach        $this->assertSame($submenus, $menu->getSubmenus());
130a25f0a04SGreg Roach    }
131a25f0a04SGreg Roach
132a25f0a04SGreg Roach    /**
133a25f0a04SGreg Roach     * Test the list rendering for a simple link.
134a25f0a04SGreg Roach     */
135c1010edaSGreg Roach    public function testFormatAsList()
136c1010edaSGreg Roach    {
137a25f0a04SGreg Roach        $menu = new Menu('Test!', 'link.html');
138a25f0a04SGreg Roach
139794c6b5bSGreg Roach        $this->assertSame('<li class=""><a href="link.html">Test!</a></li>', $menu->getMenuAsList());
140a25f0a04SGreg Roach    }
141a25f0a04SGreg Roach
142a25f0a04SGreg Roach    /**
143a25f0a04SGreg Roach     * Test the list rendering for a simple link with a CSS ID.
144a25f0a04SGreg Roach     */
145c1010edaSGreg Roach    public function testFormatAsListWithClass()
146c1010edaSGreg Roach    {
147794c6b5bSGreg Roach        $menu = new Menu('Test!', 'link.html', 'link-class');
148a25f0a04SGreg Roach
149794c6b5bSGreg Roach        $this->assertSame('<li class="link-class"><a href="link.html">Test!</a></li>', $menu->getMenuAsList());
150a25f0a04SGreg Roach    }
151a25f0a04SGreg Roach
152a25f0a04SGreg Roach    /**
153a25f0a04SGreg Roach     * Test the list rendering for an empty target.
154a25f0a04SGreg Roach     */
155c1010edaSGreg Roach    public function testFormatAsListWithNoTarget()
156c1010edaSGreg Roach    {
157a25f0a04SGreg Roach        $menu = new Menu('Test!', '');
158a25f0a04SGreg Roach
159794c6b5bSGreg Roach        $this->assertSame('<li class=""><a>Test!</a></li>', $menu->getMenuAsList());
160a25f0a04SGreg Roach    }
161a25f0a04SGreg Roach
162a25f0a04SGreg Roach    /**
163a25f0a04SGreg Roach     * Test the list rendering for a default (hash) target.
164a25f0a04SGreg Roach     */
165c1010edaSGreg Roach    public function testFormatAsListWithHashTarget()
166c1010edaSGreg Roach    {
167a25f0a04SGreg Roach        $menu = new Menu('Test!');
168a25f0a04SGreg Roach
169794c6b5bSGreg Roach        $this->assertSame('<li class=""><a href="#">Test!</a></li>', $menu->getMenuAsList());
170a25f0a04SGreg Roach    }
171a25f0a04SGreg Roach
172a25f0a04SGreg Roach    /**
173a25f0a04SGreg Roach     * Test the list rendering for an onclick link.
174a25f0a04SGreg Roach     */
175c1010edaSGreg Roach    public function testFormatAsListWithAttrs()
176c1010edaSGreg Roach    {
17713abd6f3SGreg Roach        $menu = new Menu('Test!', '#', '', ['foo' => 'bar']);
178a25f0a04SGreg Roach
1793cf92ae2SGreg Roach        $this->assertSame('<li class=""><a href="#" foo="bar">Test!</a></li>', $menu->getMenuAsList());
180a25f0a04SGreg Roach    }
181a25f0a04SGreg Roach
182a25f0a04SGreg Roach    /**
183a25f0a04SGreg Roach     * Test the list rendering for an onclick link.
184a25f0a04SGreg Roach     */
185c1010edaSGreg Roach    public function testFormatAsListWithAttrsAndId()
186c1010edaSGreg Roach    {
18713abd6f3SGreg Roach        $menu = new Menu('Test!', '#', 'link-class', ['foo' => 'bar']);
188a25f0a04SGreg Roach
1893cf92ae2SGreg Roach        $this->assertSame('<li class="link-class"><a href="#" foo="bar">Test!</a></li>', $menu->getMenuAsList());
190a25f0a04SGreg Roach    }
191a25f0a04SGreg Roach}
192