‪TYPO3CMS  ‪main
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 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
24 
29 {
30  protected array ‪$testExtensionsToLoad = [
31  'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_meta',
32  ];
33 
34  protected function ‪setUp(): void
35  {
36  parent::setUp();
37  $this->importCSVDataSet(__DIR__ . '/../Fixtures/Scenarios/pages_with_plugins_seo_meta.csv');
38 
40  'website-local',
41  $this->‪buildSiteConfiguration(1, 'http://localhost/'),
42  [
43  $this->‪buildDefaultLanguageConfiguration('EN', '/'),
44  ]
45  );
46  }
47 
48  public static function ‪ensurePageSetupIsOkDataProvider(): array
49  {
50  return [
51  'page:uid:1' => [1, false],
52  'page:uid:2' => [2, true],
53  'page:uid:3' => [3, true],
54  'page:uid:4' => [4, true],
55  'page:uid:5' => [5, true],
56  ];
57  }
58 
59  #[DataProvider('ensurePageSetupIsOkDataProvider')]
60  #[Test]
61  public function ‪ensurePageSetupIsOk(int $pageId, bool $expectPluginOutput): void
62  {
63  $this->setUpFrontendRootPage(1, ['EXT:core/Tests/Functional/Fixtures/Extensions/test_meta/Configuration/TypoScript/page' . $pageId . '.typoscript']);
64  $response = $this->executeFrontendSubRequest(
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('TYPO3Tests\TestMeta\Controller::setMetaData', $body);
73  } else {
74  self::assertStringNotContainsString('TYPO3Tests\TestMeta\Controller::setMetaData', $body);
75  }
76  }
77 
78  public static 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 
94  #[DataProvider('ensureMetaDataAreCorrectDataProvider')]
95  #[Test]
96  public function ‪ensureMetaDataAreCorrect(int $pageId, string $expectedTitle, string $expectedMetaOgTitle): void
97  {
98  $this->setUpFrontendRootPage(1, ['EXT:core/Tests/Functional/Fixtures/Extensions/test_meta/Configuration/TypoScript/page' . $pageId . '.typoscript']);
99 
100  // First hit to create a cached version
101  $uncachedResponse = $this->executeFrontendSubRequest(
102  (new InternalRequest('http://localhost/'))->withQueryParameters([
103  'id' => $pageId,
104  ])
105  );
106  $body = (string)$uncachedResponse->getBody();
107  self::assertStringContainsString('<title>' . $expectedTitle . '</title>', $body);
108  if ($expectedMetaOgTitle !== '') {
109  self::assertStringContainsString('<meta name="og:title" content="' . $expectedMetaOgTitle . '" />', $body, 'first hit, not cached');
110  }
111 
112  // Second hit to check the cached version
113  $cachedResponse = $this->executeFrontendSubRequest(
114  (new InternalRequest('http://localhost/'))->withQueryParameters([
115  'id' => $pageId,
116  ])
117  );
118  $body = (string)$cachedResponse->getBody();
119  self::assertStringContainsString('<title>' . $expectedTitle . '</title>', $body);
120  if ($expectedMetaOgTitle !== '') {
121  self::assertStringContainsString('<meta name="og:title" content="' . $expectedMetaOgTitle . '" />', $body, 'second hit, cached');
122  }
123  }
124 }
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling\PluginsTest\setUp
‪setUp()
Definition: PluginsTest.php:34
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:50
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase
Definition: AbstractTestCase.php:29
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:88
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling\PluginsTest\ensurePageSetupIsOkDataProvider
‪static ensurePageSetupIsOkDataProvider()
Definition: PluginsTest.php:48
‪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
‪static ensureMetaDataAreCorrectDataProvider()
Definition: PluginsTest.php:78
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling\PluginsTest
Definition: PluginsTest.php:29
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling
Definition: PluginsTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling\PluginsTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: PluginsTest.php:30
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:98
‪TYPO3\CMS\Core\Tests\Functional\MetaDataHandling\PluginsTest\ensureMetaDataAreCorrect
‪ensureMetaDataAreCorrect(int $pageId, string $expectedTitle, string $expectedMetaOgTitle)
Definition: PluginsTest.php:96