4bff52c0db0203814548224332965bac7b88e345
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Template / Components / MenuTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Template\Components;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Template\Components\Menu\Menu;
18 use TYPO3\CMS\Backend\Template\Components\MenuRegistry;
19
20 /**
21 * Test case for Menu
22 */
23 class MenuTest extends \TYPO3\Components\TestingFramework\Core\UnitTestCase
24 {
25 /**
26 * Try setting an empty menu
27 *
28 * @test
29 * @return void
30 */
31 public function isMenuValidBlankCallExpectFalse()
32 {
33 $menu = new Menu();
34 $isValid = $menu->isValid($menu);
35 $this->assertFalse($isValid);
36 }
37
38 /**
39 * Set a valid menu
40 *
41 * @test
42 * @return void
43 */
44 public function isMenuValidValidMenuWithDefaultsExpectTrue()
45 {
46 $menu = new Menu();
47 $menu->setIdentifier('husel');
48 $isValid = $menu->isValid($menu);
49 $this->assertTrue($isValid);
50 }
51
52 /**
53 * Set a valid menu
54 *
55 * @test
56 * @return void
57 */
58 public function makeMenuAllGoodExpectTrue()
59 {
60 $menuRegistry = new MenuRegistry();
61 $result = $menuRegistry->makeMenu()->setLabel('MenuLabel')->setIdentifier('MenuIdent');
62 $expected = new Menu();
63 $expected->setIdentifier('MenuIdent');
64 $expected->setLabel('MenuLabel');
65 $this->assertEquals($expected, $result);
66 }
67
68 /**
69 * Tests if empty menus get removed from the stack
70 *
71 * @test
72 * @return void
73 */
74 public function getMenusremovedEmptyMenusExpectsEquals()
75 {
76 $menuRegistry = new MenuRegistry();
77
78 $menu1 = $menuRegistry->makeMenu();
79 $menu1->setIdentifier('husel');
80 $menu1->setLabel('Label of an empty Menu');
81 $menuRegistry->addMenu($menu1);
82
83 $menu2 = $menuRegistry->makeMenu()->setIdentifier('Foo');
84 $item = $menu2->makeMenuItem()->setHref('#')->setTitle('Husel');
85 $menu2->addMenuItem($item);
86
87 $menuRegistry->addMenu($menu2);
88
89 $result = $menuRegistry->getMenus();
90 $expected = [
91 'Foo' => $menu2
92 ];
93
94 $this->assertEquals($expected, $result);
95 }
96 }