xref: /webtrees/tests/app/MenuTest.php (revision 6ccdf4f0fd1b65a5d54259c969912382ce49629d)
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