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