‪TYPO3CMS  10.4
DataProviderCollectionTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪DataProviderCollectionTest extends UnitTestCase
28 {
33 
37  protected function ‪setUp(): void
38  {
39  parent::setUp();
40  $this->dataProviderCollection = new ‪DataProviderCollection();
41  }
42 
47  {
48  $this->expectException(\UnexpectedValueException::class);
49  $this->expectExceptionCode(1381597629);
50  $identifier = ‪StringUtility::getUniqueId('identifier__');
51  $dataProviderMock = $this->getMockBuilder('stdClass')->getMock();
52 
53  $this->dataProviderCollection->add($identifier, get_class($dataProviderMock));
54  }
55 
60  {
61  $this->expectException(\LogicException::class);
62  $this->expectExceptionCode(1381269811);
63  $identifier = ‪StringUtility::getUniqueId('identifier');
64  $dataProviderMock = $this->getMockBuilder('stdClass')->getMock();
65 
66  $this->dataProviderCollection->add($identifier, get_class($dataProviderMock));
67  }
68 
72  public function ‪defaultBackendLayoutIsFound()
73  {
74  $backendLayoutIdentifier = ‪StringUtility::getUniqueId('identifier');
75 
76  $dataProviderMock = $this->getMockBuilder(DefaultDataProvider::class)
77  ->setMethods(['getBackendLayout'])
78  ->disableOriginalConstructor()
79  ->getMock();
80  $backendLayoutMock = $this->getMockBuilder(BackendLayout::class)
81  ->setMethods(['getIdentifier'])
82  ->disableOriginalConstructor()
83  ->getMock();
84  $backendLayoutMock->expects(self::any())->method('getIdentifier')->willReturn($backendLayoutIdentifier);
85  $dataProviderMock->expects(self::once())->method('getBackendLayout')->willReturn($backendLayoutMock);
86 
87  $this->dataProviderCollection->add('default', $dataProviderMock);
88  $providedBackendLayout = $this->dataProviderCollection->getBackendLayout($backendLayoutIdentifier, 123);
89 
90  self::assertNotNull($providedBackendLayout);
91  self::assertEquals($backendLayoutIdentifier, $providedBackendLayout->getIdentifier());
92  }
93 
97  public function ‪providedBackendLayoutIsFound()
98  {
99  $dataProviderIdentifier = ‪StringUtility::getUniqueId('custom');
100  $backendLayoutIdentifier = ‪StringUtility::getUniqueId('identifier');
101 
102  $dataProviderMock = $this->getMockBuilder(DefaultDataProvider::class)
103  ->setMethods(['getBackendLayout'])
104  ->disableOriginalConstructor()
105  ->getMock();
106  $backendLayoutMock = $this->getMockBuilder(BackendLayout::class)
107  ->setMethods(['getIdentifier'])
108  ->disableOriginalConstructor()
109  ->getMock();
110  $backendLayoutMock->expects(self::any())->method('getIdentifier')->willReturn($backendLayoutIdentifier);
111  $dataProviderMock->expects(self::once())->method('getBackendLayout')->willReturn($backendLayoutMock);
112 
113  $this->dataProviderCollection->add($dataProviderIdentifier, $dataProviderMock);
114  $providedBackendLayout = $this->dataProviderCollection->getBackendLayout($dataProviderIdentifier . '__' . $backendLayoutIdentifier, 123);
115 
116  self::assertNotNull($providedBackendLayout);
117  self::assertEquals($backendLayoutIdentifier, $providedBackendLayout->getIdentifier());
118  }
119 }
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\DataProviderCollectionTest\$dataProviderCollection
‪TYPO3 CMS Backend View BackendLayout DataProviderCollection $dataProviderCollection
Definition: DataProviderCollectionTest.php:31
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\DataProviderCollectionTest\defaultBackendLayoutIsFound
‪defaultBackendLayoutIsFound()
Definition: DataProviderCollectionTest.php:71
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\DataProviderCollectionTest\setUp
‪setUp()
Definition: DataProviderCollectionTest.php:36
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection
Definition: DataProviderCollection.php:25
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\DataProviderCollectionTest
Definition: DataProviderCollectionTest.php:28
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout
Definition: BackendLayoutCollectionTest.php:16
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\DataProviderCollectionTest\invalidIdentifierIsRecognizedOnAdding
‪invalidIdentifierIsRecognizedOnAdding()
Definition: DataProviderCollectionTest.php:45
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:92
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\DataProviderCollectionTest\invalidInterfaceIsRecognizedOnAdding
‪invalidInterfaceIsRecognizedOnAdding()
Definition: DataProviderCollectionTest.php:58
‪TYPO3\CMS\Backend\Tests\Unit\View\BackendLayout\DataProviderCollectionTest\providedBackendLayoutIsFound
‪providedBackendLayoutIsFound()
Definition: DataProviderCollectionTest.php:96
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayout
Definition: BackendLayout.php:25
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider
Definition: DefaultDataProvider.php:31