[TASK] Add resolved site object to FormEngine
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / SiteResolvingTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
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
18 use TYPO3\CMS\Backend\Form\FormDataProvider\SiteResolving;
19 use TYPO3\CMS\Core\Site\Entity\Site;
20 use TYPO3\CMS\Core\Site\SiteFinder;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23
24 /**
25 * Test case
26 */
27 class SiteResolvingTest extends UnitTestCase
28 {
29 /**
30 * @test
31 */
32 public function addDataAddsSiteObjectOfDefaultLanguageRow()
33 {
34 $siteFinderProphecy = $this->prophesize(SiteFinder::class);
35 GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
36 $siteProphecy = $this->prophesize(Site::class);
37 $siteProphecyRevelation = $siteProphecy->reveal();
38 $siteFinderProphecy->getSiteByPageId(23)->willReturn($siteProphecyRevelation);
39 $input = [
40 'defaultLanguagePageRow' => [
41 'uid' => 23,
42 ],
43 'effectivePid' => 42,
44 'site' => $siteProphecyRevelation,
45 ];
46 $expected = $input;
47 $expected['site'] = $siteProphecy->reveal();
48 $this->assertSame($expected, (new SiteResolving())->addData($input));
49 }
50
51 /**
52 * @test
53 */
54 public function addDataAddsSiteObjectOfEffectivePid()
55 {
56 $siteFinderProphecy = $this->prophesize(SiteFinder::class);
57 GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
58 $siteProphecy = $this->prophesize(Site::class);
59 $siteProphecyRevelation = $siteProphecy->reveal();
60 $siteFinderProphecy->getSiteByPageId(42)->willReturn($siteProphecyRevelation);
61 $input = [
62 'effectivePid' => 42,
63 'site' => $siteProphecyRevelation,
64 ];
65 $expected = $input;
66 $expected['site'] = $siteProphecy->reveal();
67 $this->assertSame($expected, (new SiteResolving())->addData($input));
68 }
69 }