‪TYPO3CMS  9.5
SiteDatabaseEditRowTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
31 class ‪SiteDatabaseEditRowTest extends UnitTestCase
32 {
33  public function ‪setUp()
34  {
35  $this->backupEnvironment = true;
36  parent::setUp();
38  $this->prophesize(ApplicationContext::class)->reveal(),
39  true,
40  false,
41  '',
42  '',
43  '',
44  '',
45  '',
46  ''
47  );
48  }
53  {
54  $input = [
55  'command' => 'new',
56  'foo' => 'bar',
57  ];
58  $siteConfigurationProphecy = $this->prophesize(SiteConfiguration::class);
59  $this->assertSame($input, (new ‪SiteDatabaseEditRow($siteConfigurationProphecy->reveal()))->addData($input));
60  }
61 
66  {
67  $input = [
68  'command' => 'edit',
69  'databaseRow' => [
70  'foo' => 'bar',
71  ]
72  ];
73  $siteConfigurationProphecy = $this->prophesize(SiteConfiguration::class);
74  $this->assertSame($input, (new ‪SiteDatabaseEditRow($siteConfigurationProphecy->reveal()))->addData($input));
75  }
76 
81  {
82  $input = [
83  'command' => 'edit',
84  'tableName' => 'foo',
85  ];
86  $this->expectException(\RuntimeException::class);
87  $this->expectExceptionCode(1520886234);
88  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
89  $siteConfigurationProphecy = $this->prophesize(SiteConfiguration::class);
90  GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
91  (new ‪SiteDatabaseEditRow($siteConfigurationProphecy->reveal()))->addData($input);
92  }
93 
97  public function ‪addDataSetsDataForSysSite()
98  {
99  $input = [
100  'command' => 'edit',
101  'tableName' => 'site',
102  'vanillaUid' => 23,
103  'customData' => [
104  'siteIdentifier' => 'main',
105  ]
106  ];
107  $rowData = [
108  'foo' => 'bar',
109  'rootPageId' => 42,
110  'someArray' => [
111  'foo' => 'bar',
112  ]
113  ];
114  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
115  GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
116  $siteProphecy = $this->prophesize(Site::class);
117  $siteFinderProphecy->getSiteByRootPageId(23)->willReturn($siteProphecy->reveal());
118  $siteProphecy->getIdentifier()->willReturn('testident');
119  $siteConfiguration = $this->prophesize(SiteConfiguration::class);
120  $siteConfiguration->load('testident')->willReturn($rowData);
121 
122  $expected = $input;
123  $expected['databaseRow'] = [
124  'uid' => 42,
125  'identifier' => 'main',
126  'rootPageId' => 42,
127  'pid' => 0,
128  'foo' => 'bar',
129  ];
130 
131  $this->assertEquals($expected, (new ‪SiteDatabaseEditRow($siteConfiguration->reveal()))->addData($input));
132  }
133 
138  {
139  $input = [
140  'command' => 'edit',
141  'tableName' => 'site_errorhandling',
142  'vanillaUid' => 23,
143  'inlineTopMostParentUid' => 5,
144  'inlineParentFieldName' => 'invalid',
145  ];
146  $rowData = [
147  'foo' => 'bar',
148  ];
149  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
150  GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
151  $siteProphecy = $this->prophesize(Site::class);
152  $siteFinderProphecy->getSiteByRootPageId(5)->willReturn($siteProphecy->reveal());
153  $siteProphecy->getIdentifier()->willReturn('testident');
154  $siteConfiguration = $this->prophesize(SiteConfiguration::class);
155  $siteConfiguration->load('testident')->willReturn($rowData);
156 
157  $this->expectException(\RuntimeException::class);
158  $this->expectExceptionCode(1520886092);
159  (new ‪SiteDatabaseEditRow($siteConfiguration->reveal()))->addData($input);
160  }
161 
166  {
167  $input = [
168  'command' => 'edit',
169  'tableName' => 'site_language',
170  'vanillaUid' => 23,
171  'inlineTopMostParentUid' => 5,
172  'inlineParentFieldName' => 'invalid',
173  ];
174  $rowData = [
175  'foo' => 'bar',
176  ];
177  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
178  GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
179  $siteProphecy = $this->prophesize(Site::class);
180  $siteFinderProphecy->getSiteByRootPageId(5)->willReturn($siteProphecy->reveal());
181  $siteProphecy->getIdentifier()->willReturn('testident');
182  $siteConfiguration = $this->prophesize(SiteConfiguration::class);
183  $siteConfiguration->load('testident')->willReturn($rowData);
184 
185  $this->expectException(\RuntimeException::class);
186  $this->expectExceptionCode(1520886092);
187  (new ‪SiteDatabaseEditRow($siteConfiguration->reveal()))->addData($input);
188  }
189 
193  public function ‪addDataAddLanguageRow()
194  {
195  $input = [
196  'command' => 'edit',
197  'tableName' => 'site_language',
198  'vanillaUid' => 23,
199  'inlineTopMostParentUid' => 5,
200  'inlineParentFieldName' => 'languages',
201  ];
202  $rowData = [
203  'languages' => [
204  23 => [
205  'foo' => 'bar',
206  ],
207  ],
208  ];
209  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
210  GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
211  $siteProphecy = $this->prophesize(Site::class);
212  $siteFinderProphecy->getSiteByRootPageId(5)->willReturn($siteProphecy->reveal());
213  $siteProphecy->getIdentifier()->willReturn('testident');
214  $siteConfiguration = $this->prophesize(SiteConfiguration::class);
215  $siteConfiguration->load('testident')->willReturn($rowData);
216 
217  $expected = $input;
218  $expected['databaseRow'] = [
219  'foo' => 'bar',
220  'uid' => 23,
221  'pid' => 0,
222  ];
223 
224  $this->assertEquals($expected, (new ‪SiteDatabaseEditRow($siteConfiguration->reveal()))->addData($input));
225  }
226 }
‪TYPO3\CMS\Core\Core\ApplicationContext
Definition: ApplicationContext.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest\addDataDoesNotChangeResultIfCommandIsNotEdit
‪addDataDoesNotChangeResultIfCommandIsNotEdit()
Definition: SiteDatabaseEditRowTest.php:52
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Core\Configuration\SiteConfiguration
Definition: SiteConfiguration.php:38
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:39
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest
Definition: SiteDatabaseEditRowTest.php:32
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest\addDataThrowsExceptionWithInvalidLanguage
‪addDataThrowsExceptionWithInvalidLanguage()
Definition: SiteDatabaseEditRowTest.php:165
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest\setUp
‪setUp()
Definition: SiteDatabaseEditRowTest.php:33
‪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:77
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest\addDataAddLanguageRow
‪addDataAddLanguageRow()
Definition: SiteDatabaseEditRowTest.php:193
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest\addDataDoesNotChangeResultIfDatabaseRowIsNotEmpty
‪addDataDoesNotChangeResultIfDatabaseRowIsNotEmpty()
Definition: SiteDatabaseEditRowTest.php:65
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest\addDataSetsDataForSysSite
‪addDataSetsDataForSysSite()
Definition: SiteDatabaseEditRowTest.php:97
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest\addDataThrowsExceptionIfTableNameIsNotExpected
‪addDataThrowsExceptionIfTableNameIsNotExpected()
Definition: SiteDatabaseEditRowTest.php:80
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\SiteDatabaseEditRowTest\addDataThrowsExceptionWithInvalidErrorHandling
‪addDataThrowsExceptionWithInvalidErrorHandling()
Definition: SiteDatabaseEditRowTest.php:137
‪TYPO3\CMS\Backend\Form\FormDataProvider\SiteDatabaseEditRow
Definition: SiteDatabaseEditRow.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:3