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