[TASK] Add resolved site object to FormEngine
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / DatabaseSystemLanguageRowsTest.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 Prophecy\Argument;
19 use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseSystemLanguageRows;
20 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
21 use TYPO3\CMS\Core\Localization\LanguageService;
22 use TYPO3\CMS\Core\Site\Entity\Site;
23 use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25
26 /**
27 * Test case
28 */
29 class DatabaseSystemLanguageRowsTest extends UnitTestCase
30 {
31 /**
32 * @test
33 */
34 public function addDataThrowsExceptionIfSiteObjectIsNotSet()
35 {
36 $this->expectException(\LogicException::class);
37 $this->expectExceptionCode(1534952559);
38 (new DatabaseSystemLanguageRows())->addData([]);
39 }
40
41 /**
42 * @test
43 */
44 public function addDataSetsDefaultLanguageAndAllEntries()
45 {
46 $languageService = $this->prophesize(LanguageService::class);
47 $GLOBALS['LANG'] = $languageService->reveal();
48 $languageService->sL(Argument::cetera())->willReturnArgument(0);
49 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
50 $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
51
52 $siteProphecy = $this->prophesize(Site::class);
53 $siteLanguageMinusOne = $this->prophesize(SiteLanguage::class);
54 $siteLanguageMinusOne->getLanguageId()->willReturn(-1);
55 $siteLanguageMinusOne->getTitle()->willReturn('All');
56 $siteLanguageMinusOne->getFlagIdentifier()->willReturn('flags-multiple');
57 $siteLanguageZero = $this->prophesize(SiteLanguage::class);
58 $siteLanguageZero->getLanguageId()->willReturn(0);
59 $siteLanguageZero->getTitle()->willReturn('English');
60 $siteLanguageZero->getFlagIdentifier()->willReturn('empty-empty');
61 $siteLanguageOne = $this->prophesize(SiteLanguage::class);
62 $siteLanguageOne->getLanguageId()->willReturn(1);
63 $siteLanguageOne->getTitle()->willReturn('Dutch');
64 $siteLanguageOne->getFlagIdentifier()->willReturn('flag-nl');
65 $siteLanguageOne->getTwoLetterIsoCode()->willReturn('NL');
66 $siteLanguages = [
67 $siteLanguageMinusOne->reveal(),
68 $siteLanguageZero->reveal(),
69 $siteLanguageOne->reveal(),
70 ];
71 $siteProphecy->getAvailableLanguages(Argument::cetera())->willReturn($siteLanguages);
72 $input = [
73 'effectivePid' => 42,
74 'site' => $siteProphecy->reveal(),
75 ];
76 $expected = [
77 'systemLanguageRows' => [
78 -1 => [
79 'uid' => -1,
80 'title' => 'All',
81 'iso' => 'DEF',
82 'flagIconIdentifier' => 'flags-multiple',
83 ],
84 0 => [
85 'uid' => 0,
86 'title' => 'English',
87 'iso' => 'DEF',
88 'flagIconIdentifier' => 'empty-empty',
89 ],
90 1 => [
91 'uid' => 1,
92 'title' => 'Dutch',
93 'iso' => 'NL',
94 'flagIconIdentifier' => 'flag-nl',
95 ]
96 ],
97 ];
98 $this->assertSame(array_merge($input, $expected), (new DatabaseSystemLanguageRows())->addData($input));
99 }
100 }