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