‪TYPO3CMS  ‪main
DataProviderCollectionTest.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;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 final class ‪DataProviderCollectionTest extends UnitTestCase
31 {
33 
37  protected function ‪setUp(): void
38  {
39  parent::setUp();
40  $this->dataProviderCollection = new ‪DataProviderCollection();
41  }
42 
43  #[Test]
45  {
46  $this->expectException(\UnexpectedValueException::class);
47  $this->expectExceptionCode(1381597629);
49  $dataProviderMock = $this->getMockBuilder(\stdClass::class)->getMock();
50 
51  $this->dataProviderCollection->add(‪$identifier, get_class($dataProviderMock));
52  }
53 
54  #[Test]
56  {
57  $this->expectException(\LogicException::class);
58  $this->expectExceptionCode(1381269811);
60  $dataProviderMock = $this->getMockBuilder(\stdClass::class)->getMock();
61 
62  $this->dataProviderCollection->add(‪$identifier, get_class($dataProviderMock));
63  }
64 
65  #[Test]
66  public function ‪defaultBackendLayoutIsFound(): void
67  {
68  $backendLayoutIdentifier = ‪StringUtility::getUniqueId('identifier');
69 
70  $dataProviderMock = $this->getMockBuilder(DefaultDataProvider::class)
71  ->onlyMethods(['getBackendLayout'])
72  ->disableOriginalConstructor()
73  ->getMock();
74  $backendLayoutMock = $this->getMockBuilder(BackendLayout::class)
75  ->onlyMethods(['getIdentifier'])
76  ->disableOriginalConstructor()
77  ->getMock();
78  $backendLayoutMock->method('getIdentifier')->willReturn($backendLayoutIdentifier);
79  $dataProviderMock->expects(self::once())->method('getBackendLayout')->willReturn($backendLayoutMock);
80 
81  $this->dataProviderCollection->add('default', $dataProviderMock);
82  $providedBackendLayout = $this->dataProviderCollection->getBackendLayout($backendLayoutIdentifier, 123);
83 
84  self::assertNotNull($providedBackendLayout);
85  self::assertEquals($backendLayoutIdentifier, $providedBackendLayout->getIdentifier());
86  }
87 
88  #[Test]
89  public function ‪providedBackendLayoutIsFound(): void
90  {
91  $dataProviderIdentifier = ‪StringUtility::getUniqueId('custom');
92  $backendLayoutIdentifier = ‪StringUtility::getUniqueId('identifier');
93 
94  $dataProviderMock = $this->getMockBuilder(DefaultDataProvider::class)
95  ->onlyMethods(['getBackendLayout'])
96  ->disableOriginalConstructor()
97  ->getMock();
98  $backendLayoutMock = $this->getMockBuilder(BackendLayout::class)
99  ->onlyMethods(['getIdentifier'])
100  ->disableOriginalConstructor()
101  ->getMock();
102  $backendLayoutMock->method('getIdentifier')->willReturn($backendLayoutIdentifier);
103  $dataProviderMock->expects(self::once())->method('getBackendLayout')->willReturn($backendLayoutMock);
104 
105  $this->dataProviderCollection->add($dataProviderIdentifier, $dataProviderMock);
106  $providedBackendLayout = $this->dataProviderCollection->getBackendLayout($dataProviderIdentifier . '__' . $backendLayoutIdentifier, 123);
107 
108  self::assertNotNull($providedBackendLayout);
109  self::assertEquals($backendLayoutIdentifier, $providedBackendLayout->getIdentifier());
110  }
111 }
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\DataProviderCollectionTest\defaultBackendLayoutIsFound
‪defaultBackendLayoutIsFound()
Definition: DataProviderCollectionTest.php:66
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\DataProviderCollectionTest\$dataProviderCollection
‪DataProviderCollection $dataProviderCollection
Definition: DataProviderCollectionTest.php:32
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\DataProviderCollectionTest\setUp
‪setUp()
Definition: DataProviderCollectionTest.php:37
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection
Definition: DataProviderCollection.php:25
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\DataProviderCollectionTest
Definition: DataProviderCollectionTest.php:31
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout
Definition: BackendLayoutCollectionTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\DataProviderCollectionTest\invalidIdentifierIsRecognizedOnAdding
‪invalidIdentifierIsRecognizedOnAdding()
Definition: DataProviderCollectionTest.php:44
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\DataProviderCollectionTest\invalidInterfaceIsRecognizedOnAdding
‪invalidInterfaceIsRecognizedOnAdding()
Definition: DataProviderCollectionTest.php:55
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\DataProviderCollectionTest\providedBackendLayoutIsFound
‪providedBackendLayoutIsFound()
Definition: DataProviderCollectionTest.php:89
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayout
Definition: BackendLayout.php:25
‪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
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider
Definition: DefaultDataProvider.php:32