‪TYPO3CMS  11.5
TranslationConfigurationProviderTest.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;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
30 class ‪TranslationConfigurationProviderTest extends UnitTestCase
31 {
32  use ProphecyTrait;
33 
35 
36  protected function ‪setUp(): void
37  {
38  parent::setUp();
39 
40  $this->subject = new ‪TranslationConfigurationProvider();
41  $backendUserAuthentication = $this->prophesize(BackendUserAuthentication::class);
42  $backendUserAuthentication->checkLanguageAccess(Argument::any())->willReturn(true);
43  ‪$GLOBALS['BE_USER'] = $backendUserAuthentication->reveal();
44  $languageService = $this->prophesize(LanguageService::class);
45  ‪$GLOBALS['LANG'] = $languageService->reveal();
46  }
47 
51  public function ‪defaultLanguageIsAlwaysReturned(): void
52  {
53  $languageService = $this->prophesize(LanguageService::class);
54  $languageService->sL(Argument::cetera())->willReturn('');
55  ‪$GLOBALS['LANG'] = $languageService->reveal();
56 
57  $pageId = 1;
58  $site = new ‪Site('dummy', $pageId, ['base' => 'http://sub.domainhostname.tld/path/']);
59  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
60  $siteFinderProphecy->getSiteByPageId($pageId)->willReturn($site);
61  GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
62  $languages = $this->subject->getSystemLanguages($pageId);
63  self::assertArrayHasKey(0, $languages);
64  }
65 
70  {
71  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
72  $siteFinderProphecy->getAllSites()->willReturn($this->‪getDummySites());
73  GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
74  $languages = $this->subject->getSystemLanguages(0);
75  self::assertCount(3, $languages);
76  }
77 
82  {
83  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
84  $siteFinderProphecy->getAllSites()->willReturn($this->‪getDummySites());
85  GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
86  $languages = $this->subject->getSystemLanguages(0);
87  self::assertEquals('Deutsch [Site: dummy1], German [Site: dummy2]', $languages[1]['title']);
88  }
89 
93  protected function ‪getDummySites(): array
94  {
95  return [
96  new Site(
97  'dummy1',
98  1,
99  [
100  'base' => 'https://domain.tld/',
101  'languages' => [
102  [
103  'languageId' => 0,
104  'locale' => 'en_US.UTF-8',
105  'title' => 'English',
106  ],
107  [
108  'languageId' => 1,
109  'locale' => 'de_DE.UTF-8',
110  'title' => 'Deutsch',
111  ],
112  ],
113  ]
114  ),
115  new Site(
116  'dummy2',
117  2,
118  [
119  'base' => 'https://domain.tld/',
120  'languages' => [
121  [
122  'languageId' => 0,
123  'locale' => 'en_US.UTF-8',
124  'title' => 'English',
125  ],
126  [
127  'languageId' => 1,
128  'locale' => 'de_DE.UTF-8',
129  'title' => 'German',
130  ],
131  [
132  'languageId' => 2,
133  'locale' => 'da_DK.UTF-8',
134  'title' => 'Danish',
135  ],
136  ],
137  ]
138  ),
139  ];
140  }
141 }
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Backend\Tests\Unit\Configuration
Definition: BackendUserConfigurationTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\TranslationConfigurationProviderTest\$subject
‪TranslationConfigurationProvider $subject
Definition: TranslationConfigurationProviderTest.php:33
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:42
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\TranslationConfigurationProviderTest\defaultLanguageIsAlwaysReturned
‪defaultLanguageIsAlwaysReturned()
Definition: TranslationConfigurationProviderTest.php:50
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\TranslationConfigurationProviderTest
Definition: TranslationConfigurationProviderTest.php:31
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\TranslationConfigurationProviderTest\getSystemLanguagesConcatenatesTitlesOfLanguagesForRootLevel
‪getSystemLanguagesConcatenatesTitlesOfLanguagesForRootLevel()
Definition: TranslationConfigurationProviderTest.php:80
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\TranslationConfigurationProviderTest\setUp
‪setUp()
Definition: TranslationConfigurationProviderTest.php:35
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
Definition: TranslationConfigurationProvider.php:37
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\TranslationConfigurationProviderTest\getDummySites
‪Site[] getDummySites()
Definition: TranslationConfigurationProviderTest.php:92
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\TranslationConfigurationProviderTest\getSystemLanguagesAggregatesLanguagesOfAllSitesForRootLevel
‪getSystemLanguagesAggregatesLanguagesOfAllSitesForRootLevel()
Definition: TranslationConfigurationProviderTest.php:68