[BUGFIX] Add missing namespace parts
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / View / BackendLayout / BackendLayoutCollectionTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout;
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 /**
18 * Testing collection of backend layouts.
19 */
20 class BackendLayoutCollectionTest extends \TYPO3\Components\TestingFramework\Core\Unit\UnitTestCase
21 {
22 /**
23 * @test
24 */
25 public function invalidIdentifierIsRecognizedOnCreation()
26 {
27 $this->expectException(\UnexpectedValueException::class);
28 $this->expectExceptionCode(1381597631);
29 $identifier = $this->getUniqueId('identifier__');
30 new \TYPO3\CMS\Backend\View\BackendLayout\BackendLayoutCollection($identifier);
31 }
32
33 /**
34 * @test
35 */
36 public function objectIsCreated()
37 {
38 $identifier = $this->getUniqueId('identifier');
39 $backendLayoutCollection = new \TYPO3\CMS\Backend\View\BackendLayout\BackendLayoutCollection($identifier);
40
41 $this->assertEquals($identifier, $backendLayoutCollection->getIdentifier());
42 }
43
44 /**
45 * @test
46 */
47 public function invalidBackendLayoutIsRecognizedOnAdding()
48 {
49 $this->expectException(\UnexpectedValueException::class);
50 $this->expectExceptionCode(1381597628);
51 $identifier = $this->getUniqueId('identifier');
52 $backendLayoutCollection = new \TYPO3\CMS\Backend\View\BackendLayout\BackendLayoutCollection($identifier);
53 $backendLayoutIdentifier = $this->getUniqueId('identifier__');
54 $backendLayoutMock = $this->getMockBuilder(\TYPO3\CMS\Backend\View\BackendLayout\BackendLayout::class)
55 ->setMethods(['getIdentifier'])
56 ->disableOriginalConstructor()
57 ->getMock();
58 $backendLayoutMock->expects($this->once())->method('getIdentifier')->will($this->returnValue($backendLayoutIdentifier));
59
60 $backendLayoutCollection->add($backendLayoutMock);
61 }
62
63 /**
64 * @test
65 */
66 public function duplicateBackendLayoutIsRecognizedOnAdding()
67 {
68 $this->expectException(\LogicException::class);
69 $this->expectExceptionCode(1381559376);
70 $identifier = $this->getUniqueId('identifier');
71 $backendLayoutCollection = new \TYPO3\CMS\Backend\View\BackendLayout\BackendLayoutCollection($identifier);
72 $backendLayoutIdentifier = $this->getUniqueId('identifier');
73 $firstBackendLayoutMock = $this->getMockBuilder(\TYPO3\CMS\Backend\View\BackendLayout\BackendLayout::class)
74 ->setMethods(['getIdentifier'])
75 ->disableOriginalConstructor()
76 ->getMock();
77 $firstBackendLayoutMock->expects($this->once())->method('getIdentifier')->will($this->returnValue($backendLayoutIdentifier));
78 $secondBackendLayoutMock = $this->getMockBuilder(\TYPO3\CMS\Backend\View\BackendLayout\BackendLayout::class)
79 ->setMethods(['getIdentifier'])
80 ->disableOriginalConstructor()
81 ->getMock();
82 $secondBackendLayoutMock->expects($this->once())->method('getIdentifier')->will($this->returnValue($backendLayoutIdentifier));
83
84 $backendLayoutCollection->add($firstBackendLayoutMock);
85 $backendLayoutCollection->add($secondBackendLayoutMock);
86 }
87
88 /**
89 * @test
90 */
91 public function backendLayoutCanBeFetched()
92 {
93 $identifier = $this->getUniqueId('identifier');
94 $backendLayoutCollection = new \TYPO3\CMS\Backend\View\BackendLayout\BackendLayoutCollection($identifier);
95 $backendLayoutIdentifier = $this->getUniqueId('identifier');
96 $backendLayoutMock = $this->getMockBuilder(\TYPO3\CMS\Backend\View\BackendLayout\BackendLayout::class)
97 ->setMethods(['getIdentifier'])
98 ->disableOriginalConstructor()
99 ->getMock();
100 $backendLayoutMock->expects($this->once())->method('getIdentifier')->will($this->returnValue($backendLayoutIdentifier));
101
102 $backendLayoutCollection->add($backendLayoutMock);
103
104 $this->assertEquals($backendLayoutMock, $backendLayoutCollection->get($backendLayoutIdentifier));
105 }
106 }