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