‪TYPO3CMS  10.4
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;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
29 class ‪TranslationConfigurationProviderTest extends UnitTestCase
30 {
34  protected ‪$subject;
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  $pageId = 1;
54  $site = new ‪Site('dummy', $pageId, ['base' => 'http://sub.domainhostname.tld/path/']);
55  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
56  $siteFinderProphecy->getSiteByPageId($pageId)->willReturn($site);
57  GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
58  $languages = $this->subject->getSystemLanguages($pageId);
59  self::assertArrayHasKey(0, $languages);
60  }
61 
66  {
67  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
68  $siteFinderProphecy->getAllSites()->willReturn($this->‪getDummySites());
69  GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
70  $languages = $this->subject->getSystemLanguages(0);
71  self::assertCount(3, $languages);
72  }
73 
78  {
79  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
80  $siteFinderProphecy->getAllSites()->willReturn($this->‪getDummySites());
81  GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
82  $languages = $this->subject->getSystemLanguages(0);
83  self::assertEquals('Deutsch [Site: dummy1], German [Site: dummy2]', $languages[1]['title']);
84  }
85 
86  protected function ‪getDummySites(): array
87  {
88  return [
89  new ‪Site(
90  'dummy1',
91  1,
92  [
93  'base' => 'https://domain.tld/',
94  'languages' => [
95  [
96  'languageId' => 0,
97  'locale' => 'en_US.UTF-8',
98  'title' => 'English',
99  ],
100  [
101  'languageId' => 1,
102  'locale' => 'de_DE.UTF-8',
103  'title' => 'Deutsch'
104  ]
105  ]
106  ]
107  ),
108  new ‪Site(
109  'dummy2',
110  2,
111  [
112  'base' => 'https://domain.tld/',
113  'languages' => [
114  [
115  'languageId' => 0,
116  'locale' => 'en_US.UTF-8',
117  'title' => 'English'
118  ],
119  [
120  'languageId' => 1,
121  'locale' => 'de_DE.UTF-8',
122  'title' => 'German'
123  ],
124  [
125  'languageId' => 2,
126  'locale' => 'da_DK.UTF-8',
127  'title' => 'Danish'
128  ],
129  ]
130  ]
131  )
132  ];
133  }
134 }
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\TranslationConfigurationProviderTest\getDummySites
‪getDummySites()
Definition: TranslationConfigurationProviderTest.php:85
‪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:40
‪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:30
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\TranslationConfigurationProviderTest\getSystemLanguagesConcatenatesTitlesOfLanguagesForRootLevel
‪getSystemLanguagesConcatenatesTitlesOfLanguagesForRootLevel()
Definition: TranslationConfigurationProviderTest.php:76
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\TranslationConfigurationProviderTest\setUp
‪setUp()
Definition: TranslationConfigurationProviderTest.php:35
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
Definition: TranslationConfigurationProvider.php:35
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\TranslationConfigurationProviderTest\getSystemLanguagesAggregatesLanguagesOfAllSitesForRootLevel
‪getSystemLanguagesAggregatesLanguagesOfAllSitesForRootLevel()
Definition: TranslationConfigurationProviderTest.php:64