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