[BUGFIX] Remove caches for page title and meta tag
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / MetaDataHandling / PluginsTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\Functional\MetaDataHandling;
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
18 use TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase;
19 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
20
21 /**
22 * Functional test for the DataHandler
23 */
24 class PluginsTest extends AbstractTestCase
25 {
26 protected function setUp(): void
27 {
28 $this->testExtensionsToLoad[] = 'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_meta';
29
30 parent::setUp();
31 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/Scenarios/pages_with_plugins_seo_meta.xml');
32
33 $this->writeSiteConfiguration(
34 'website-local',
35 $this->buildSiteConfiguration(1, 'http://localhost/'),
36 [
37 $this->buildDefaultLanguageConfiguration('EN', '/')
38 ]
39 );
40 }
41
42 public function ensurePageSetupIsOkDataProvider(): array
43 {
44 return [
45 'page:uid:1' => [1, false],
46 'page:uid:2' => [2, true],
47 'page:uid:3' => [3, true],
48 'page:uid:4' => [4, true],
49 'page:uid:5' => [5, true],
50 ];
51 }
52
53 /**
54 * @test
55 * @dataProvider ensurePageSetupIsOkDataProvider
56 * @param int $pageId
57 * @param bool $expectPluginOutput
58 */
59 public function ensurePageSetupIsOk(int $pageId, bool $expectPluginOutput): void
60 {
61 $this->setUpFrontendRootPage(1, ['typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_meta/Configuration/TypoScript/page' . $pageId . '.typoscript']);
62 $response = $this->executeFrontendRequest(
63 (new InternalRequest('http://localhost/'))->withQueryParameters([
64 'id' => $pageId,
65 ])
66 );
67 $body = (string)$response->getBody();
68 $this->assertStringContainsString('<h1>MetaData-Test</h1>', $body);
69 if ($expectPluginOutput) {
70 $this->assertStringContainsString('TYPO3\CMS\TestMeta\Controller::setMetaData', $body);
71 } else {
72 $this->assertStringNotContainsString('TYPO3\CMS\TestMeta\Controller::setMetaData', $body);
73 }
74 }
75
76 public function ensureMetaDataAreCorrectDataProvider(): array
77 {
78 return [
79 'page:uid:1' => [1, 'Rootpage for Tests', ''],
80 'page:uid:2' => [2, 'static title with pageId: 2 and pluginNumber: 20', 'OG title from a controller with pageId: 2 and pluginNumber: 20'],
81 'page:uid:3' => [3, 'static title with pageId: 3 and pluginNumber: 20', 'OG title from a controller with pageId: 3 and pluginNumber: 20'],
82 'page:uid:4' => [4, 'static title with pageId: 4 and pluginNumber: 20', 'OG title from a controller with pageId: 4 and pluginNumber: 20'],
83 'page:uid:5' => [5, 'static title with pageId: 5 and pluginNumber: 10', 'OG title from a controller with pageId: 5 and pluginNumber: 10'],
84 ];
85 }
86
87 /**
88 * This test ensures that the meta data and title of the page are the same
89 * even if the pages is delivered cached or uncached.
90 *
91 * @test
92 * @dataProvider ensureMetaDataAreCorrectDataProvider
93 * @param int $pageId
94 * @param string $expectedTitle
95 * @param string $expectedMetaOgTitle
96 */
97 public function ensureMetaDataAreCorrect(int $pageId, string $expectedTitle, string $expectedMetaOgTitle): void
98 {
99 $this->setUpFrontendRootPage(1, ['typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_meta/Configuration/TypoScript/page' . $pageId . '.typoscript']);
100
101 // First hit to create a cached version
102 $uncachedResponse = $this->executeFrontendRequest(
103 (new InternalRequest('http://localhost/'))->withQueryParameters([
104 'id' => $pageId,
105 ])
106 );
107 $body = (string)$uncachedResponse->getBody();
108 $this->assertStringContainsString('<title>' . $expectedTitle . '</title>', $body);
109 if ($expectedMetaOgTitle !== '') {
110 $this->assertStringContainsString('<meta name="og:title" content="' . $expectedMetaOgTitle . '" />', $body, 'first hit, not cached');
111 }
112
113 // Second hit to check the cached version
114 $cachedResponse = $this->executeFrontendRequest(
115 (new InternalRequest('http://localhost/'))->withQueryParameters([
116 'id' => $pageId,
117 ])
118 );
119 $body = (string)$cachedResponse->getBody();
120 $this->assertStringContainsString('<title>' . $expectedTitle . '</title>', $body);
121 if ($expectedMetaOgTitle !== '') {
122 $this->assertStringContainsString('<meta name="og:title" content="' . $expectedMetaOgTitle . '" />', $body, 'second hit, cached');
123 }
124 }
125 }