‪TYPO3CMS  ‪main
MultiSiteTest.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;
25 use TYPO3\TestingFramework\Core\Functional\Framework\Constraint\RequestSection\HasRecordConstraint;
26 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\ActionService;
27 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
28 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\ResponseContent;
29 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
30 
34 final class ‪MultiSiteTest extends FunctionalTestCase
35 {
37 
38  private const ‪VALUE_PageIdWebsite = 1;
39  private const ‪VALUE_PageIdSecondSite = 50;
40  private const ‪TABLE_Page = 'pages';
41  private const ‪LANGUAGE_PRESETS = [
42  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
43  ];
44 
45  protected function ‪setUp(): void
46  {
47  parent::setUp();
48  $this->importCSVDataSet(__DIR__ . '/../DataSet/ImportDefault.csv');
49  $this->importCSVDataSet(__DIR__ . '/../../../Fixtures/be_users_admin.csv');
51  'test',
52  $this->‪buildSiteConfiguration(1, 'http://localhost/'),
53  [
54  $this->‪buildDefaultLanguageConfiguration('EN', '/en/'),
55  ],
56  $this->‪buildErrorHandlingConfiguration('Fluid', [404]),
57  );
58  $this->setUpFrontendRootPage(1, ['EXT:core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript']);
59  }
60 
61  #[Test]
62  public function ‪moveRootPageToDifferentPageTree(): void
63  {
64  $backendUser = $this->setUpBackendUser(1);
65  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
66 
67  // Warm up caches for the root line utility to identify side effects
68  GeneralUtility::makeInstance(SiteMatcher::class)->matchByPageId(self::VALUE_PageIdWebsite);
69  GeneralUtility::makeInstance(SiteMatcher::class)->matchByPageId(self::VALUE_PageIdSecondSite);
70 
71  // URL is now "/1" for the second site
72  $actionService = new ActionService();
73  $actionService->moveRecord(self::TABLE_Page, self::VALUE_PageIdSecondSite, self::VALUE_PageIdWebsite);
74  $this->assertCSVDataSet(__DIR__ . '/DataSet/moveRootPageToDifferentPageTree.csv');
75 
76  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(self::VALUE_PageIdSecondSite));
77  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections();
78  self::assertThat($responseSections, (new HasRecordConstraint())
79  ->setTable(self::TABLE_Page)->setField('title')->setValues('Second Root Page'));
80  }
81 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:37
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:50
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:88
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\MultiSite\MultiSiteTest\VALUE_PageIdSecondSite
‪const VALUE_PageIdSecondSite
Definition: MultiSiteTest.php:38
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\MultiSite\MultiSiteTest\setUp
‪setUp()
Definition: MultiSiteTest.php:44
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\MultiSite\MultiSiteTest\VALUE_PageIdWebsite
‪const VALUE_PageIdWebsite
Definition: MultiSiteTest.php:37
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildErrorHandlingConfiguration
‪buildErrorHandlingConfiguration(string $handler, array $codes)
Definition: SiteBasedTestTrait.php:142
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\MultiSite\MultiSiteTest\TABLE_Page
‪const TABLE_Page
Definition: MultiSiteTest.php:39
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\MultiSite
Definition: MultiSiteTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:98
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\MultiSite\MultiSiteTest
Definition: MultiSiteTest.php:35
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\MultiSite\MultiSiteTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: MultiSiteTest.php:40
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\MultiSite\MultiSiteTest\moveRootPageToDifferentPageTree
‪moveRootPageToDifferentPageTree()
Definition: MultiSiteTest.php:61
‪TYPO3\CMS\Core\Routing\SiteMatcher
Definition: SiteMatcher.php:52