‪TYPO3CMS  ‪main
SiteConfigurationControllerTest.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;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 final class ‪SiteConfigurationControllerTest extends UnitTestCase
26 {
27  #[Test]
28  public function ‪duplicateEntryPointsAreRecognized(): void
29  {
30  $mockedSiteConfigurationController = $this->getAccessibleMock(SiteConfigurationController::class, null, [], '', false);
31 
32  $sites = [
33  new ‪Site('site-1', 1, [
34  'base' => '//domain1.tld',
35  'languages' => [
36  [
37  'languageId' => 0,
38  'base' => '/',
39  'locale' => 'de_DE.UTF-8',
40  ],
41  [
42  'languageId' => 1,
43  'base' => '/fr/',
44  'locale' => 'fr_FR.UTF-8',
45  ],
46  ],
47  ]),
48  new ‪Site('site-2', 1, [
49  'base' => '//domain2.tld',
50  'languages' => [
51  [
52  'languageId' => 0,
53  'base' => '/',
54  'locale' => 'de_DE.UTF-8',
55  ],
56  [
57  'languageId' => 1,
58  'base' => 'https://domain1.tld/',
59  'locale' => 'fr_FR.UTF-8',
60  ],
61  [
62  'languageId' => 2,
63  'base' => 'https://domain2.tld/en',
64  'locale' => 'fr_FR.UTF-8',
65  ],
66  ],
67  ]),
68  new ‪Site('site-3', 3, [
69  'base' => '/',
70  'languages' => [
71  [
72  'languageId' => 0,
73  'base' => 'http://domain1.tld/de',
74  'locale' => 'de_DE.UTF-8',
75  ],
76  [
77  'languageId' => 1,
78  'base' => 'https://domain3.tld',
79  'locale' => 'fr_FR.UTF-8',
80  ],
81  ],
82  ]),
83  new ‪Site('site-4', 4, [
84  'base' => '',
85  'languages' => [
86  [
87  'languageId' => 0,
88  'base' => 'http://domain1.tld/de/',
89  'locale' => 'de_DE.UTF-8',
90  ],
91  [
92  'languageId' => 1,
93  'base' => 'http://domain1.tld/',
94  'locale' => 'fr_FR.UTF-8',
95  ],
96  ],
97  ]),
98  new ‪Site('site-5', 5, [
99  'base' => '//domain2.tld/en/',
100  'languages' => [
101  [
102  'languageId' => 0,
103  'base' => '/',
104  'locale' => 'de_DE.UTF-8',
105  ],
106  ],
107  ]),
108  ];
109  $rootPages = array_flip([1, 2, 3, 4, 5]);
110 
111  $expected = [
112  'domain1.tld' => [
113  '//domain1.tld' => 1,
114  'https://domain1.tld' => 1,
115  'http://domain1.tld' => 1,
116  ],
117  'domain2.tld/en' => [
118  'https://domain2.tld/en' => 1,
119  '//domain2.tld/en' => 1,
120  ],
121  'domain1.tld/de' => [
122  'http://domain1.tld/de' => 2,
123  ],
124  ];
125 
126  self::assertEquals($expected, $mockedSiteConfigurationController->_call('getDuplicatedEntryPoints', $sites, $rootPages));
127  }
128 
129  #[Test]
130  public function ‪languageBaseVariantsAreKept(): void
131  {
132  $mockedSiteConfigurationController = $this->getAccessibleMock(SiteConfigurationController::class, null, [], '', false);
133 
134  $currentSiteConfig = [
135  'base' => '//domain1.tld/',
136  'websiteTitle' => 'domain1',
137  'languages' => [
138  0 => [
139  'languageId' => 0,
140  'title' => 'English',
141  'base' => '/',
142  'baseVariants' => [
143  [
144  'base' => '/en',
145  ],
146  ],
147  ],
148  ],
149  ];
150 
151  $newSiteConfig = $currentSiteConfig;
152  $newSiteConfig['rootPageId'] = 123;
153  $newSiteConfig['websiteTitle'] = 'domain1 renamed';
154  unset($newSiteConfig['languages'][0]['baseVariants']);
155 
156  $expected = [
157  'base' => '//domain1.tld/',
158  'rootPageId' => 123,
159  'websiteTitle' => 'domain1 renamed',
160  'languages' => [
161  0 => [
162  'languageId' => 0,
163  'title' => 'English',
164  'base' => '/',
165  'baseVariants' => [
166  [
167  'base' => '/en',
168  ],
169  ],
170  ],
171  ],
172  ];
173 
174  self::assertEquals(
175  $expected,
176  $mockedSiteConfigurationController->_call('getMergeSiteData', $currentSiteConfig, $newSiteConfig)
177  );
178  }
179 }
‪TYPO3\CMS\Backend\Tests\Unit\Controller\SiteConfigurationControllerTest\languageBaseVariantsAreKept
‪languageBaseVariantsAreKept()
Definition: SiteConfigurationControllerTest.php:130
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:42
‪TYPO3\CMS\Backend\Controller\SiteConfigurationController
Definition: SiteConfigurationController.php:67
‪TYPO3\CMS\Backend\Tests\Unit\Controller
‪TYPO3\CMS\Backend\Tests\Unit\Controller\SiteConfigurationControllerTest
Definition: SiteConfigurationControllerTest.php:26
‪TYPO3\CMS\Backend\Tests\Unit\Controller\SiteConfigurationControllerTest\duplicateEntryPointsAreRecognized
‪duplicateEntryPointsAreRecognized()
Definition: SiteConfigurationControllerTest.php:28