‪TYPO3CMS  11.5
TcaSystemLanguageCollectorTest.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 
20 use Prophecy\Argument;
21 use Prophecy\PhpUnit\ProphecyTrait;
31 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
32 
33 class ‪TcaSystemLanguageCollectorTest extends UnitTestCase
34 {
35  use ProphecyTrait;
36 
40  protected ‪$resetSingletonInstances = true;
41 
42  public function ‪setUp(): void
43  {
44  parent::setUp();
45  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
46  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
47  $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
48  $cacheManagerProphecy->getCache('runtime')->willReturn($cacheFrontendProphecy->reveal());
49 
50  ‪$GLOBALS['BE_USER'] = new ‪BackendUserAuthentication();
51  ‪$GLOBALS['BE_USER']->groupData = ['allowed_languages' => ''];
52 
53  $languageServiceProphecy = $this->prophesize(LanguageService::class);
54  ‪$GLOBALS['LANG'] = $languageServiceProphecy->reveal();
55  }
56 
60  public function ‪populateAvailableSiteLanguagesTest(): void
61  {
62  $siteFinder = $this->prophesize(SiteFinder::class);
63  $siteFinder->getAllSites()->willReturn([
64  new ‪Site('site-1', 1, [
65  'base' => '/',
66  'languages' => [
67  [
68  'title' => 'English',
69  'languageId' => 0,
70  'base' => '/',
71  'locale' => 'en_US',
72  'flag' => 'us',
73  ],
74  [
75  'title' => 'German',
76  'languageId' => 2,
77  'base' => '/de/',
78  'locale' => 'de_DE',
79  'flag' => 'de',
80  ],
81  ],
82  ]),
83  new ‪Site('site-2', 2, [
84  'base' => '/',
85  'languages' => [
86  [
87  'title' => 'English',
88  'languageId' => 0,
89  'base' => '/',
90  'locale' => 'en_US',
91  'flag' => 'us',
92  ],
93  ],
94  ]),
95  ]);
96  GeneralUtility::addInstance(SiteFinder::class, $siteFinder->reveal());
97 
98  $expectedItems = [
99  0 => [
100  0 => 'English [Site: site-1], English [Site: site-2]',
101  1 => 0,
102  2 => 'flags-us',
103  ],
104  1 => [
105  0 => 'German [Site: site-1]',
106  1 => 2,
107  2 => 'flags-de',
108  ],
109  ];
110 
111  $fieldInformation = ['items' => []];
112 
113  (new ‪TcaSystemLanguageCollector(new ‪Locales()))->populateAvailableSiteLanguages($fieldInformation);
114 
115  self::assertSame($expectedItems, $fieldInformation['items']);
116  }
117 
122  {
123  $languageService = $this->prophesize(LanguageService::class);
124  $languageService->sL(Argument::cetera())->willReturn('');
125  ‪$GLOBALS['LANG'] = $languageService->reveal();
126 
127  $siteFinder = $this->prophesize(SiteFinder::class);
128  $siteFinder->getAllSites()->willReturn([]);
129  GeneralUtility::addInstance(SiteFinder::class, $siteFinder->reveal());
130 
131  $expectedItems = [
132  0 => [
133  0 => 'Default',
134  1 => 0,
135  2 => '',
136  ],
137  ];
138 
139  $fieldInformation = ['items' => []];
140 
141  (new TcaSystemLanguageCollector(new Locales()))->populateAvailableSiteLanguages($fieldInformation);
142 
143  self::assertSame($expectedItems, $fieldInformation['items']);
144  }
145 }
‪TYPO3\CMS\Core\Tests\Unit\Localization\TcaSystemLanguageCollectorTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: TcaSystemLanguageCollectorTest.php:38
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Core\Localization\Locales
Definition: Locales.php:30
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:42
‪TYPO3\CMS\Core\Tests\Unit\Localization\TcaSystemLanguageCollectorTest\setUp
‪setUp()
Definition: TcaSystemLanguageCollectorTest.php:40
‪TYPO3\CMS\Core\Localization\TcaSystemLanguageCollector
Definition: TcaSystemLanguageCollector.php:31
‪TYPO3\CMS\Core\Tests\Unit\Localization\TcaSystemLanguageCollectorTest
Definition: TcaSystemLanguageCollectorTest.php:34
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Unit\Localization
Definition: LocalesTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Localization\TcaSystemLanguageCollectorTest\populateAvailableSiteLanguagesWithoutSiteTest
‪populateAvailableSiteLanguagesWithoutSiteTest()
Definition: TcaSystemLanguageCollectorTest.php:119
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Tests\Unit\Localization\TcaSystemLanguageCollectorTest\populateAvailableSiteLanguagesTest
‪populateAvailableSiteLanguagesTest()
Definition: TcaSystemLanguageCollectorTest.php:58