‪TYPO3CMS  9.5
SiteLanguageTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
22 class ‪SiteLanguageTest extends UnitTestCase
23 {
25  {
26  return [
27  'no fallback set' => [
28  null,
29  []
30  ],
31  'fallback given as empty string returns no fallback' => [
32  '',
33  []
34  ],
35  'fallback to default language as string returns proper fallback' => [
36  '0',
37  [0]
38  ],
39  'fallback to multiple languages as string returns proper fallback' => [
40  '3,0',
41  [3, 0]
42  ],
43  'fallback to default language as array returns proper fallback' => [
44  ['0'],
45  [0]
46  ],
47  'fallback to multiple languages as array returns proper fallback' => [
48  ['3', '0'],
49  [3, 0]
50  ],
51  'fallback to multiple languages as array with integers returns proper fallback' => [
52  [3, 0],
53  [3, 0]
54  ],
55 
56  ];
57  }
58 
65  public function ‪languageFallbackIdConversion($input, array $expected)
66  {
67  $configuration = [
68  'fallbacks' => $input,
69  'locale' => 'fr',
70  ];
71  $site = $this->‪createSiteWithLanguage($configuration);
72  $subject = $site->getLanguageById(1);
73  $this->assertSame($expected, $subject->getFallbackLanguageIds());
74  }
75 
80  {
81  $configuration = [
82  'navigationTitle' => 'NavTitle',
83  'customValue' => 'a custom value',
84  'fallbacks' => '1,2',
85  'locale' => 'de',
86  ];
87  $site = $this->‪createSiteWithLanguage($configuration);
88  $subject = $site->getLanguageById(1);
89  $expected = [
90  'navigationTitle' => 'NavTitle',
91  'customValue' => 'a custom value',
92  'fallbacks' => '1,2',
93  'locale' => 'de',
94  'languageId' => 1,
95  'base' => '/',
96  'title' => 'Default',
97  'twoLetterIsoCode' => 'en',
98  'hreflang' => 'en-US',
99  'direction' => '',
100  'typo3Language' => 'default',
101  'flagIdentifier' => '',
102  'fallbackType' => 'strict',
103  'enabled' => true,
104  'fallbackLanguageIds' => [
105  1,
106  2
107  ],
108  ];
109  $this->assertSame($expected, $subject->toArray());
110  }
111 
112  private function ‪createSiteWithLanguage(array $languageConfiguration): ‪Site
113  {
114  return new ‪Site('test', 1, [
115  'identifier' => 'test',
116  'rootPageId' => 1,
117  'base' => '/',
118  'languages' => [
119  array_merge(
120  $languageConfiguration,
121  [
122  'languageId' => 1,
123  'base' => '/',
124  ]
125  )
126  ]
127  ]);
128  }
129 }
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity
Definition: PseudoSiteTest.php:4
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:39
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteLanguageTest\toArrayReturnsProperOverlaidData
‪toArrayReturnsProperOverlaidData()
Definition: SiteLanguageTest.php:79
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteLanguageTest\createSiteWithLanguage
‪createSiteWithLanguage(array $languageConfiguration)
Definition: SiteLanguageTest.php:112
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteLanguageTest\languageFallbackIdConversionDataProvider
‪languageFallbackIdConversionDataProvider()
Definition: SiteLanguageTest.php:24
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteLanguageTest\languageFallbackIdConversion
‪languageFallbackIdConversion($input, array $expected)
Definition: SiteLanguageTest.php:65
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteLanguageTest
Definition: SiteLanguageTest.php:23