b00a6b853a874175b8ffdddfdae088f3a8dc97d7
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / View / BackendLayoutViewTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\View;
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 behaviour of \TYPO3\CMS\Backend\View\BackendLayoutView
19 */
20 class BackendLayoutViewTest extends \TYPO3\Components\TestingFramework\Core\UnitTestCase
21 {
22 /**
23 * @var \TYPO3\CMS\Backend\View\BackendLayoutView|\PHPUnit_Framework_MockObject_MockObject
24 */
25 protected $backendLayoutView;
26
27 /**
28 * Sets up this test case.
29 */
30 protected function setUp()
31 {
32 $this->backendLayoutView = $this->getAccessibleMock(
33 \TYPO3\CMS\Backend\View\BackendLayoutView::class,
34 ['getPage', 'getRootLine'],
35 [], '', false
36 );
37 }
38
39 /**
40 * @param bool|string $expected
41 * @param array $page
42 * @param array $rootLine
43 * @test
44 * @dataProvider selectedCombinedIdentifierIsDeterminedDataProvider
45 */
46 public function selectedCombinedIdentifierIsDetermined($expected, array $page, array $rootLine)
47 {
48 $pageId = $page['uid'];
49
50 $this->backendLayoutView->expects($this->once())
51 ->method('getPage')->with($this->equalTo($pageId))
52 ->will($this->returnValue($page));
53 $this->backendLayoutView->expects($this->any())
54 ->method('getRootLine')->with($this->equalTo($pageId))
55 ->will($this->returnValue($rootLine));
56
57 $selectedCombinedIdentifier = $this->backendLayoutView->_call('getSelectedCombinedIdentifier', $pageId);
58 $this->assertEquals($expected, $selectedCombinedIdentifier);
59 }
60
61 /**
62 * @return array
63 */
64 public function selectedCombinedIdentifierIsDeterminedDataProvider()
65 {
66 return [
67 'first level w/o layout' => [
68 '0',
69 ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
70 [
71 ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
72 ['uid' => 0, 'pid' => null],
73 ]
74 ],
75 'first level with layout' => [
76 '1',
77 ['uid' => 1, 'pid' => 0, 'backend_layout' => '1', 'backend_layout_next_level' => '0'],
78 [
79 ['uid' => 1, 'pid' => 0, 'backend_layout' => '1', 'backend_layout_next_level' => '0'],
80 ['uid' => 0, 'pid' => null],
81 ]
82 ],
83 'first level with provided layout' => [
84 'mine_current',
85 ['uid' => 1, 'pid' => 0, 'backend_layout' => 'mine_current', 'backend_layout_next_level' => '0'],
86 [
87 ['uid' => 1, 'pid' => 0, 'backend_layout' => 'mine_current', 'backend_layout_next_level' => '0'],
88 ['uid' => 0, 'pid' => null],
89 ]
90 ],
91 'first level with next layout' => [
92 '0',
93 ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '1'],
94 [
95 ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '1'],
96 ['uid' => 0, 'pid' => null],
97 ]
98 ],
99 'first level with provided next layout' => [
100 '0',
101 ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => 'mine_next'],
102 [
103 ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => 'mine_next'],
104 ['uid' => 0, 'pid' => null],
105 ]
106 ],
107 'second level w/o layout, first level with layout' => [
108 '0',
109 ['uid' => 2, 'pid' => 1, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
110 [
111 ['uid' => 2, 'pid' => 1, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
112 ['uid' => 1, 'pid' => 0, 'backend_layout' => '1', 'backend_layout_next_level' => '0'],
113 ['uid' => 0, 'pid' => null],
114 ]
115 ],
116 'second level w/o layout, first level with next layout' => [
117 '1',
118 ['uid' => 2, 'pid' => 1, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
119 [
120 ['uid' => 2, 'pid' => 1, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
121 ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '1'],
122 ['uid' => 0, 'pid' => null],
123 ]
124 ],
125 'second level with layout, first level with next layout' => [
126 '2',
127 ['uid' => 2, 'pid' => 1, 'backend_layout' => '2', 'backend_layout_next_level' => '0'],
128 [
129 ['uid' => 2, 'pid' => 1, 'backend_layout' => '2', 'backend_layout_next_level' => '0'],
130 ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '1'],
131 ['uid' => 0, 'pid' => null],
132 ]
133 ],
134 'second level with layouts, first level resetting all layouts' => [
135 '1',
136 ['uid' => 2, 'pid' => 1, 'backend_layout' => '1', 'backend_layout_next_level' => '1'],
137 [
138 ['uid' => 2, 'pid' => 1, 'backend_layout' => '1', 'backend_layout_next_level' => '1'],
139 ['uid' => 1, 'pid' => 0, 'backend_layout' => '-1', 'backend_layout_next_level' => '-1'],
140 ['uid' => 0, 'pid' => null],
141 ]
142 ],
143 'second level with provided layouts, first level resetting all layouts' => [
144 'mine_current',
145 ['uid' => 2, 'pid' => 1, 'backend_layout' => 'mine_current', 'backend_layout_next_level' => 'mine_next'],
146 [
147 ['uid' => 2, 'pid' => 1, 'backend_layout' => 'mine_current', 'backend_layout_next_level' => 'mine_next'],
148 ['uid' => 1, 'pid' => 0, 'backend_layout' => '-1', 'backend_layout_next_level' => '-1'],
149 ['uid' => 0, 'pid' => null],
150 ]
151 ],
152 'second level resetting layout, first level with next layout' => [
153 false,
154 ['uid' => 2, 'pid' => 1, 'backend_layout' => '-1', 'backend_layout_next_level' => '0'],
155 [
156 ['uid' => 2, 'pid' => 1, 'backend_layout' => '-1', 'backend_layout_next_level' => '0'],
157 ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '1'],
158 ['uid' => 0, 'pid' => null],
159 ]
160 ],
161 'second level resetting next layout, first level with next layout' => [
162 '1',
163 ['uid' => 2, 'pid' => 1, 'backend_layout' => '0', 'backend_layout_next_level' => '-1'],
164 [
165 ['uid' => 2, 'pid' => 1, 'backend_layout' => '0', 'backend_layout_next_level' => '-1'],
166 ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '1'],
167 ['uid' => 0, 'pid' => null],
168 ]
169 ],
170 'third level w/o layout, second level resetting layout, first level with next layout' => [
171 '1',
172 ['uid' => 3, 'pid' => 2, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
173 [
174 ['uid' => 3, 'pid' => 2, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
175 ['uid' => 2, 'pid' => 1, 'backend_layout' => '-1', 'backend_layout_next_level' => '0'],
176 ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '1'],
177 ['uid' => 0, 'pid' => null],
178 ]
179 ],
180 'third level w/o layout, second level resetting next layout, first level with next layout' => [
181 false,
182 ['uid' => 3, 'pid' => 2, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
183 [
184 ['uid' => 3, 'pid' => 2, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
185 ['uid' => 2, 'pid' => 1, 'backend_layout' => '0', 'backend_layout_next_level' => '-1'],
186 ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '1'],
187 ['uid' => 0, 'pid' => null],
188 ]
189 ],
190 'third level with provided layouts, second level w/o layout, first level resetting layouts' => [
191 'mine_current',
192 ['uid' => 3, 'pid' => 2, 'backend_layout' => 'mine_current', 'backend_layout_next_level' => 'mine_next'],
193 [
194 ['uid' => 3, 'pid' => 2, 'backend_layout' => 'mine_current', 'backend_layout_next_level' => 'mine_next'],
195 ['uid' => 2, 'pid' => 1, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
196 ['uid' => 1, 'pid' => 0, 'backend_layout' => '-1', 'backend_layout_next_level' => '-1'],
197 ['uid' => 0, 'pid' => null],
198 ]
199 ],
200 ];
201 }
202 }