xref: /webtrees/tests/app/MenuTest.php (revision c1010eda29c0909ed4d5d463f32d32bfefdd4dfe)
1a25f0a04SGreg Roach<?php
2a25f0a04SGreg Roach
3a25f0a04SGreg Roach/**
4a25f0a04SGreg Roach * webtrees: online genealogy
51062a142SGreg Roach * Copyright (C) 2018 webtrees development team
6a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify
7a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by
8a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9a25f0a04SGreg Roach * (at your option) any later version.
10a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful,
11a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13a25f0a04SGreg Roach * GNU General Public License for more details.
14a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License
15a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
16a25f0a04SGreg Roach */
17a25f0a04SGreg Roach
180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Menu;
19a25f0a04SGreg Roach
20a25f0a04SGreg Roach/**
21a25f0a04SGreg Roach * Test harness for the class Menu
22a25f0a04SGreg Roach */
23*c1010edaSGreg Roachclass MenuTest extends \PHPUnit\Framework\TestCase
24*c1010edaSGreg Roach{
25a25f0a04SGreg Roach    /**
26a25f0a04SGreg Roach     * Prepare the environment for these tests.
27a25f0a04SGreg Roach     */
28*c1010edaSGreg Roach    public function setUp()
29*c1010edaSGreg Roach    {
30a25f0a04SGreg Roach    }
31a25f0a04SGreg Roach
32a25f0a04SGreg Roach    /**
33a25f0a04SGreg Roach     * Test the constructor with default parameters.
34a25f0a04SGreg Roach     */
35*c1010edaSGreg Roach    public function testConstructorDefaults()
36*c1010edaSGreg Roach    {
37a25f0a04SGreg Roach        $menu = new Menu('Test!');
38a25f0a04SGreg Roach
39a25f0a04SGreg Roach        $this->assertSame('Test!', $menu->getLabel());
40a25f0a04SGreg Roach        $this->assertSame('#', $menu->getLink());
417820e4d7SGreg Roach        $this->assertSame('', $menu->getClass());
4213abd6f3SGreg Roach        $this->assertSame([], $menu->getAttrs());
4313abd6f3SGreg Roach        $this->assertSame([], $menu->getSubmenus());
44a25f0a04SGreg Roach    }
45a25f0a04SGreg Roach
46a25f0a04SGreg Roach    /**
47a25f0a04SGreg Roach     * Test the constructor with non-default parameters.
48a25f0a04SGreg Roach     */
49*c1010edaSGreg Roach    public function testConstructorNonDefaults()
50*c1010edaSGreg Roach    {
5113abd6f3SGreg Roach        $submenus = [new Menu('Submenu')];
5213abd6f3SGreg Roach        $menu     = new Menu('Test!', 'link.html', 'link-class', ['foo' => 'bar'], $submenus);
53a25f0a04SGreg Roach
54a25f0a04SGreg Roach        $this->assertSame('Test!', $menu->getLabel());
55a25f0a04SGreg Roach        $this->assertSame('link.html', $menu->getLink());
56794c6b5bSGreg Roach        $this->assertSame('link-class', $menu->getClass());
5713abd6f3SGreg Roach        $this->assertSame(['foo' => 'bar'], $menu->getAttrs());
58a25f0a04SGreg Roach        $this->assertSame($submenus, $menu->getSubmenus());
59a25f0a04SGreg Roach    }
60a25f0a04SGreg Roach
61a25f0a04SGreg Roach    /**
62a25f0a04SGreg Roach     * Test the getter/setter for the label.
63a25f0a04SGreg Roach     */
64*c1010edaSGreg Roach    public function testGetterSetterLabel()
65*c1010edaSGreg Roach    {
66a25f0a04SGreg Roach        $menu = new Menu('Test!');
67a25f0a04SGreg Roach
68a25f0a04SGreg Roach        $return = $menu->setLabel('Label');
69a25f0a04SGreg Roach
70a25f0a04SGreg Roach        $this->assertSame($return, $menu);
71a25f0a04SGreg Roach        $this->assertSame('Label', $menu->getLabel());
72a25f0a04SGreg Roach    }
73a25f0a04SGreg Roach
74a25f0a04SGreg Roach    /**
75a25f0a04SGreg Roach     * Test the getter/setter for the link.
76a25f0a04SGreg Roach     */
77*c1010edaSGreg Roach    public function testGetterSetterLink()
78*c1010edaSGreg Roach    {
79a25f0a04SGreg Roach        $menu = new Menu('Test!');
80a25f0a04SGreg Roach
81a25f0a04SGreg Roach        $return = $menu->setLink('link.html');
82a25f0a04SGreg Roach
83a25f0a04SGreg Roach        $this->assertSame($return, $menu);
84a25f0a04SGreg Roach        $this->assertSame('link.html', $menu->getLink());
85a25f0a04SGreg Roach    }
86a25f0a04SGreg Roach
87a25f0a04SGreg Roach    /**
88a25f0a04SGreg Roach     * Test the getter/setter for the ID.
89a25f0a04SGreg Roach     */
90*c1010edaSGreg Roach    public function testGetterSetterId()
91*c1010edaSGreg Roach    {
92a25f0a04SGreg Roach        $menu = new Menu('Test!');
93a25f0a04SGreg Roach
94794c6b5bSGreg Roach        $return = $menu->setClass('link-class');
95a25f0a04SGreg Roach
96a25f0a04SGreg Roach        $this->assertSame($return, $menu);
97794c6b5bSGreg Roach        $this->assertSame('link-class', $menu->getClass());
98a25f0a04SGreg Roach    }
99a25f0a04SGreg Roach
100a25f0a04SGreg Roach    /**
1013cf92ae2SGreg Roach     * Test the getter/setter for the Attrs event.
102a25f0a04SGreg Roach     */
103*c1010edaSGreg Roach    public function testGetterSetterAttrs()
104*c1010edaSGreg Roach    {
105a25f0a04SGreg Roach        $menu = new Menu('Test!');
106a25f0a04SGreg Roach
10713abd6f3SGreg Roach        $return = $menu->setAttrs(['foo' => 'bar']);
108a25f0a04SGreg Roach
109a25f0a04SGreg Roach        $this->assertSame($return, $menu);
11013abd6f3SGreg Roach        $this->assertSame(['foo' => 'bar'], $menu->getAttrs());
111a25f0a04SGreg Roach    }
112a25f0a04SGreg Roach
113a25f0a04SGreg Roach    /**
114a25f0a04SGreg Roach     * Test the getter/setter for the submenus.
115a25f0a04SGreg Roach     */
116*c1010edaSGreg Roach    public function testGetterSetterSubmenus()
117*c1010edaSGreg Roach    {
118a25f0a04SGreg Roach        $menu     = new Menu('Test!');
11913abd6f3SGreg Roach        $submenus = [
120a25f0a04SGreg Roach            new Menu('Sub1'),
121a25f0a04SGreg Roach            new Menu('Sub2'),
12213abd6f3SGreg Roach        ];
123a25f0a04SGreg Roach
124a25f0a04SGreg Roach        $return = $menu->setSubmenus($submenus);
125a25f0a04SGreg Roach
126a25f0a04SGreg Roach        $this->assertSame($return, $menu);
127a25f0a04SGreg Roach        $this->assertSame($submenus, $menu->getSubmenus());
128a25f0a04SGreg Roach    }
129a25f0a04SGreg Roach
130a25f0a04SGreg Roach    /**
131a25f0a04SGreg Roach     * Test the list rendering for a simple link.
132a25f0a04SGreg Roach     */
133*c1010edaSGreg Roach    public function testFormatAsList()
134*c1010edaSGreg Roach    {
135a25f0a04SGreg Roach        $menu = new Menu('Test!', 'link.html');
136a25f0a04SGreg Roach
137794c6b5bSGreg Roach        $this->assertSame('<li class=""><a href="link.html">Test!</a></li>', $menu->getMenuAsList());
138a25f0a04SGreg Roach    }
139a25f0a04SGreg Roach
140a25f0a04SGreg Roach    /**
141a25f0a04SGreg Roach     * Test the list rendering for a simple link with a CSS ID.
142a25f0a04SGreg Roach     */
143*c1010edaSGreg Roach    public function testFormatAsListWithClass()
144*c1010edaSGreg Roach    {
145794c6b5bSGreg Roach        $menu = new Menu('Test!', 'link.html', 'link-class');
146a25f0a04SGreg Roach
147794c6b5bSGreg Roach        $this->assertSame('<li class="link-class"><a href="link.html">Test!</a></li>', $menu->getMenuAsList());
148a25f0a04SGreg Roach    }
149a25f0a04SGreg Roach
150a25f0a04SGreg Roach    /**
151a25f0a04SGreg Roach     * Test the list rendering for an empty target.
152a25f0a04SGreg Roach     */
153*c1010edaSGreg Roach    public function testFormatAsListWithNoTarget()
154*c1010edaSGreg Roach    {
155a25f0a04SGreg Roach        $menu = new Menu('Test!', '');
156a25f0a04SGreg Roach
157794c6b5bSGreg Roach        $this->assertSame('<li class=""><a>Test!</a></li>', $menu->getMenuAsList());
158a25f0a04SGreg Roach    }
159a25f0a04SGreg Roach
160a25f0a04SGreg Roach    /**
161a25f0a04SGreg Roach     * Test the list rendering for a default (hash) target.
162a25f0a04SGreg Roach     */
163*c1010edaSGreg Roach    public function testFormatAsListWithHashTarget()
164*c1010edaSGreg Roach    {
165a25f0a04SGreg Roach        $menu = new Menu('Test!');
166a25f0a04SGreg Roach
167794c6b5bSGreg Roach        $this->assertSame('<li class=""><a href="#">Test!</a></li>', $menu->getMenuAsList());
168a25f0a04SGreg Roach    }
169a25f0a04SGreg Roach
170a25f0a04SGreg Roach    /**
171a25f0a04SGreg Roach     * Test the list rendering for an onclick link.
172a25f0a04SGreg Roach     */
173*c1010edaSGreg Roach    public function testFormatAsListWithAttrs()
174*c1010edaSGreg Roach    {
17513abd6f3SGreg Roach        $menu = new Menu('Test!', '#', '', ['foo' => 'bar']);
176a25f0a04SGreg Roach
1773cf92ae2SGreg Roach        $this->assertSame('<li class=""><a href="#" foo="bar">Test!</a></li>', $menu->getMenuAsList());
178a25f0a04SGreg Roach    }
179a25f0a04SGreg Roach
180a25f0a04SGreg Roach    /**
181a25f0a04SGreg Roach     * Test the list rendering for an onclick link.
182a25f0a04SGreg Roach     */
183*c1010edaSGreg Roach    public function testFormatAsListWithAttrsAndId()
184*c1010edaSGreg Roach    {
18513abd6f3SGreg Roach        $menu = new Menu('Test!', '#', 'link-class', ['foo' => 'bar']);
186a25f0a04SGreg Roach
1873cf92ae2SGreg Roach        $this->assertSame('<li class="link-class"><a href="#" foo="bar">Test!</a></li>', $menu->getMenuAsList());
188a25f0a04SGreg Roach    }
189a25f0a04SGreg Roach}
190