xref: /webtrees/tests/app/MenuTest.php (revision 202c018b592d5a516e4a465dc6dc515f3be37399)
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
25*202c018bSGreg Roach#[CoversClass(Menu::class)]
26e5a6b4d4SGreg Roachclass MenuTest extends TestCase
27c1010edaSGreg Roach{
289b802b22SGreg Roach    public function testConstructorDefaults(): void
29c1010edaSGreg Roach    {
30a25f0a04SGreg Roach        $menu = new Menu('Test!');
31a25f0a04SGreg Roach
325e933c21SGreg Roach        self::assertSame('Test!', $menu->getLabel());
335e933c21SGreg Roach        self::assertSame('#', $menu->getLink());
345e933c21SGreg Roach        self::assertSame('', $menu->getClass());
355e933c21SGreg Roach        self::assertSame([], $menu->getAttrs());
365e933c21SGreg Roach        self::assertSame([], $menu->getSubmenus());
37a25f0a04SGreg Roach    }
38a25f0a04SGreg Roach
399b802b22SGreg Roach    public function testConstructorNonDefaults(): void
40c1010edaSGreg Roach    {
4113abd6f3SGreg Roach        $submenus = [new Menu('Submenu')];
4213abd6f3SGreg Roach        $menu     = new Menu('Test!', 'link.html', 'link-class', ['foo' => 'bar'], $submenus);
43a25f0a04SGreg Roach
445e933c21SGreg Roach        self::assertSame('Test!', $menu->getLabel());
455e933c21SGreg Roach        self::assertSame('link.html', $menu->getLink());
465e933c21SGreg Roach        self::assertSame('link-class', $menu->getClass());
475e933c21SGreg Roach        self::assertSame(['foo' => 'bar'], $menu->getAttrs());
485e933c21SGreg Roach        self::assertSame($submenus, $menu->getSubmenus());
49a25f0a04SGreg Roach    }
50a25f0a04SGreg Roach
519b802b22SGreg Roach    public function testGetterSetterLabel(): void
52c1010edaSGreg Roach    {
53a25f0a04SGreg Roach        $menu = new Menu('Test!');
54a25f0a04SGreg Roach
55a25f0a04SGreg Roach        $return = $menu->setLabel('Label');
56a25f0a04SGreg Roach
575e933c21SGreg Roach        self::assertSame($return, $menu);
585e933c21SGreg Roach        self::assertSame('Label', $menu->getLabel());
59a25f0a04SGreg Roach    }
60a25f0a04SGreg Roach
619b802b22SGreg Roach    public function testGetterSetterLink(): void
62c1010edaSGreg Roach    {
63a25f0a04SGreg Roach        $menu = new Menu('Test!');
64a25f0a04SGreg Roach
65a25f0a04SGreg Roach        $return = $menu->setLink('link.html');
66a25f0a04SGreg Roach
675e933c21SGreg Roach        self::assertSame($return, $menu);
685e933c21SGreg Roach        self::assertSame('link.html', $menu->getLink());
69a25f0a04SGreg Roach    }
70a25f0a04SGreg Roach
719b802b22SGreg Roach    public function testGetterSetterId(): void
72c1010edaSGreg Roach    {
73a25f0a04SGreg Roach        $menu = new Menu('Test!');
74a25f0a04SGreg Roach
75794c6b5bSGreg Roach        $return = $menu->setClass('link-class');
76a25f0a04SGreg Roach
775e933c21SGreg Roach        self::assertSame($return, $menu);
785e933c21SGreg Roach        self::assertSame('link-class', $menu->getClass());
79a25f0a04SGreg Roach    }
80a25f0a04SGreg Roach
819b802b22SGreg Roach    public function testGetterSetterAttrs(): void
82c1010edaSGreg Roach    {
83a25f0a04SGreg Roach        $menu = new Menu('Test!');
84a25f0a04SGreg Roach
8513abd6f3SGreg Roach        $return = $menu->setAttrs(['foo' => 'bar']);
86a25f0a04SGreg Roach
875e933c21SGreg Roach        self::assertSame($return, $menu);
885e933c21SGreg Roach        self::assertSame(['foo' => 'bar'], $menu->getAttrs());
89a25f0a04SGreg Roach    }
90a25f0a04SGreg Roach
919b802b22SGreg Roach    public function testGetterSetterSubmenus(): void
92c1010edaSGreg Roach    {
93a25f0a04SGreg Roach        $menu     = new Menu('Test!');
9413abd6f3SGreg Roach        $submenus = [
95a25f0a04SGreg Roach            new Menu('Sub1'),
96a25f0a04SGreg Roach            new Menu('Sub2'),
9713abd6f3SGreg Roach        ];
98a25f0a04SGreg Roach
99a25f0a04SGreg Roach        $return = $menu->setSubmenus($submenus);
100a25f0a04SGreg Roach
1015e933c21SGreg Roach        self::assertSame($return, $menu);
1025e933c21SGreg Roach        self::assertSame($submenus, $menu->getSubmenus());
103a25f0a04SGreg Roach    }
104a25f0a04SGreg Roach}
105