‪TYPO3CMS  10.4
PluginsTest.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 
21 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
22 
27 {
28  protected function ‪setUp(): void
29  {
30  $this->testExtensionsToLoad[] = 'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_meta';
31 
32  parent::setUp();
33  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/Scenarios/pages_with_plugins_seo_meta.xml');
34 
36  'website-local',
37  $this->‪buildSiteConfiguration(1, 'http://localhost/'),
38  [
39  $this->‪buildDefaultLanguageConfiguration('EN', '/')
40  ]
41  );
42  }
43 
44  public function ‪ensurePageSetupIsOkDataProvider(): array
45  {
46  return [
47  'page:uid:1' => [1, false],
48  'page:uid:2' => [2, true],
49  'page:uid:3' => [3, true],
50  'page:uid:4' => [4, true],
51  'page:uid:5' => [5, true],
52  ];
53  }
54 
61  public function ‪ensurePageSetupIsOk(int $pageId, bool $expectPluginOutput): void
62  {
63  $this->setUpFrontendRootPage(1, ['typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_meta/Configuration/TypoScript/page' . $pageId . '.typoscript']);
64  $response = $this->executeFrontendRequest(
65  (new InternalRequest('http://localhost/'))->withQueryParameters([
66  'id' => $pageId,
67  ])
68  );
69  $body = (string)$response->getBody();
70  self::assertStringContainsString('<h1>MetaData-Test</h1>', $body);
71  if ($expectPluginOutput) {
72  self::assertStringContainsString('TYPO3\CMS\TestMeta\Controller::setMetaData', $body);
73  } else {
74  self::assertStringNotContainsString('TYPO3\CMS\TestMeta\Controller::setMetaData', $body);
75  }
76  }
77 
78  public function ‪ensureMetaDataAreCorrectDataProvider(): array
79  {
80  return [
81  'page:uid:1' => [1, 'Rootpage for Tests', ''],
82  'page:uid:2' => [2, 'static title with pageId: 2 and pluginNumber: 20', 'OG title from a controller with pageId: 2 and pluginNumber: 20'],
83  'page:uid:3' => [3, 'static title with pageId: 3 and pluginNumber: 20', 'OG title from a controller with pageId: 3 and pluginNumber: 20'],
84  'page:uid:4' => [4, 'static title with pageId: 4 and pluginNumber: 20', 'OG title from a controller with pageId: 4 and pluginNumber: 20'],
85  'page:uid:5' => [5, 'static title with pageId: 5 and pluginNumber: 10', 'OG title from a controller with pageId: 5 and pluginNumber: 10'],
86  'page:uid:6' => [6, 'static title with pageId: 6 and pluginNumber: 10', 'OG title from a controller with pageId: 6 and pluginNumber: 20'],
87  ];
88  }
89 
100  public function ‪ensureMetaDataAreCorrect(int $pageId, string $expectedTitle, string $expectedMetaOgTitle): void
101  {
102  $this->setUpFrontendRootPage(1, ['typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_meta/Configuration/TypoScript/page' . $pageId . '.typoscript']);
103 
104  // First hit to create a cached version
105  $uncachedResponse = $this->executeFrontendRequest(
106  (new InternalRequest('http://localhost/'))->withQueryParameters([
107  'id' => $pageId,
108  ])
109  );
110  $body = (string)$uncachedResponse->getBody();
111  self::assertStringContainsString('<title>' . $expectedTitle . '</title>', $body);
112  if ($expectedMetaOgTitle !== '') {
113  self::assertStringContainsString('<meta name="og:title" content="' . $expectedMetaOgTitle . '" />', $body, 'first hit, not cached');
114  }
115 
116  // Second hit to check the cached version
117  $cachedResponse = $this->executeFrontendRequest(
118  (new InternalRequest('http://localhost/'))->withQueryParameters([
119  'id' => $pageId,
120  ])
121  );
122  $body = (string)$cachedResponse->getBody();
123  self::assertStringContainsString('<title>' . $expectedTitle . '</title>', $body);
124  if ($expectedMetaOgTitle !== '') {
125  self::assertStringContainsString('<meta name="og:title" content="' . $expectedMetaOgTitle . '" />', $body, 'second hit, cached');
126  }
127  }
128 }
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling\PluginsTest\setUp
‪setUp()
Definition: PluginsTest.php:28
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:58
‪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:124
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling\PluginsTest\ensurePageSetupIsOk
‪ensurePageSetupIsOk(int $pageId, bool $expectPluginOutput)
Definition: PluginsTest.php:61
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling\PluginsTest\ensureMetaDataAreCorrectDataProvider
‪ensureMetaDataAreCorrectDataProvider()
Definition: PluginsTest.php:78
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling\PluginsTest
Definition: PluginsTest.php:27
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling
Definition: PluginsTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling\PluginsTest\ensurePageSetupIsOkDataProvider
‪ensurePageSetupIsOkDataProvider()
Definition: PluginsTest.php:44
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪array buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:109
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling\PluginsTest\ensureMetaDataAreCorrect
‪ensureMetaDataAreCorrect(int $pageId, string $expectedTitle, string $expectedMetaOgTitle)
Definition: PluginsTest.php:100