[FEATURE] Show only sys_languages in Backend which are available
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / DatabaseSystemLanguageRowsTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Prophecy\Argument;
18 use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseSystemLanguageRows;
19 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
20 use TYPO3\CMS\Core\Localization\LanguageService;
21 use TYPO3\CMS\Core\Site\Entity\Site;
22 use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
23 use TYPO3\CMS\Core\Site\SiteFinder;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26
27 /**
28 * Test case
29 */
30 class DatabaseSystemLanguageRowsTest extends UnitTestCase
31 {
32 /**
33 * @test
34 */
35 public function addDataSetsDefaultLanguageAndAllEntries()
36 {
37 $languageService = $this->prophesize(LanguageService::class);
38 $GLOBALS['LANG'] = $languageService->reveal();
39 $languageService->sL(Argument::cetera())->willReturnArgument(0);
40 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
41 $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
42
43 $siteFinderProphecy = $this->prophesize(SiteFinder::class);
44 GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
45 $siteProphecy = $this->prophesize(Site::class);
46 $siteFinderProphecy->getSiteByPageId(42)->willReturn($siteProphecy->reveal());
47 $siteLanguageMinusOne = $this->prophesize(SiteLanguage::class);
48 $siteLanguageMinusOne->getLanguageId()->willReturn(-1);
49 $siteLanguageMinusOne->getTitle()->willReturn('All');
50 $siteLanguageMinusOne->getFlagIdentifier()->willReturn('flags-multiple');
51 $siteLanguageZero = $this->prophesize(SiteLanguage::class);
52 $siteLanguageZero->getLanguageId()->willReturn(0);
53 $siteLanguageZero->getTitle()->willReturn('English');
54 $siteLanguageZero->getFlagIdentifier()->willReturn('empty-empty');
55 $siteLanguageOne = $this->prophesize(SiteLanguage::class);
56 $siteLanguageOne->getLanguageId()->willReturn(1);
57 $siteLanguageOne->getTitle()->willReturn('Dutch');
58 $siteLanguageOne->getFlagIdentifier()->willReturn('flag-nl');
59 $siteLanguageOne->getTwoLetterIsoCode()->willReturn('NL');
60 $siteLanguages = [
61 $siteLanguageMinusOne->reveal(),
62 $siteLanguageZero->reveal(),
63 $siteLanguageOne->reveal(),
64 ];
65 $siteProphecy->getAvailableLanguages(Argument::cetera())->willReturn($siteLanguages);
66 $input = [
67 'pageTsConfig' => [],
68 'effectivePid' => 42,
69 ];
70 $expected = [
71 'systemLanguageRows' => [
72 -1 => [
73 'uid' => -1,
74 'title' => 'All',
75 'iso' => 'DEF',
76 'flagIconIdentifier' => 'flags-multiple',
77 ],
78 0 => [
79 'uid' => 0,
80 'title' => 'English',
81 'iso' => 'DEF',
82 'flagIconIdentifier' => 'empty-empty',
83 ],
84 1 => [
85 'uid' => 1,
86 'title' => 'Dutch',
87 'iso' => 'NL',
88 'flagIconIdentifier' => 'flag-nl',
89 ]
90 ],
91 ];
92 $this->assertSame(array_merge($input, $expected), (new DatabaseSystemLanguageRows())->addData($input));
93 }
94 }