‪TYPO3CMS  9.5
PluginsTest.php
Go to the documentation of this file.
1 <?php
2 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 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
20 
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 
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 
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  'page:uid:6' => [6, 'static title with pageId: 6 and pluginNumber: 10', 'OG title from a controller with pageId: 6 and pluginNumber: 20'],
85  ];
86  }
87 
98  public function ‪ensureMetaDataAreCorrect(int $pageId, string $expectedTitle, string $expectedMetaOgTitle): void
99  {
100  $this->setUpFrontendRootPage(1, ['typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_meta/Configuration/TypoScript/page' . $pageId . '.typoscript']);
101 
102  // First hit to create a cached version
103  $uncachedResponse = $this->executeFrontendRequest(
104  (new InternalRequest('http://localhost/'))->withQueryParameters([
105  'id' => $pageId,
106  ])
107  );
108  $body = (string)$uncachedResponse->getBody();
109  $this->assertStringContainsString('<title>' . $expectedTitle . '</title>', $body);
110  if ($expectedMetaOgTitle !== '') {
111  $this->assertStringContainsString('<meta name="og:title" content="' . $expectedMetaOgTitle . '" />', $body, 'first hit, not cached');
112  }
113 
114  // Second hit to check the cached version
115  $cachedResponse = $this->executeFrontendRequest(
116  (new InternalRequest('http://localhost/'))->withQueryParameters([
117  'id' => $pageId,
118  ])
119  );
120  $body = (string)$cachedResponse->getBody();
121  $this->assertStringContainsString('<title>' . $expectedTitle . '</title>', $body);
122  if ($expectedMetaOgTitle !== '') {
123  $this->assertStringContainsString('<meta name="og:title" content="' . $expectedMetaOgTitle . '" />', $body, 'second hit, cached');
124  }
125  }
126 }
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling\PluginsTest\setUp
‪setUp()
Definition: PluginsTest.php:26
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:56
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase
Definition: AbstractTestCase.php:29
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪array buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:122
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling\PluginsTest\ensurePageSetupIsOk
‪ensurePageSetupIsOk(int $pageId, bool $expectPluginOutput)
Definition: PluginsTest.php:59
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling\PluginsTest\ensureMetaDataAreCorrectDataProvider
‪ensureMetaDataAreCorrectDataProvider()
Definition: PluginsTest.php:76
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling\PluginsTest
Definition: PluginsTest.php:25
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling
Definition: PluginsTest.php:3
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling\PluginsTest\ensurePageSetupIsOkDataProvider
‪ensurePageSetupIsOkDataProvider()
Definition: PluginsTest.php:42
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪array buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:107
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling\PluginsTest\ensureMetaDataAreCorrect
‪ensureMetaDataAreCorrect(int $pageId, string $expectedTitle, string $expectedMetaOgTitle)
Definition: PluginsTest.php:98