xref: /webtrees/tests/app/MenuTest.php (revision 18fd0859d876caec952296f28638ed0844e10712)
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
22use PHPUnit\Framework\Attributes\CoversClass;
23
24#[CoversClass(Menu::class)]
25class MenuTest extends TestCase
26{
27    public function testConstructorDefaults(): void
28    {
29        $menu = new Menu('Test!');
30
31        self::assertSame('Test!', $menu->getLabel());
32        self::assertSame('#', $menu->getLink());
33        self::assertSame('', $menu->getClass());
34        self::assertSame([], $menu->getAttrs());
35        self::assertSame([], $menu->getSubmenus());
36    }
37
38    public function testConstructorNonDefaults(): void
39    {
40        $submenus = [new Menu('Submenu')];
41        $menu     = new Menu('Test!', 'link.html', 'link-class', ['foo' => 'bar'], $submenus);
42
43        self::assertSame('Test!', $menu->getLabel());
44        self::assertSame('link.html', $menu->getLink());
45        self::assertSame('link-class', $menu->getClass());
46        self::assertSame(['foo' => 'bar'], $menu->getAttrs());
47        self::assertSame($submenus, $menu->getSubmenus());
48    }
49
50    public function testGetterSetterLabel(): void
51    {
52        $menu = new Menu('Test!');
53
54        $return = $menu->setLabel('Label');
55
56        self::assertSame($return, $menu);
57        self::assertSame('Label', $menu->getLabel());
58    }
59
60    public function testGetterSetterLink(): void
61    {
62        $menu = new Menu('Test!');
63
64        $return = $menu->setLink('link.html');
65
66        self::assertSame($return, $menu);
67        self::assertSame('link.html', $menu->getLink());
68    }
69
70    public function testGetterSetterId(): void
71    {
72        $menu = new Menu('Test!');
73
74        $return = $menu->setClass('link-class');
75
76        self::assertSame($return, $menu);
77        self::assertSame('link-class', $menu->getClass());
78    }
79
80    public function testGetterSetterAttrs(): void
81    {
82        $menu = new Menu('Test!');
83
84        $return = $menu->setAttrs(['foo' => 'bar']);
85
86        self::assertSame($return, $menu);
87        self::assertSame(['foo' => 'bar'], $menu->getAttrs());
88    }
89
90    public function testGetterSetterSubmenus(): void
91    {
92        $menu     = new Menu('Test!');
93        $submenus = [
94            new Menu('Sub1'),
95            new Menu('Sub2'),
96        ];
97
98        $return = $menu->setSubmenus($submenus);
99
100        self::assertSame($return, $menu);
101        self::assertSame($submenus, $menu->getSubmenus());
102    }
103}
104