xref: /webtrees/tests/app/MenuTest.php (revision 5a8afed46297e8105e3e5a33ce37e6a8e88bc79d)
1a25f0a04SGreg Roach<?php
23976b470SGreg Roach
3a25f0a04SGreg Roach/**
4a25f0a04SGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 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
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16a25f0a04SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2084e2cf4eSGreg Roachnamespace Fisharebest\Webtrees;
21a25f0a04SGreg Roach
22*202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass;
23*202c018bSGreg Roach
24*202c018bSGreg Roach#[CoversClass(Menu::class)]
25e5a6b4d4SGreg Roachclass MenuTest extends TestCase
26c1010edaSGreg Roach{
279b802b22SGreg Roach    public function testConstructorDefaults(): void
28c1010edaSGreg Roach    {
29a25f0a04SGreg Roach        $menu = new Menu('Test!');
30a25f0a04SGreg Roach
315e933c21SGreg Roach        self::assertSame('Test!', $menu->getLabel());
325e933c21SGreg Roach        self::assertSame('#', $menu->getLink());
335e933c21SGreg Roach        self::assertSame('', $menu->getClass());
345e933c21SGreg Roach        self::assertSame([], $menu->getAttrs());
355e933c21SGreg Roach        self::assertSame([], $menu->getSubmenus());
36a25f0a04SGreg Roach    }
37a25f0a04SGreg Roach
389b802b22SGreg Roach    public function testConstructorNonDefaults(): void
39c1010edaSGreg Roach    {
4013abd6f3SGreg Roach        $submenus = [new Menu('Submenu')];
4113abd6f3SGreg Roach        $menu     = new Menu('Test!', 'link.html', 'link-class', ['foo' => 'bar'], $submenus);
42a25f0a04SGreg Roach
435e933c21SGreg Roach        self::assertSame('Test!', $menu->getLabel());
445e933c21SGreg Roach        self::assertSame('link.html', $menu->getLink());
455e933c21SGreg Roach        self::assertSame('link-class', $menu->getClass());
465e933c21SGreg Roach        self::assertSame(['foo' => 'bar'], $menu->getAttrs());
475e933c21SGreg Roach        self::assertSame($submenus, $menu->getSubmenus());
48a25f0a04SGreg Roach    }
49a25f0a04SGreg Roach
509b802b22SGreg Roach    public function testGetterSetterLabel(): void
51c1010edaSGreg Roach    {
52a25f0a04SGreg Roach        $menu = new Menu('Test!');
53a25f0a04SGreg Roach
54a25f0a04SGreg Roach        $return = $menu->setLabel('Label');
55a25f0a04SGreg Roach
565e933c21SGreg Roach        self::assertSame($return, $menu);
575e933c21SGreg Roach        self::assertSame('Label', $menu->getLabel());
58a25f0a04SGreg Roach    }
59a25f0a04SGreg Roach
609b802b22SGreg Roach    public function testGetterSetterLink(): void
61c1010edaSGreg Roach    {
62a25f0a04SGreg Roach        $menu = new Menu('Test!');
63a25f0a04SGreg Roach
64a25f0a04SGreg Roach        $return = $menu->setLink('link.html');
65a25f0a04SGreg Roach
665e933c21SGreg Roach        self::assertSame($return, $menu);
675e933c21SGreg Roach        self::assertSame('link.html', $menu->getLink());
68a25f0a04SGreg Roach    }
69a25f0a04SGreg Roach
709b802b22SGreg Roach    public function testGetterSetterId(): void
71c1010edaSGreg Roach    {
72a25f0a04SGreg Roach        $menu = new Menu('Test!');
73a25f0a04SGreg Roach
74794c6b5bSGreg Roach        $return = $menu->setClass('link-class');
75a25f0a04SGreg Roach
765e933c21SGreg Roach        self::assertSame($return, $menu);
775e933c21SGreg Roach        self::assertSame('link-class', $menu->getClass());
78a25f0a04SGreg Roach    }
79a25f0a04SGreg Roach
809b802b22SGreg Roach    public function testGetterSetterAttrs(): void
81c1010edaSGreg Roach    {
82a25f0a04SGreg Roach        $menu = new Menu('Test!');
83a25f0a04SGreg Roach
8413abd6f3SGreg Roach        $return = $menu->setAttrs(['foo' => 'bar']);
85a25f0a04SGreg Roach
865e933c21SGreg Roach        self::assertSame($return, $menu);
875e933c21SGreg Roach        self::assertSame(['foo' => 'bar'], $menu->getAttrs());
88a25f0a04SGreg Roach    }
89a25f0a04SGreg Roach
909b802b22SGreg Roach    public function testGetterSetterSubmenus(): void
91c1010edaSGreg Roach    {
92a25f0a04SGreg Roach        $menu     = new Menu('Test!');
9313abd6f3SGreg Roach        $submenus = [
94a25f0a04SGreg Roach            new Menu('Sub1'),
95a25f0a04SGreg Roach            new Menu('Sub2'),
9613abd6f3SGreg Roach        ];
97a25f0a04SGreg Roach
98a25f0a04SGreg Roach        $return = $menu->setSubmenus($submenus);
99a25f0a04SGreg Roach
1005e933c21SGreg Roach        self::assertSame($return, $menu);
1015e933c21SGreg Roach        self::assertSame($submenus, $menu->getSubmenus());
102a25f0a04SGreg Roach    }
103a25f0a04SGreg Roach}
104