‪TYPO3CMS  ‪main
BackendLayoutCollectionTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 final class ‪BackendLayoutCollectionTest extends UnitTestCase
30 {
31  #[Test]
33  {
34  $this->expectException(\UnexpectedValueException::class);
35  $this->expectExceptionCode(1381597631);
38  }
39 
40  #[Test]
41  public function ‪objectIsCreated(): void
42  {
44  $backendLayoutCollection = new ‪BackendLayoutCollection(‪$identifier);
45 
46  self::assertEquals(‪$identifier, $backendLayoutCollection->getIdentifier());
47  }
48 
49  #[Test]
51  {
52  $this->expectException(\UnexpectedValueException::class);
53  $this->expectExceptionCode(1381597628);
55  $backendLayoutCollection = new ‪BackendLayoutCollection(‪$identifier);
56  $backendLayoutIdentifier = ‪StringUtility::getUniqueId('identifier__');
57  $backendLayoutMock = $this->getMockBuilder(BackendLayout::class)
58  ->onlyMethods(['getIdentifier'])
59  ->disableOriginalConstructor()
60  ->getMock();
61  $backendLayoutMock->expects(self::once())->method('getIdentifier')->willReturn($backendLayoutIdentifier);
62 
63  $backendLayoutCollection->add($backendLayoutMock);
64  }
65 
66  #[Test]
68  {
69  $this->expectException(\LogicException::class);
70  $this->expectExceptionCode(1381559376);
72  $backendLayoutCollection = new ‪BackendLayoutCollection(‪$identifier);
73  $backendLayoutIdentifier = ‪StringUtility::getUniqueId('identifier');
74  $firstBackendLayoutMock = $this->getMockBuilder(BackendLayout::class)
75  ->onlyMethods(['getIdentifier'])
76  ->disableOriginalConstructor()
77  ->getMock();
78  $firstBackendLayoutMock->expects(self::once())->method('getIdentifier')->willReturn($backendLayoutIdentifier);
79  $secondBackendLayoutMock = $this->getMockBuilder(BackendLayout::class)
80  ->onlyMethods(['getIdentifier'])
81  ->disableOriginalConstructor()
82  ->getMock();
83  $secondBackendLayoutMock->expects(self::once())->method('getIdentifier')->willReturn($backendLayoutIdentifier);
84 
85  $backendLayoutCollection->add($firstBackendLayoutMock);
86  $backendLayoutCollection->add($secondBackendLayoutMock);
87  }
88 
89  #[Test]
90  public function ‪backendLayoutCanBeFetched(): void
91  {
93  $backendLayoutCollection = new ‪BackendLayoutCollection(‪$identifier);
94  $backendLayoutIdentifier = ‪StringUtility::getUniqueId('identifier');
95  $backendLayoutMock = $this->getMockBuilder(BackendLayout::class)
96  ->onlyMethods(['getIdentifier'])
97  ->disableOriginalConstructor()
98  ->getMock();
99  $backendLayoutMock->expects(self::once())->method('getIdentifier')->willReturn($backendLayoutIdentifier);
100 
101  $backendLayoutCollection->add($backendLayoutMock);
102 
103  self::assertEquals($backendLayoutMock, $backendLayoutCollection->get($backendLayoutIdentifier));
104  }
105 }
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\BackendLayoutCollectionTest
Definition: BackendLayoutCollectionTest.php:30
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayoutCollection
Definition: BackendLayoutCollection.php:22
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\BackendLayoutCollectionTest\backendLayoutCanBeFetched
‪backendLayoutCanBeFetched()
Definition: BackendLayoutCollectionTest.php:90
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\BackendLayoutCollectionTest\objectIsCreated
‪objectIsCreated()
Definition: BackendLayoutCollectionTest.php:41
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\BackendLayoutCollectionTest\invalidBackendLayoutIsRecognizedOnAdding
‪invalidBackendLayoutIsRecognizedOnAdding()
Definition: BackendLayoutCollectionTest.php:50
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout
Definition: BackendLayoutCollectionTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\BackendLayoutCollectionTest\duplicateBackendLayoutIsRecognizedOnAdding
‪duplicateBackendLayoutIsRecognizedOnAdding()
Definition: BackendLayoutCollectionTest.php:67
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\BackendLayoutCollectionTest\invalidIdentifierIsRecognizedOnCreation
‪invalidIdentifierIsRecognizedOnCreation()
Definition: BackendLayoutCollectionTest.php:32
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayout
Definition: BackendLayout.php:27
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57