[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / View / BackendLayout / DataProviderCollectionTest.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 layout data providers.
19 */
20 class DataProviderCollectionTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
21 {
22 /**
23 * @var \TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection
24 */
25 protected $dataProviderCollection;
26
27 /**
28 * Sets up this test case.
29 */
30 protected function setUp()
31 {
32 $this->dataProviderCollection = new \TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection();
33 }
34
35 /**
36 * @test
37 */
38 public function invalidIdentifierIsRecognizedOnAdding()
39 {
40 $this->expectException(\UnexpectedValueException::class);
41 $this->expectExceptionCode(1381597629);
42 $identifier = $this->getUniqueId('identifier__');
43 $dataProviderMock = $this->getMockBuilder('stdClass')->getMock();
44
45 $this->dataProviderCollection->add($identifier, get_class($dataProviderMock));
46 }
47
48 /**
49 * @test
50 */
51 public function invalidInterfaceIsRecognizedOnAdding()
52 {
53 $this->expectException(\LogicException::class);
54 $this->expectExceptionCode(1381269811);
55 $identifier = $this->getUniqueId('identifier');
56 $dataProviderMock = $this->getMockBuilder('stdClass')->getMock();
57
58 $this->dataProviderCollection->add($identifier, get_class($dataProviderMock));
59 }
60
61 /**
62 * @test
63 */
64 public function defaultBackendLayoutIsFound()
65 {
66 $backendLayoutIdentifier = $this->getUniqueId('identifier');
67
68 $dataProviderMock = $this->getMockBuilder(\TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider::class)
69 ->setMethods(['getBackendLayout'])
70 ->disableOriginalConstructor()
71 ->getMock();
72 $backendLayoutMock = $this->getMockBuilder(\TYPO3\CMS\Backend\View\BackendLayout\BackendLayout::class)
73 ->setMethods(['getIdentifier'])
74 ->disableOriginalConstructor()
75 ->getMock();
76 $backendLayoutMock->expects($this->any())->method('getIdentifier')->will($this->returnValue($backendLayoutIdentifier));
77 $dataProviderMock->expects($this->once())->method('getBackendLayout')->will($this->returnValue($backendLayoutMock));
78
79 $this->dataProviderCollection->add('default', $dataProviderMock);
80 $providedBackendLayout = $this->dataProviderCollection->getBackendLayout($backendLayoutIdentifier, 123);
81
82 $this->assertNotNull($providedBackendLayout);
83 $this->assertEquals($backendLayoutIdentifier, $providedBackendLayout->getIdentifier());
84 }
85
86 /**
87 * @test
88 */
89 public function providedBackendLayoutIsFound()
90 {
91 $dataProviderIdentifier = $this->getUniqueId('custom');
92 $backendLayoutIdentifier = $this->getUniqueId('identifier');
93
94 $dataProviderMock = $this->getMockBuilder(\TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider::class)
95 ->setMethods(['getBackendLayout'])
96 ->disableOriginalConstructor()
97 ->getMock();
98 $backendLayoutMock = $this->getMockBuilder(\TYPO3\CMS\Backend\View\BackendLayout\BackendLayout::class)
99 ->setMethods(['getIdentifier'])
100 ->disableOriginalConstructor()
101 ->getMock();
102 $backendLayoutMock->expects($this->any())->method('getIdentifier')->will($this->returnValue($backendLayoutIdentifier));
103 $dataProviderMock->expects($this->once())->method('getBackendLayout')->will($this->returnValue($backendLayoutMock));
104
105 $this->dataProviderCollection->add($dataProviderIdentifier, $dataProviderMock);
106 $providedBackendLayout = $this->dataProviderCollection->getBackendLayout($dataProviderIdentifier . '__' . $backendLayoutIdentifier, 123);
107
108 $this->assertNotNull($providedBackendLayout);
109 $this->assertEquals($backendLayoutIdentifier, $providedBackendLayout->getIdentifier());
110 }
111 }