[BUGFIX] Ensure "0" is treated as proper fallback in site language
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Site / Entity / SiteLanguageTest.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Core\Tests\Unit\Site\Entity;
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
19 use TYPO3\CMS\Core\Http\Uri;
20 use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22
23 class SiteLanguageTest extends UnitTestCase
24 {
25 public function languageFallbackIdConversionDataProvider()
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
60 /**
61 * @dataProvider languageFallbackIdConversionDataProvider
62 * @test
63 * @param string|array|null $input
64 * @param array $expected
65 */
66 public function languageFallbackIdConversion($input, array $expected)
67 {
68 $configuration = [
69 'fallbacks' => $input
70 ];
71 $subject = new SiteLanguage(1, 'fr', new Uri('/'), $configuration);
72 $this->assertSame($expected, $subject->getFallbackLanguageIds());
73 }
74
75 /**
76 * @test
77 */
78 public function toArrayReturnsProperOverlaidData()
79 {
80 $configuration = [
81 'navigationTitle' => 'NavTitle',
82 'customValue' => 'a custom value',
83 'fallbacks' => '1,2',
84 ];
85 $subject = new SiteLanguage(1, 'de', new Uri('/'), $configuration);
86 $expected = [
87 'navigationTitle' => 'NavTitle',
88 'customValue' => 'a custom value',
89 'fallbacks' => '1,2',
90 'languageId' => 1,
91 'locale' => 'de',
92 'base' => '/',
93 'title' => 'Default',
94 'twoLetterIsoCode' => 'en',
95 'hreflang' => 'en-US',
96 'direction' => '',
97 'typo3Language' => 'default',
98 'flagIdentifier' => '',
99 'fallbackType' => 'strict',
100 'enabled' => true,
101 'fallbackLanguageIds' => [
102 1,
103 2
104 ],
105 ];
106 $this->assertSame($expected, $subject->toArray());
107 }
108 }