2 declare(strict_types = 1);
19 use Symfony\Component\Yaml\Yaml;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
54 protected function setUp(): void
58 $this->fixturePath = $basePath .
'/fixture/config/sites';
59 if (!file_exists($this->fixturePath)) {
60 GeneralUtility::mkdir_deep($this->fixturePath);
62 $this->filesToDelete[] = $basePath;
63 $cacheManager = $this->prophesize(CacheManager::class);
64 $cacheManager->getCache(
'cache_core')->willReturn($this->prophesize(FrontendInterface::class)->reveal());
65 GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManager->reveal());
75 $this->assertEmpty($this->siteConfiguration->resolveAllExistingSites());
85 'base' =>
'https://example.com',
87 $yamlFileContents = Yaml::dump($configuration, 99, 2);
88 GeneralUtility::mkdir($this->fixturePath .
'/home');
89 GeneralUtility::writeFile($this->fixturePath .
'/home/config.yaml', $yamlFileContents);
90 $sites = $this->siteConfiguration->resolveAllExistingSites();
91 $this->assertCount(1, $sites);
92 $currentSite = current($sites);
93 $this->assertSame(42, $currentSite->getRootPageId());
94 $this->assertEquals(
new Uri(
'https://example.com'), $currentSite->getBase());
102 $identifier =
'testsite';
103 GeneralUtility::mkdir_deep($this->fixturePath .
'/' . $identifier);
104 $configFixture = __DIR__ .
'/Fixtures/SiteConfigs/config1.yaml';
105 $expected = __DIR__ .
'/Fixtures/SiteConfigs/config1_expected.yaml';
106 $siteConfig = $this->fixturePath .
'/' . $identifier .
'/config.yaml';
107 copy($configFixture, $siteConfig);
110 $configuration = GeneralUtility::makeInstance(YamlFileLoader::class)
112 GeneralUtility::fixWindowsFilePath($siteConfig),
116 $configuration[
'base'] =
'https://example.net/';
118 $configuration[
'languages'][0][
'title'] =
'English';
120 unset($configuration[
'someOtherValue'], $configuration[
'languages'][1]);
122 $this->siteConfiguration->write($identifier, $configuration);
125 self::assertFileEquals($expected, $siteConfig);
131 foreach ($this->filesToDelete as $absoluteFileName) {
133 if (!GeneralUtility::validPathStr($absoluteFileName)) {
134 throw new \RuntimeException(
'tearDown() cleanup: Filename contains illegal characters', 1410633087);
137 throw new \RuntimeException(
143 if (@is_link($absoluteFileName) || @is_file($absoluteFileName)) {
144 unlink($absoluteFileName);
145 } elseif (@is_dir($absoluteFileName)) {
146 GeneralUtility::rmdir($absoluteFileName,
true);
148 throw new \RuntimeException(
'tearDown() cleanup: File, link or directory does not exist', 1410633510);
151 $this->filesToDelete = [];
160 $identifier =
'testsite';
161 GeneralUtility::mkdir_deep($this->fixturePath .
'/' . $identifier);
162 $configFixture = __DIR__ .
'/Fixtures/SiteConfigs/config2.yaml';
163 $expected = __DIR__ .
'/Fixtures/SiteConfigs/config2_expected.yaml';
164 $siteConfig = $this->fixturePath .
'/' . $identifier .
'/config.yaml';
165 copy($configFixture, $siteConfig);
168 $configuration = GeneralUtility::makeInstance(YamlFileLoader::class)
170 GeneralUtility::fixWindowsFilePath($siteConfig),
175 'title' =>
'English',
179 'typo3Language' =>
'default',
180 'locale' =>
'en_US.utf8',
185 'navigationTitle' =>
'English',
187 array_unshift($configuration[
'languages'], $languageConfig);
188 $this->siteConfiguration->write($identifier, $configuration);
191 self::assertFileEquals($expected, $siteConfig);