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