xref: /webtrees/tests/app/MenuTest.php (revision 5e933c21f8006e675d1df8bcedc634ee61f4aec2)
1a25f0a04SGreg Roach<?php
23976b470SGreg Roach
3a25f0a04SGreg Roach/**
4a25f0a04SGreg Roach * webtrees: online genealogy
5*5e933c21SGreg Roach * Copyright (C) 2020 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
15a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
16a25f0a04SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2084e2cf4eSGreg Roachnamespace Fisharebest\Webtrees;
21a25f0a04SGreg Roach
22a25f0a04SGreg Roach/**
23a25f0a04SGreg Roach * Test harness for the class Menu
24a25f0a04SGreg Roach */
25e5a6b4d4SGreg Roachclass MenuTest extends TestCase
26c1010edaSGreg Roach{
27a25f0a04SGreg Roach    /**
289b802b22SGreg Roach     * @covers \Fisharebest\Webtrees\Menu::__construct
2918d7a90dSGreg Roach     *
3018d7a90dSGreg Roach     * @return void
31a25f0a04SGreg Roach     */
329b802b22SGreg Roach    public function testConstructorDefaults(): void
33c1010edaSGreg Roach    {
34a25f0a04SGreg Roach        $menu = new Menu('Test!');
35a25f0a04SGreg Roach
36*5e933c21SGreg Roach        self::assertSame('Test!', $menu->getLabel());
37*5e933c21SGreg Roach        self::assertSame('#', $menu->getLink());
38*5e933c21SGreg Roach        self::assertSame('', $menu->getClass());
39*5e933c21SGreg Roach        self::assertSame([], $menu->getAttrs());
40*5e933c21SGreg Roach        self::assertSame([], $menu->getSubmenus());
41a25f0a04SGreg Roach    }
42a25f0a04SGreg Roach
43a25f0a04SGreg Roach    /**
449b802b22SGreg Roach     * @covers \Fisharebest\Webtrees\Menu::__construct
4518d7a90dSGreg Roach     *
4618d7a90dSGreg Roach     * @return void
47a25f0a04SGreg Roach     */
489b802b22SGreg Roach    public function testConstructorNonDefaults(): void
49c1010edaSGreg Roach    {
5013abd6f3SGreg Roach        $submenus = [new Menu('Submenu')];
5113abd6f3SGreg Roach        $menu     = new Menu('Test!', 'link.html', 'link-class', ['foo' => 'bar'], $submenus);
52a25f0a04SGreg Roach
53*5e933c21SGreg Roach        self::assertSame('Test!', $menu->getLabel());
54*5e933c21SGreg Roach        self::assertSame('link.html', $menu->getLink());
55*5e933c21SGreg Roach        self::assertSame('link-class', $menu->getClass());
56*5e933c21SGreg Roach        self::assertSame(['foo' => 'bar'], $menu->getAttrs());
57*5e933c21SGreg Roach        self::assertSame($submenus, $menu->getSubmenus());
58a25f0a04SGreg Roach    }
59a25f0a04SGreg Roach
60a25f0a04SGreg Roach    /**
619b802b22SGreg Roach     * @covers \Fisharebest\Webtrees\Menu::getLabel
629b802b22SGreg Roach     * @covers \Fisharebest\Webtrees\Menu::setLabel
6318d7a90dSGreg Roach     *
6418d7a90dSGreg Roach     * @return void
65a25f0a04SGreg Roach     */
669b802b22SGreg Roach    public function testGetterSetterLabel(): void
67c1010edaSGreg Roach    {
68a25f0a04SGreg Roach        $menu = new Menu('Test!');
69a25f0a04SGreg Roach
70a25f0a04SGreg Roach        $return = $menu->setLabel('Label');
71a25f0a04SGreg Roach
72*5e933c21SGreg Roach        self::assertSame($return, $menu);
73*5e933c21SGreg Roach        self::assertSame('Label', $menu->getLabel());
74a25f0a04SGreg Roach    }
75a25f0a04SGreg Roach
76a25f0a04SGreg Roach    /**
779b802b22SGreg Roach     * @covers \Fisharebest\Webtrees\Menu::getLink
789b802b22SGreg Roach     * @covers \Fisharebest\Webtrees\Menu::setLink
7918d7a90dSGreg Roach     *
8018d7a90dSGreg Roach     * @return void
81a25f0a04SGreg Roach     */
829b802b22SGreg Roach    public function testGetterSetterLink(): void
83c1010edaSGreg Roach    {
84a25f0a04SGreg Roach        $menu = new Menu('Test!');
85a25f0a04SGreg Roach
86a25f0a04SGreg Roach        $return = $menu->setLink('link.html');
87a25f0a04SGreg Roach
88*5e933c21SGreg Roach        self::assertSame($return, $menu);
89*5e933c21SGreg Roach        self::assertSame('link.html', $menu->getLink());
90a25f0a04SGreg Roach    }
91a25f0a04SGreg Roach
92a25f0a04SGreg Roach    /**
939b802b22SGreg Roach     * @covers \Fisharebest\Webtrees\Menu::getClass
949b802b22SGreg Roach     * @covers \Fisharebest\Webtrees\Menu::setClass
9518d7a90dSGreg Roach     *
9618d7a90dSGreg Roach     * @return void
97a25f0a04SGreg Roach     */
989b802b22SGreg Roach    public function testGetterSetterId(): void
99c1010edaSGreg Roach    {
100a25f0a04SGreg Roach        $menu = new Menu('Test!');
101a25f0a04SGreg Roach
102794c6b5bSGreg Roach        $return = $menu->setClass('link-class');
103a25f0a04SGreg Roach
104*5e933c21SGreg Roach        self::assertSame($return, $menu);
105*5e933c21SGreg Roach        self::assertSame('link-class', $menu->getClass());
106a25f0a04SGreg Roach    }
107a25f0a04SGreg Roach
108a25f0a04SGreg Roach    /**
1099b802b22SGreg Roach     * @covers \Fisharebest\Webtrees\Menu::getAttrs
1109b802b22SGreg Roach     * @covers \Fisharebest\Webtrees\Menu::setAttrs
11118d7a90dSGreg Roach     *
11218d7a90dSGreg Roach     * @return void
113a25f0a04SGreg Roach     */
1149b802b22SGreg Roach    public function testGetterSetterAttrs(): void
115c1010edaSGreg Roach    {
116a25f0a04SGreg Roach        $menu = new Menu('Test!');
117a25f0a04SGreg Roach
11813abd6f3SGreg Roach        $return = $menu->setAttrs(['foo' => 'bar']);
119a25f0a04SGreg Roach
120*5e933c21SGreg Roach        self::assertSame($return, $menu);
121*5e933c21SGreg Roach        self::assertSame(['foo' => 'bar'], $menu->getAttrs());
122a25f0a04SGreg Roach    }
123a25f0a04SGreg Roach
124a25f0a04SGreg Roach    /**
1259b802b22SGreg Roach     * @covers \Fisharebest\Webtrees\Menu::getSubmenus
1269b802b22SGreg Roach     * @covers \Fisharebest\Webtrees\Menu::setSubmenus
12718d7a90dSGreg Roach     *
12818d7a90dSGreg Roach     * @return void
129a25f0a04SGreg Roach     */
1309b802b22SGreg Roach    public function testGetterSetterSubmenus(): void
131c1010edaSGreg Roach    {
132a25f0a04SGreg Roach        $menu     = new Menu('Test!');
13313abd6f3SGreg Roach        $submenus = [
134a25f0a04SGreg Roach            new Menu('Sub1'),
135a25f0a04SGreg Roach            new Menu('Sub2'),
13613abd6f3SGreg Roach        ];
137a25f0a04SGreg Roach
138a25f0a04SGreg Roach        $return = $menu->setSubmenus($submenus);
139a25f0a04SGreg Roach
140*5e933c21SGreg Roach        self::assertSame($return, $menu);
141*5e933c21SGreg Roach        self::assertSame($submenus, $menu->getSubmenus());
142a25f0a04SGreg Roach    }
143a25f0a04SGreg Roach}
144