TYPO3 CMS  TYPO3_7-6
DataProviderCollectionTest.php
Go to the documentation of this file.
1 <?php
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 
21 {
26 
30  protected function setUp()
31  {
32  $this->dataProviderCollection = new \TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection();
33  }
34 
40  {
41  $identifier = $this->getUniqueId('identifier__');
42  $dataProviderMock = $this->getMock('stdClass');
43 
44  $this->dataProviderCollection->add($identifier, get_class($dataProviderMock));
45  }
46 
52  {
53  $identifier = $this->getUniqueId('identifier');
54  $dataProviderMock = $this->getMock('stdClass');
55 
56  $this->dataProviderCollection->add($identifier, get_class($dataProviderMock));
57  }
58 
62  public function defaultBackendLayoutIsFound()
63  {
64  $backendLayoutIdentifier = $this->getUniqueId('identifier');
65 
66  $dataProviderMock = $this->getMock(\TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider::class, ['getBackendLayout'], [], '', false);
67  $backendLayoutMock = $this->getMock(\TYPO3\CMS\Backend\View\BackendLayout\BackendLayout::class, ['getIdentifier'], [], '', false);
68  $backendLayoutMock->expects($this->any())->method('getIdentifier')->will($this->returnValue($backendLayoutIdentifier));
69  $dataProviderMock->expects($this->once())->method('getBackendLayout')->will($this->returnValue($backendLayoutMock));
70 
71  $this->dataProviderCollection->add('default', $dataProviderMock);
72  $providedBackendLayout = $this->dataProviderCollection->getBackendLayout($backendLayoutIdentifier, 123);
73 
74  $this->assertNotNull($providedBackendLayout);
75  $this->assertEquals($backendLayoutIdentifier, $providedBackendLayout->getIdentifier());
76  }
77 
81  public function providedBackendLayoutIsFound()
82  {
83  $dataProviderIdentifier = $this->getUniqueId('custom');
84  $backendLayoutIdentifier = $this->getUniqueId('identifier');
85 
86  $dataProviderMock = $this->getMock(\TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider::class, ['getBackendLayout'], [], '', false);
87  $backendLayoutMock = $this->getMock(\TYPO3\CMS\Backend\View\BackendLayout\BackendLayout::class, ['getIdentifier'], [], '', false);
88  $backendLayoutMock->expects($this->any())->method('getIdentifier')->will($this->returnValue($backendLayoutIdentifier));
89  $dataProviderMock->expects($this->once())->method('getBackendLayout')->will($this->returnValue($backendLayoutMock));
90 
91  $this->dataProviderCollection->add($dataProviderIdentifier, $dataProviderMock);
92  $providedBackendLayout = $this->dataProviderCollection->getBackendLayout($dataProviderIdentifier . '__' . $backendLayoutIdentifier, 123);
93 
94  $this->assertNotNull($providedBackendLayout);
95  $this->assertEquals($backendLayoutIdentifier, $providedBackendLayout->getIdentifier());
96  }
97 }