‪TYPO3CMS  ‪main
MetaTagTest.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 function ‪setUp(): void
31  {
32  $this->coreExtensionsToLoad[] = 'seo';
33 
34  parent::setUp();
35  $this->importCSVDataSet(__DIR__ . '/../Fixtures/Scenarios/pages_with_seo_meta.csv');
36 
38  'website-local',
39  $this->‪buildSiteConfiguration(1, 'http://localhost/'),
40  [
41  $this->‪buildDefaultLanguageConfiguration('EN', '/'),
42  ]
43  );
44  }
45 
46  public static function ‪ensureMetaDataAreCorrectDataProvider(): array
47  {
48  return [
49  'page with twitter_card in page properties' => [
50  1,
51  [
52  ['type' => 'name' , 'tag' => 'twitter:card', 'content' => 'summary'],
53  ],
54  ],
55  'page with twitter_card in page properties and in typoscript' => [
56  2,
57  [
58  ['type' => 'name' , 'tag' => 'twitter:card', 'content' => 'summary'],
59  ],
60  ],
61  'page with twitter_card in page properties and in typoscript with replace' => [
62  3,
63  [
64  ['type' => 'name' , 'tag' => 'twitter:card', 'content' => 'summary_large_image'],
65  ],
66  ],
67  ];
68  }
69 
70  #[DataProvider('ensureMetaDataAreCorrectDataProvider')]
71  #[Test]
72  public function ‪ensureMetaDataAreCorrect(int $pageId, array $expectedMetaTags): void
73  {
74  $this->setUpFrontendRootPage(1, ['EXT:seo/Tests/Functional/Fixtures/page' . $pageId . '.typoscript']);
75 
76  // First hit to create a cached version
77  $uncachedResponse = $this->executeFrontendSubRequest(
78  (new InternalRequest('http://localhost/'))->withQueryParameters([
79  'id' => $pageId,
80  ])
81  );
82  $body = (string)$uncachedResponse->getBody();
83 
84  foreach ($expectedMetaTags as $expectedMetaTag) {
85  self::assertStringContainsString('<meta ' . $expectedMetaTag['type'] . '="' . $expectedMetaTag['tag'] . '" content="' . $expectedMetaTag['content'] . '" />', $body);
86  }
87  }
88 }
‪TYPO3\CMS\Seo\Tests\Functional\MetaTag\MetaTagTest\setUp
‪setUp()
Definition: MetaTagTest.php:30
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:50
‪TYPO3\CMS\Seo\Tests\Functional\MetaTag
Definition: MetaTagGeneratorTest.php:18
‪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\Seo\Tests\Functional\MetaTag\MetaTagTest\ensureMetaDataAreCorrect
‪ensureMetaDataAreCorrect(int $pageId, array $expectedMetaTags)
Definition: MetaTagTest.php:72
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:98
‪TYPO3\CMS\Seo\Tests\Functional\MetaTag\MetaTagTest\ensureMetaDataAreCorrectDataProvider
‪static ensureMetaDataAreCorrectDataProvider()
Definition: MetaTagTest.php:46
‪TYPO3\CMS\Seo\Tests\Functional\MetaTag\MetaTagTest
Definition: MetaTagTest.php:29