‪TYPO3CMS  11.5
BackendLayoutRendererTest.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 
27 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerFactory;
28 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerWriter;
29 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
30 
34 class ‪BackendLayoutRendererTest extends FunctionalTestCase
35 {
37 
38  protected const ‪LANGUAGE_PRESETS = [];
39 
40  protected ‪$coreExtensionsToLoad = ['workspaces'];
41 
46 
47  protected function ‪setUp(): void
48  {
49  parent::setUp();
50 
51  $this->backendUser = $this->setUpBackendUserFromFixture(1);
52 
53  $this->withDatabaseSnapshot(function () {
54  $this->‪setUpDatabase();
55  });
56  }
57 
58  protected function ‪tearDown(): void
59  {
60  unset($this->backendUser);
61  parent::tearDown();
62  }
63 
64  protected function ‪setUpDatabase(): void
65  {
67 
68  $scenarioFile = __DIR__ . '/../Fixtures/DefaultViewScenario.yaml';
69  $factory = DataHandlerFactory::fromYamlFile($scenarioFile);
70  $writer = DataHandlerWriter::withBackendUser($this->backendUser);
71  $writer->invokeFactory($factory);
72  static::failIfArrayIsNotEmpty(
73  $writer->getErrors()
74  );
75  }
76 
82  protected function ‪getPageLayoutContext(int $pageId, array $configuration)
83  {
84  // Create a BackendLayout
85  $backendLayout = new ‪BackendLayout('layout1', 'Layout 1', $configuration);
86 
87  // Create a mock for the PageLayoutContext class
88  return $this->createConfiguredMock(
89  PageLayoutContext::class,
90  [
91  'getBackendLayout' => $backendLayout,
92  'getPageId' => $pageId,
93  ]
94  );
95  }
96 
101  protected function ‪getSubject(PageLayoutContext $context): BackendLayoutRenderer
102  {
103  return GeneralUtility::makeInstance(BackendLayoutRenderer::class, $context);
104  }
105 
109  public function ‪emptyBackendLayoutIsRendered(): void
110  {
111  $configuration['__config']['backend_layout.'] = [
112  'rows.' => [],
113  ];
114  $pageLayoutContext = $this->‪getPageLayoutContext(1100, $configuration);
115  $subject = $this->‪getSubject($pageLayoutContext);
116 
117  // Test the subject
118  self::assertCount(0, $subject->getGridForPageLayoutContext($pageLayoutContext)->getRows());
119  }
120 
124  public function ‪oneRowBackendLayoutIsRendered(): void
125  {
126  $configuration['__config']['backend_layout.'] = [
127  'rows.' => [
128  0 => [
129  'columns.' => [],
130  ],
131  ],
132  ];
133  $pageLayoutContext = $this->‪getPageLayoutContext(1100, $configuration);
134  $subject = $this->‪getSubject($pageLayoutContext);
135 
136  // Test the subject
137  self::assertCount(1, $subject->getGridForPageLayoutContext($pageLayoutContext)->getRows());
138  self::assertCount(0, $subject->getGridForPageLayoutContext($pageLayoutContext)->getColumns());
139  }
140 
144  public function ‪multipleRowsBackendLayoutIsRendered(): void
145  {
146  $configuration['__config']['backend_layout.'] = [
147  'rows.' => [
148  0 => [
149  'columns.' => [],
150  ],
151  1 => [
152  'columns.' => [],
153  ],
154  ],
155  ];
156  $pageLayoutContext = $this->‪getPageLayoutContext(1100, $configuration);
157  $subject = $this->‪getSubject($pageLayoutContext);
158 
159  // Test the subject
160  self::assertCount(2, $subject->getGridForPageLayoutContext($pageLayoutContext)->getRows());
161  self::assertCount(0, $subject->getGridForPageLayoutContext($pageLayoutContext)->getColumns());
162  }
163 
167  public function ‪oneRowOneColBackendLayoutIsRendered(): void
168  {
169  $configuration['__config']['backend_layout.'] = [
170  'rows.' => [
171  0 => [
172  'columns.' => [
173  0 => [
174  'colPos' => 0,
175  ],
176  ],
177  ],
178  ],
179  ];
180  $pageLayoutContext = $this->‪getPageLayoutContext(1100, $configuration);
181  $subject = $this->‪getSubject($pageLayoutContext);
182 
183  // Test the subject
184  self::assertCount(1, $subject->getGridForPageLayoutContext($pageLayoutContext)->getRows());
185  self::assertCount(1, $subject->getGridForPageLayoutContext($pageLayoutContext)->getColumns());
186  foreach ($subject->getGridForPageLayoutContext($pageLayoutContext)->getColumns() as $column) {
187  self::assertCount(1, $column->getItems());
188  }
189  }
190 
194  public function ‪oneRowMultipleColsBackendLayoutIsRendered(): void
195  {
196  $configuration['__config']['backend_layout.'] = [
197  'rows.' => [
198  0 => [
199  'columns.' => [
200  0 => [
201  'colPos' => 0,
202  ],
203  1 => [
204  'colPos' => 1,
205  ],
206  ],
207  ],
208  ],
209  ];
210  $pageLayoutContext = $this->‪getPageLayoutContext(1100, $configuration);
211  $subject = $this->‪getSubject($pageLayoutContext);
212 
213  // Test the subject
214  self::assertCount(1, $subject->getGridForPageLayoutContext($pageLayoutContext)->getRows());
215  self::assertCount(2, $subject->getGridForPageLayoutContext($pageLayoutContext)->getColumns());
216  foreach ($subject->getGridForPageLayoutContext($pageLayoutContext)->getColumns() as $column) {
217  self::assertCount(1, $column->getItems());
218  }
219  }
220 
224  public function ‪multipleRowsOneColBackendLayoutIsRendered(): void
225  {
226  $configuration['__config']['backend_layout.'] = [
227  'rows.' => [
228  0 => [
229  'columns.' => [
230  0 => [
231  'colPos' => 0,
232  ],
233  ],
234  ],
235  1 => [
236  'columns.' => [
237  0 => [
238  'colPos' => 1,
239  ],
240  ],
241  ],
242  ],
243  ];
244  $pageLayoutContext = $this->‪getPageLayoutContext(1100, $configuration);
245  $subject = $this->‪getSubject($pageLayoutContext);
246 
247  // Test the subject
248  self::assertCount(2, $subject->getGridForPageLayoutContext($pageLayoutContext)->getRows());
249  self::assertCount(2, $subject->getGridForPageLayoutContext($pageLayoutContext)->getColumns());
250  foreach ($subject->getGridForPageLayoutContext($pageLayoutContext)->getColumns() as $column) {
251  self::assertCount(1, $column->getItems());
252  }
253  }
254 
259  {
260  $configuration['__config']['backend_layout.'] = [
261  'rows.' => [
262  0 => [
263  'columns.' => [
264  0 => [
265  'colPos' => 0,
266  ],
267  1 => [
268  'colPos' => 1,
269  ],
270  ],
271  ],
272  1 => [
273  'columns.' => [
274  0 => [
275  'colPos' => 2,
276  ],
277  1 => [
278  'colPos' => 3,
279  ],
280  ],
281  ],
282  ],
283  ];
284  $pageLayoutContext = $this->‪getPageLayoutContext(1100, $configuration);
285  $subject = $this->‪getSubject($pageLayoutContext);
286 
287  // Test the subject
288  self::assertCount(2, $subject->getGridForPageLayoutContext($pageLayoutContext)->getRows());
289  self::assertCount(4, $subject->getGridForPageLayoutContext($pageLayoutContext)->getColumns());
290  foreach ($subject->getGridForPageLayoutContext($pageLayoutContext)->getColumns() as $column) {
291  self::assertCount(1, $column->getItems());
292  }
293  }
294 
298  public function ‪noColPosBackendLayoutIsRendered(): void
299  {
300  $configuration['__config']['backend_layout.'] = [
301  'rows.' => [
302  0 => [
303  'columns.' => [
304  0 => [
305  ],
306  1 => [
307  ],
308  ],
309  ],
310  ],
311  ];
312  $pageLayoutContext = $this->‪getPageLayoutContext(1100, $configuration);
313  $subject = $this->‪getSubject($pageLayoutContext);
314 
315  // Test the subject
316  self::assertCount(1, $subject->getGridForPageLayoutContext($pageLayoutContext)->getRows());
317  self::assertCount(1, $subject->getGridForPageLayoutContext($pageLayoutContext)->getColumns());
318  foreach ($subject->getGridForPageLayoutContext($pageLayoutContext)->getColumns() as $column) {
319  self::assertCount(0, $column->getItems());
320  }
321  }
322 }
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing
Definition: BackendLayoutRendererTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:36
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing\BackendLayoutRendererTest\multipleRowsBackendLayoutIsRendered
‪multipleRowsBackendLayoutIsRendered()
Definition: BackendLayoutRendererTest.php:143
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing\BackendLayoutRendererTest\getSubject
‪BackendLayoutRenderer getSubject(PageLayoutContext $context)
Definition: BackendLayoutRendererTest.php:100
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing\BackendLayoutRendererTest\oneRowBackendLayoutIsRendered
‪oneRowBackendLayoutIsRendered()
Definition: BackendLayoutRendererTest.php:123
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing\BackendLayoutRendererTest\setUp
‪setUp()
Definition: BackendLayoutRendererTest.php:46
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing\BackendLayoutRendererTest\oneRowMultipleColsBackendLayoutIsRendered
‪oneRowMultipleColsBackendLayoutIsRendered()
Definition: BackendLayoutRendererTest.php:193
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing\BackendLayoutRendererTest\tearDown
‪tearDown()
Definition: BackendLayoutRendererTest.php:57
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing\BackendLayoutRendererTest\$backendUser
‪BackendUserAuthentication $backendUser
Definition: BackendLayoutRendererTest.php:44
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:598
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing\BackendLayoutRendererTest\multipleRowsMultipleColsBackendLayoutIsRendered
‪multipleRowsMultipleColsBackendLayoutIsRendered()
Definition: BackendLayoutRendererTest.php:257
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing\BackendLayoutRendererTest\emptyBackendLayoutIsRendered
‪emptyBackendLayoutIsRendered()
Definition: BackendLayoutRendererTest.php:108
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing\BackendLayoutRendererTest\noColPosBackendLayoutIsRendered
‪noColPosBackendLayoutIsRendered()
Definition: BackendLayoutRendererTest.php:297
‪TYPO3\CMS\Backend\View\Drawing\BackendLayoutRenderer
Definition: BackendLayoutRenderer.php:47
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing\BackendLayoutRendererTest\setUpDatabase
‪setUpDatabase()
Definition: BackendLayoutRendererTest.php:63
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing\BackendLayoutRendererTest\oneRowOneColBackendLayoutIsRendered
‪oneRowOneColBackendLayoutIsRendered()
Definition: BackendLayoutRendererTest.php:166
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing\BackendLayoutRendererTest\getPageLayoutContext
‪PageLayoutContext PHPUnit Framework MockObject MockObject getPageLayoutContext(int $pageId, array $configuration)
Definition: BackendLayoutRendererTest.php:81
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing\BackendLayoutRendererTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: BackendLayoutRendererTest.php:37
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing\BackendLayoutRendererTest\multipleRowsOneColBackendLayoutIsRendered
‪multipleRowsOneColBackendLayoutIsRendered()
Definition: BackendLayoutRendererTest.php:223
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing\BackendLayoutRendererTest
Definition: BackendLayoutRendererTest.php:35
‪TYPO3\CMS\Backend\View\PageLayoutContext
Definition: PageLayoutContext.php:43
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:70
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayout
Definition: BackendLayout.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Tests\Functional\View\Drawing\BackendLayoutRendererTest\$coreExtensionsToLoad
‪$coreExtensionsToLoad
Definition: BackendLayoutRendererTest.php:39