‪TYPO3CMS  ‪main
BackendLayoutViewTest.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\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
27 final class ‪BackendLayoutViewTest extends FunctionalTestCase
28 {
29  private const ‪RUNTIME_CACHE_ENTRY = 'backendUtilityBeGetRootLine';
30 
33 
34  protected function ‪setUp(): void
35  {
36  parent::setUp();
37  $this->runtimeCache = $this->get(CacheManager::class)->getCache('runtime');
38  $this->subject = $this->get(BackendLayoutView::class);
39  }
40 
41  protected function ‪tearDown(): void
42  {
43  $this->runtimeCache->remove(self::RUNTIME_CACHE_ENTRY);
44  parent::tearDown();
45  }
46 
47  #[DataProvider('selectedCombinedIdentifierIsDeterminedDataProvider')]
48  #[Test]
49  public function ‪selectedCombinedIdentifierIsDetermined(false|string $expected, array $page, array $rootLine): void
50  {
51  $pageId = $page['uid'];
52  if ($pageId !== false) {
53  $this->‪mockRootLine((int)$pageId, $rootLine);
54  }
55 
56  $selectedCombinedIdentifier = $this->subject->getSelectedCombinedIdentifier($pageId);
57  self::assertEquals($expected, $selectedCombinedIdentifier);
58  }
59 
61  {
62  return [
63  'first level w/o layout' => [
64  '0',
65  ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
66  [
67  ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
68  ['uid' => 0, 'pid' => null],
69  ],
70  ],
71  'first level with layout' => [
72  '1',
73  ['uid' => 1, 'pid' => 0, 'backend_layout' => '1', 'backend_layout_next_level' => '0'],
74  [
75  ['uid' => 1, 'pid' => 0, 'backend_layout' => '1', 'backend_layout_next_level' => '0'],
76  ['uid' => 0, 'pid' => null],
77  ],
78  ],
79  'first level with provided layout' => [
80  'mine_current',
81  ['uid' => 1, 'pid' => 0, 'backend_layout' => 'mine_current', 'backend_layout_next_level' => '0'],
82  [
83  ['uid' => 1, 'pid' => 0, 'backend_layout' => 'mine_current', 'backend_layout_next_level' => '0'],
84  ['uid' => 0, 'pid' => null],
85  ],
86  ],
87  'first level with next layout' => [
88  '0',
89  ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '1'],
90  [
91  ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '1'],
92  ['uid' => 0, 'pid' => null],
93  ],
94  ],
95  'first level with provided next layout' => [
96  '0',
97  ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => 'mine_next'],
98  [
99  ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => 'mine_next'],
100  ['uid' => 0, 'pid' => null],
101  ],
102  ],
103  'second level w/o layout, first level with layout' => [
104  '0',
105  ['uid' => 2, 'pid' => 1, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
106  [
107  ['uid' => 2, 'pid' => 1, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
108  ['uid' => 1, 'pid' => 0, 'backend_layout' => '1', 'backend_layout_next_level' => '0'],
109  ['uid' => 0, 'pid' => null],
110  ],
111  ],
112  'second level w/o layout, first level with next layout' => [
113  '1',
114  ['uid' => 2, 'pid' => 1, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
115  [
116  ['uid' => 2, 'pid' => 1, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
117  ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '1'],
118  ['uid' => 0, 'pid' => null],
119  ],
120  ],
121  'second level with layout, first level with next layout' => [
122  '2',
123  ['uid' => 2, 'pid' => 1, 'backend_layout' => '2', 'backend_layout_next_level' => '0'],
124  [
125  ['uid' => 2, 'pid' => 1, 'backend_layout' => '2', 'backend_layout_next_level' => '0'],
126  ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '1'],
127  ['uid' => 0, 'pid' => null],
128  ],
129  ],
130  'second level with layouts, first level resetting all layouts' => [
131  '1',
132  ['uid' => 2, 'pid' => 1, 'backend_layout' => '1', 'backend_layout_next_level' => '1'],
133  [
134  ['uid' => 2, 'pid' => 1, 'backend_layout' => '1', 'backend_layout_next_level' => '1'],
135  ['uid' => 1, 'pid' => 0, 'backend_layout' => '-1', 'backend_layout_next_level' => '-1'],
136  ['uid' => 0, 'pid' => null],
137  ],
138  ],
139  'second level with provided layouts, first level resetting all layouts' => [
140  'mine_current',
141  ['uid' => 2, 'pid' => 1, 'backend_layout' => 'mine_current', 'backend_layout_next_level' => 'mine_next'],
142  [
143  ['uid' => 2, 'pid' => 1, 'backend_layout' => 'mine_current', 'backend_layout_next_level' => 'mine_next'],
144  ['uid' => 1, 'pid' => 0, 'backend_layout' => '-1', 'backend_layout_next_level' => '-1'],
145  ['uid' => 0, 'pid' => null],
146  ],
147  ],
148  'second level resetting layout, first level with next layout' => [
149  false,
150  ['uid' => 2, 'pid' => 1, 'backend_layout' => '-1', 'backend_layout_next_level' => '0'],
151  [
152  ['uid' => 2, 'pid' => 1, 'backend_layout' => '-1', 'backend_layout_next_level' => '0'],
153  ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '1'],
154  ['uid' => 0, 'pid' => null],
155  ],
156  ],
157  'second level resetting next layout, first level with next layout' => [
158  '1',
159  ['uid' => 2, 'pid' => 1, 'backend_layout' => '0', 'backend_layout_next_level' => '-1'],
160  [
161  ['uid' => 2, 'pid' => 1, 'backend_layout' => '0', 'backend_layout_next_level' => '-1'],
162  ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '1'],
163  ['uid' => 0, 'pid' => null],
164  ],
165  ],
166  'third level w/o layout, second level resetting layout, first level with next layout' => [
167  '1',
168  ['uid' => 3, 'pid' => 2, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
169  [
170  ['uid' => 3, 'pid' => 2, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
171  ['uid' => 2, 'pid' => 1, 'backend_layout' => '-1', 'backend_layout_next_level' => '0'],
172  ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '1'],
173  ['uid' => 0, 'pid' => null],
174  ],
175  ],
176  'third level w/o layout, second level resetting next layout, first level with next layout' => [
177  false,
178  ['uid' => 3, 'pid' => 2, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
179  [
180  ['uid' => 3, 'pid' => 2, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
181  ['uid' => 2, 'pid' => 1, 'backend_layout' => '0', 'backend_layout_next_level' => '-1'],
182  ['uid' => 1, 'pid' => 0, 'backend_layout' => '0', 'backend_layout_next_level' => '1'],
183  ['uid' => 0, 'pid' => null],
184  ],
185  ],
186  'third level with provided layouts, second level w/o layout, first level resetting layouts' => [
187  'mine_current',
188  ['uid' => 3, 'pid' => 2, 'backend_layout' => 'mine_current', 'backend_layout_next_level' => 'mine_next'],
189  [
190  ['uid' => 3, 'pid' => 2, 'backend_layout' => 'mine_current', 'backend_layout_next_level' => 'mine_next'],
191  ['uid' => 2, 'pid' => 1, 'backend_layout' => '0', 'backend_layout_next_level' => '0'],
192  ['uid' => 1, 'pid' => 0, 'backend_layout' => '-1', 'backend_layout_next_level' => '-1'],
193  ['uid' => 0, 'pid' => null],
194  ],
195  ],
196  ];
197  }
198 
199  private function ‪mockRootLine(int $pageId, array $rootLine): void
200  {
201  $this->runtimeCache->set(self::RUNTIME_CACHE_ENTRY, [
202  $pageId . '--' => $rootLine, // plain, no overlay
203  $pageId . '--1' => $rootLine, // workspace overlay
204  ]);
205  }
206 }
‪TYPO3\CMS\Backend\Tests\Functional\View
Definition: BackendLayoutViewTest.php:18
‪TYPO3\CMS\Backend\Tests\Functional\View\BackendLayoutViewTest\setUp
‪setUp()
Definition: BackendLayoutViewTest.php:34
‪TYPO3\CMS\Backend\Tests\Functional\View\BackendLayoutViewTest\mockRootLine
‪mockRootLine(int $pageId, array $rootLine)
Definition: BackendLayoutViewTest.php:199
‪TYPO3\CMS\Backend\Tests\Functional\View\BackendLayoutViewTest\selectedCombinedIdentifierIsDetermined
‪selectedCombinedIdentifierIsDetermined(false|string $expected, array $page, array $rootLine)
Definition: BackendLayoutViewTest.php:49
‪TYPO3\CMS\Backend\Tests\Functional\View\BackendLayoutViewTest\tearDown
‪tearDown()
Definition: BackendLayoutViewTest.php:41
‪TYPO3\CMS\Backend\Tests\Functional\View\BackendLayoutViewTest
Definition: BackendLayoutViewTest.php:28
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Backend\Tests\Functional\View\BackendLayoutViewTest\RUNTIME_CACHE_ENTRY
‪const RUNTIME_CACHE_ENTRY
Definition: BackendLayoutViewTest.php:29
‪TYPO3\CMS\Backend\Tests\Functional\View\BackendLayoutViewTest\$runtimeCache
‪FrontendInterface $runtimeCache
Definition: BackendLayoutViewTest.php:31
‪TYPO3\CMS\Backend\Tests\Functional\View\BackendLayoutViewTest\$subject
‪BackendLayoutView $subject
Definition: BackendLayoutViewTest.php:32
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Backend\View\BackendLayoutView
Definition: BackendLayoutView.php:37
‪TYPO3\CMS\Backend\Tests\Functional\View\BackendLayoutViewTest\selectedCombinedIdentifierIsDeterminedDataProvider
‪static selectedCombinedIdentifierIsDeterminedDataProvider()
Definition: BackendLayoutViewTest.php:60