xref: /webtrees/tests/app/MenuTest.php (revision a3a38d4c57c3592e2cda86bfa45f636d85cf6ad3)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees;
21
22/**
23 * Test harness for the class Menu
24 */
25class MenuTest extends TestCase
26{
27    /**
28     * @covers \Fisharebest\Webtrees\Menu::__construct
29     */
30    public function testConstructorDefaults(): void
31    {
32        $menu = new Menu('Test!');
33
34        self::assertSame('Test!', $menu->getLabel());
35        self::assertSame('#', $menu->getLink());
36        self::assertSame('', $menu->getClass());
37        self::assertSame([], $menu->getAttrs());
38        self::assertSame([], $menu->getSubmenus());
39    }
40
41    /**
42     * @covers \Fisharebest\Webtrees\Menu::__construct
43     */
44    public function testConstructorNonDefaults(): void
45    {
46        $submenus = [new Menu('Submenu')];
47        $menu     = new Menu('Test!', 'link.html', 'link-class', ['foo' => 'bar'], $submenus);
48
49        self::assertSame('Test!', $menu->getLabel());
50        self::assertSame('link.html', $menu->getLink());
51        self::assertSame('link-class', $menu->getClass());
52        self::assertSame(['foo' => 'bar'], $menu->getAttrs());
53        self::assertSame($submenus, $menu->getSubmenus());
54    }
55
56    /**
57     * @covers \Fisharebest\Webtrees\Menu::getLabel
58     * @covers \Fisharebest\Webtrees\Menu::setLabel
59     */
60    public function testGetterSetterLabel(): void
61    {
62        $menu = new Menu('Test!');
63
64        $return = $menu->setLabel('Label');
65
66        self::assertSame($return, $menu);
67        self::assertSame('Label', $menu->getLabel());
68    }
69
70    /**
71     * @covers \Fisharebest\Webtrees\Menu::getLink
72     * @covers \Fisharebest\Webtrees\Menu::setLink
73     */
74    public function testGetterSetterLink(): void
75    {
76        $menu = new Menu('Test!');
77
78        $return = $menu->setLink('link.html');
79
80        self::assertSame($return, $menu);
81        self::assertSame('link.html', $menu->getLink());
82    }
83
84    /**
85     * @covers \Fisharebest\Webtrees\Menu::getClass
86     * @covers \Fisharebest\Webtrees\Menu::setClass
87     */
88    public function testGetterSetterId(): void
89    {
90        $menu = new Menu('Test!');
91
92        $return = $menu->setClass('link-class');
93
94        self::assertSame($return, $menu);
95        self::assertSame('link-class', $menu->getClass());
96    }
97
98    /**
99     * @covers \Fisharebest\Webtrees\Menu::getAttrs
100     * @covers \Fisharebest\Webtrees\Menu::setAttrs
101     */
102    public function testGetterSetterAttrs(): void
103    {
104        $menu = new Menu('Test!');
105
106        $return = $menu->setAttrs(['foo' => 'bar']);
107
108        self::assertSame($return, $menu);
109        self::assertSame(['foo' => 'bar'], $menu->getAttrs());
110    }
111
112    /**
113     * @covers \Fisharebest\Webtrees\Menu::getSubmenus
114     * @covers \Fisharebest\Webtrees\Menu::setSubmenus
115     */
116    public function testGetterSetterSubmenus(): void
117    {
118        $menu     = new Menu('Test!');
119        $submenus = [
120            new Menu('Sub1'),
121            new Menu('Sub2'),
122        ];
123
124        $return = $menu->setSubmenus($submenus);
125
126        self::assertSame($return, $menu);
127        self::assertSame($submenus, $menu->getSubmenus());
128    }
129}
130