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