[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / ContentObject / Menu / MenuContentObjectFactoryTest.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Unit\ContentObject\Menu;
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\Frontend\ContentObject\Menu\Exception\NoSuchMenuTypeException;
18 use TYPO3\CMS\Frontend\ContentObject\Menu\MenuContentObjectFactory;
19
20 /**
21 * Testcase
22 */
23 class MenuContentObjectFactoryTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
24 {
25 /**
26 * @test
27 */
28 public function getMenuObjectByTypeThrowsExceptionForUnknownType()
29 {
30 $this->expectException(NoSuchMenuTypeException::class);
31 $this->expectExceptionCode(1363278130);
32 $factory = new MenuContentObjectFactory;
33 $factory->getMenuObjectByType($this->getUniqueId('foo_'));
34 }
35
36 /**
37 * @test
38 */
39 public function getMenuObjectByTypeReturnsObjectForRegisteredMenuType()
40 {
41 $factory = new MenuContentObjectFactory;
42 $this->assertInternalType('object', $factory->getMenuObjectByType('GMENU'));
43 }
44
45 /**
46 * @test
47 */
48 public function getMenuObjectByTypeReturnsObjectWithLowercasedMenuType()
49 {
50 $factory = new MenuContentObjectFactory;
51 $this->assertInternalType('object', $factory->getMenuObjectByType('gmenu'));
52 }
53
54 /**
55 * @test
56 */
57 public function getMenuObjectByTypeReturnsInstanceOfOwnRegisteredTypeInsteadOfInternalType()
58 {
59 $factory = new MenuContentObjectFactory;
60 $selfClassName = get_class($this);
61 $factory->registerMenuType('GMENU', $selfClassName);
62 $this->assertInstanceOf($selfClassName, $factory->getMenuObjectByType('GMENU'));
63 }
64
65 /**
66 * @test
67 */
68 public function getMenuObjectByTypeReturnsInstanceOfNewRegisteredType()
69 {
70 $factory = new MenuContentObjectFactory;
71 $selfClassName = get_class($this);
72 $uniqueMenuType = $this->getUniqueId('foo_');
73 $factory->registerMenuType($uniqueMenuType, $selfClassName);
74 $this->assertInstanceOf($selfClassName, $factory->getMenuObjectByType($uniqueMenuType));
75 }
76
77 /**
78 * @test
79 */
80 public function registerMenuTypeThrowsExceptionIfTypeIsNotOfTypeString()
81 {
82 $this->expectException(\InvalidArgumentException::class);
83 $this->expectExceptionCode(1363429303);
84 $factory = new MenuContentObjectFactory;
85 $factory->registerMenuType([], 'foo');
86 }
87
88 /**
89 * @test
90 */
91 public function registerMenuTypeThrowsExceptionIfClassNameIsNotOfTypeString()
92 {
93 $this->expectException(\InvalidArgumentException::class);
94 $this->expectExceptionCode(1363429303);
95 $factory = new MenuContentObjectFactory;
96 $factory->registerMenuType('foo', []);
97 }
98 }