‪TYPO3CMS  11.5
SiteDatabaseEditRowTest.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 Prophecy\PhpUnit\ProphecyTrait;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
33 class ‪SiteDatabaseEditRowTest extends UnitTestCase
34 {
35  use ProphecyTrait;
36 
37  public function ‪setUp(): void
38  {
39  $this->backupEnvironment = true;
40  parent::setUp();
42  $this->prophesize(ApplicationContext::class)->reveal(),
43  true,
44  false,
45  '',
46  '',
47  '',
48  '',
49  '',
50  ''
51  );
52  }
53 
58  {
59  $input = [
60  'command' => 'new',
61  'foo' => 'bar',
62  ];
63  $siteConfigurationProphecy = $this->prophesize(SiteConfiguration::class);
64  self::assertSame($input, (new ‪SiteDatabaseEditRow($siteConfigurationProphecy->reveal()))->addData($input));
65  }
66 
71  {
72  $input = [
73  'command' => 'edit',
74  'databaseRow' => [
75  'foo' => 'bar',
76  ],
77  ];
78  $siteConfigurationProphecy = $this->prophesize(SiteConfiguration::class);
79  self::assertSame($input, (new SiteDatabaseEditRow($siteConfigurationProphecy->reveal()))->addData($input));
80  }
81 
86  {
87  $input = [
88  'command' => 'edit',
89  'tableName' => 'foo',
90  ];
91  $this->expectException(\RuntimeException::class);
92  $this->expectExceptionCode(1520886234);
93  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
94  $siteConfigurationProphecy = $this->prophesize(SiteConfiguration::class);
95  GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
96  (new SiteDatabaseEditRow($siteConfigurationProphecy->reveal()))->addData($input);
97  }
98 
102  public function ‪addDataSetsDataForSysSite(): void
103  {
104  $input = [
105  'command' => 'edit',
106  'tableName' => 'site',
107  'vanillaUid' => 23,
108  'customData' => [
109  'siteIdentifier' => 'main',
110  ],
111  ];
112  $rowData = [
113  'foo' => 'bar',
114  'rootPageId' => 42,
115  'someArray' => [
116  'foo' => 'bar',
117  ],
118  ];
119  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
120  GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
121  $siteProphecy = $this->prophesize(Site::class);
122  $siteFinderProphecy->getSiteByRootPageId(23)->willReturn($siteProphecy->reveal());
123  $siteProphecy->getIdentifier()->willReturn('testident');
124  $siteConfiguration = $this->prophesize(SiteConfiguration::class);
125  $siteConfiguration->load('testident')->willReturn($rowData);
126 
127  $expected = $input;
128  $expected['databaseRow'] = [
129  'uid' => 42,
130  'identifier' => 'main',
131  'rootPageId' => 42,
132  'pid' => 0,
133  'foo' => 'bar',
134  ];
135 
136  self::assertEquals($expected, (new SiteDatabaseEditRow($siteConfiguration->reveal()))->addData($input));
137  }
138 
143  {
144  $input = [
145  'command' => 'edit',
146  'tableName' => 'site_errorhandling',
147  'vanillaUid' => 23,
148  'inlineTopMostParentUid' => 5,
149  'inlineParentFieldName' => 'invalid',
150  ];
151  $rowData = [
152  'foo' => 'bar',
153  ];
154  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
155  GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
156  $siteProphecy = $this->prophesize(Site::class);
157  $siteFinderProphecy->getSiteByRootPageId(5)->willReturn($siteProphecy->reveal());
158  $siteProphecy->getIdentifier()->willReturn('testident');
159  $siteConfiguration = $this->prophesize(SiteConfiguration::class);
160  $siteConfiguration->load('testident')->willReturn($rowData);
161 
162  $this->expectException(\RuntimeException::class);
163  $this->expectExceptionCode(1520886092);
164  (new SiteDatabaseEditRow($siteConfiguration->reveal()))->addData($input);
165  }
166 
170  public function ‪addDataThrowsExceptionWithInvalidLanguage(): void
171  {
172  $input = [
173  'command' => 'edit',
174  'tableName' => 'site_language',
175  'vanillaUid' => 23,
176  'inlineTopMostParentUid' => 5,
177  'inlineParentFieldName' => 'invalid',
178  ];
179  $rowData = [
180  'foo' => 'bar',
181  ];
182  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
183  GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
184  $siteProphecy = $this->prophesize(Site::class);
185  $siteFinderProphecy->getSiteByRootPageId(5)->willReturn($siteProphecy->reveal());
186  $siteProphecy->getIdentifier()->willReturn('testident');
187  $siteConfiguration = $this->prophesize(SiteConfiguration::class);
188  $siteConfiguration->load('testident')->willReturn($rowData);
189 
190  $this->expectException(\RuntimeException::class);
191  $this->expectExceptionCode(1520886092);
192  (new SiteDatabaseEditRow($siteConfiguration->reveal()))->addData($input);
193  }
194 
198  public function ‪addDataAddLanguageRow(): void
199  {
200  $input = [
201  'command' => 'edit',
202  'tableName' => 'site_language',
203  'vanillaUid' => 23,
204  'inlineTopMostParentUid' => 5,
205  'inlineParentFieldName' => 'languages',
206  ];
207  $rowData = [
208  'languages' => [
209  23 => [
210  'foo' => 'bar',
211  ],
212  ],
213  ];
214  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
215  GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
216  $siteProphecy = $this->prophesize(Site::class);
217  $siteFinderProphecy->getSiteByRootPageId(5)->willReturn($siteProphecy->reveal());
218  $siteProphecy->getIdentifier()->willReturn('testident');
219  $siteConfiguration = $this->prophesize(SiteConfiguration::class);
220  $siteConfiguration->load('testident')->willReturn($rowData);
221 
222  $expected = $input;
223  $expected['databaseRow'] = [
224  'foo' => 'bar',
225  'uid' => 23,
226  'pid' => 0,
227  ];
228 
229  self::assertEquals($expected, (new SiteDatabaseEditRow($siteConfiguration->reveal()))->addData($input));
230  }
231 }
‪TYPO3\CMS\Core\Core\ApplicationContext
Definition: ApplicationContext.php:39
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest\addDataDoesNotChangeResultIfCommandIsNotEdit
‪addDataDoesNotChangeResultIfCommandIsNotEdit()
Definition: SiteDatabaseEditRowTest.php:56
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Core\Configuration\SiteConfiguration
Definition: SiteConfiguration.php:43
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:42
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest
Definition: SiteDatabaseEditRowTest.php:34
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest\addDataThrowsExceptionWithInvalidLanguage
‪addDataThrowsExceptionWithInvalidLanguage()
Definition: SiteDatabaseEditRowTest.php:169
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest\setUp
‪setUp()
Definition: SiteDatabaseEditRowTest.php:36
‪TYPO3\CMS\Core\Core\Environment\initialize
‪static initialize(ApplicationContext $context, bool $cli, bool $composerMode, string $projectPath, string $publicPath, string $varPath, string $configPath, string $currentScript, string $os)
Definition: Environment.php:111
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest\addDataAddLanguageRow
‪addDataAddLanguageRow()
Definition: SiteDatabaseEditRowTest.php:197
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest\addDataDoesNotChangeResultIfDatabaseRowIsNotEmpty
‪addDataDoesNotChangeResultIfDatabaseRowIsNotEmpty()
Definition: SiteDatabaseEditRowTest.php:69
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest\addDataSetsDataForSysSite
‪addDataSetsDataForSysSite()
Definition: SiteDatabaseEditRowTest.php:101
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:43
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest\addDataThrowsExceptionIfTableNameIsNotExpected
‪addDataThrowsExceptionIfTableNameIsNotExpected()
Definition: SiteDatabaseEditRowTest.php:84
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest\addDataThrowsExceptionWithInvalidErrorHandling
‪addDataThrowsExceptionWithInvalidErrorHandling()
Definition: SiteDatabaseEditRowTest.php:141
‪TYPO3\CMS\Backend\Form\FormDataProvider\SiteDatabaseEditRow
Definition: SiteDatabaseEditRow.php:32
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18