‪TYPO3CMS  10.4
SiteLanguageTest.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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
23 class ‪SiteLanguageTest extends UnitTestCase
24 {
26  {
27  return [
28  'no fallback set' => [
29  null,
30  []
31  ],
32  'fallback given as empty string returns no fallback' => [
33  '',
34  []
35  ],
36  'fallback to default language as string returns proper fallback' => [
37  '0',
38  [0]
39  ],
40  'fallback to multiple languages as string returns proper fallback' => [
41  '3,0',
42  [3, 0]
43  ],
44  'fallback to default language as array returns proper fallback' => [
45  ['0'],
46  [0]
47  ],
48  'fallback to multiple languages as array returns proper fallback' => [
49  ['3', '0'],
50  [3, 0]
51  ],
52  'fallback to multiple languages as array with integers returns proper fallback' => [
53  [3, 0],
54  [3, 0]
55  ],
56 
57  ];
58  }
59 
66  public function ‪languageFallbackIdConversion($input, array $expected)
67  {
68  $configuration = [
69  'fallbacks' => $input,
70  'locale' => 'fr',
71  ];
72  $site = $this->‪createSiteWithLanguage($configuration);
73  $subject = $site->getLanguageById(1);
74  self::assertSame($expected, $subject->getFallbackLanguageIds());
75  }
76 
81  {
82  $configuration = [
83  'navigationTitle' => 'NavTitle',
84  'customValue' => 'a custom value',
85  'fallbacks' => '1,2',
86  'locale' => 'de',
87  ];
88  $site = $this->‪createSiteWithLanguage($configuration);
89  $subject = $site->getLanguageById(1);
90  $expected = [
91  'navigationTitle' => 'NavTitle',
92  'customValue' => 'a custom value',
93  'fallbacks' => '1,2',
94  'locale' => 'de',
95  'languageId' => 1,
96  'base' => '/',
97  'title' => 'Default',
98  'websiteTitle' => '',
99  'twoLetterIsoCode' => 'en',
100  'hreflang' => 'en-US',
101  'direction' => '',
102  'typo3Language' => 'default',
103  'flagIdentifier' => '',
104  'fallbackType' => 'strict',
105  'enabled' => true,
106  'fallbackLanguageIds' => [
107  1,
108  2
109  ],
110  ];
111  self::assertSame($expected, $subject->toArray());
112  }
113 
114  private function ‪createSiteWithLanguage(array $languageConfiguration): ‪Site
115  {
116  return new ‪Site('test', 1, [
117  'identifier' => 'test',
118  'rootPageId' => 1,
119  'base' => '/',
120  'languages' => [
121  array_merge(
122  $languageConfiguration,
123  [
124  'languageId' => 1,
125  'base' => '/',
126  ]
127  )
128  ]
129  ]);
130  }
131 }
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity
Definition: SiteLanguageTest.php:18
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:40
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteLanguageTest\toArrayReturnsProperOverlaidData
‪toArrayReturnsProperOverlaidData()
Definition: SiteLanguageTest.php:80
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteLanguageTest\createSiteWithLanguage
‪createSiteWithLanguage(array $languageConfiguration)
Definition: SiteLanguageTest.php:114
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteLanguageTest\languageFallbackIdConversionDataProvider
‪languageFallbackIdConversionDataProvider()
Definition: SiteLanguageTest.php:25
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteLanguageTest\languageFallbackIdConversion
‪languageFallbackIdConversion($input, array $expected)
Definition: SiteLanguageTest.php:66
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteLanguageTest
Definition: SiteLanguageTest.php:24