‪TYPO3CMS  ‪main
XmlSitemapRecordsTest.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 ‪$coreExtensionsToLoad = ['seo'];
31 
33  'FE' => [
34  'cacheHash' => [
35  'enforceValidation' => false,
36  ],
37  ],
38  ];
39 
40  protected function ‪setUp(): void
41  {
42  parent::setUp();
43  $this->importCSVDataSet(__DIR__ . '/../Fixtures/pages-sitemap.csv');
44  $this->importCSVDataSet(__DIR__ . '/../Fixtures/sys_category.csv');
45  $this->importCSVDataSet(__DIR__ . '/../Fixtures/tt_content.csv');
46  $this->importCSVDataSet(__DIR__ . '/../Fixtures/sys_news.csv');
47  $this->setUpFrontendRootPage(
48  1,
49  [
50  'constants' => ['EXT:seo/Configuration/TypoScript/XmlSitemap/constants.typoscript'],
51  'setup' => [
52  'EXT:seo/Configuration/TypoScript/XmlSitemap/setup.typoscript',
53  'EXT:seo/Tests/Functional/Fixtures/records.typoscript',
54  'EXT:seo/Tests/Functional/Fixtures/content.typoscript',
55  ],
56  ]
57  );
58 
60  'website-local',
61  $this->‪buildSiteConfiguration(1, 'http://localhost/'),
62  [
63  $this->‪buildDefaultLanguageConfiguration('EN', '/'),
64  $this->‪buildLanguageConfiguration('FR', '/fr'),
65  ]
66  );
67  }
68 
69  #[DataProvider('sitemapEntriesToCheck')]
70  #[Test]
71  public function ‪checkIfSiteMapIndexContainsSysCategoryLinks(string $sitemap, string $host, array $expectedEntries, array $notExpectedEntries): void
72  {
73  $response = $this->executeFrontendSubRequest(
74  (new InternalRequest($host))->withQueryParameters(
75  [
76  'type' => 1533906435,
77  'sitemap' => $sitemap,
78  ]
79  )
80  );
81 
82  self::assertEquals(200, $response->getStatusCode());
83  self::assertArrayHasKey('Content-Type', $response->getHeaders());
84  self::assertEquals('application/xml;charset=utf-8', $response->getHeader('Content-Type')[0]);
85  self::assertArrayHasKey('X-Robots-Tag', $response->getHeaders());
86  self::assertEquals('noindex', $response->getHeader('X-Robots-Tag')[0]);
87  self::assertArrayHasKey('Content-Length', $response->getHeaders());
88  $stream = $response->getBody();
89  $stream->rewind();
90  $content = $stream->getContents();
91 
92  foreach ($expectedEntries as $expectedEntry) {
93  self::assertStringContainsString($expectedEntry, $content);
94  }
95 
96  foreach ($notExpectedEntries as $notExpectedEntry) {
97  self::assertStringNotContainsString($notExpectedEntry, $content);
98  }
99 
100  self::assertGreaterThan(0, $response->getHeader('Content-Length')[0]);
101  }
102 
106  public static function ‪sitemapEntriesToCheck(): array
107  {
108  return [
109  'default-language' => [
110  'records',
111  'http://localhost/',
112  [
113  'http://localhost/?tx_example_category%5Bid%5D=1&amp;',
114  'http://localhost/?tx_example_category%5Bid%5D=2&amp;',
115  '<priority>0.5</priority>',
116  ],
117  [
118  'http://localhost/?tx_example_category%5Bid%5D=3&amp;',
119  'http://localhost/fr/?tx_example_category%5Bid%5D=3&amp;',
120  ],
121  ],
122  'french-language' => [
123  'records',
124  'http://localhost/fr',
125  [
126  'http://localhost/fr/?tx_example_category%5Bid%5D=3&amp;',
127  '<priority>0.5</priority>',
128  ],
129  [
130  'http://localhost/fr/?tx_example_category%5Bid%5D=1&amp;',
131  'http://localhost/fr/?tx_example_category%5Bid%5D=2&amp;',
132  'http://localhost/?tx_example_category%5Bid%5D=1&amp;',
133  'http://localhost/?tx_example_category%5Bid%5D=2&amp;',
134  ],
135  ],
136  'only-records-in-live-workspace-should-be-shown-when-not-in-workspace-mode' => [
137  'records',
138  'http://localhost/',
139  [
140  'http://localhost/?tx_example_category%5Bid%5D=1&amp;',
141  'http://localhost/?tx_example_category%5Bid%5D=2&amp;',
142  ],
143  [
144  'http://localhost/?tx_example_category%5Bid%5D=4&amp;',
145  ],
146  ],
147  'non-workspace-tables-should-work-fine' => [
148  'records_without_workspace_settings',
149  'http://localhost/',
150  [
151  'http://localhost/?tx_example_news%5Bid%5D=1&amp;',
152  'http://localhost/?tx_example_news%5Bid%5D=2&amp;',
153  ],
154  [],
155  ],
156  ];
157  }
158 
159  #[Test]
161  {
162  $response = $this->executeFrontendSubRequest(
163  (new InternalRequest('http://localhost/'))->withQueryParameters(
164  [
165  'id' => 1,
166  'type' => 1533906435,
167  'sitemap' => 'content',
168  ]
169  )
170  );
171 
172  self::assertEquals(200, $response->getStatusCode());
173  self::assertArrayHasKey('Content-Length', $response->getHeaders());
174  $stream = $response->getBody();
175  $stream->rewind();
176  $content = $stream->getContents();
177 
178  self::assertStringContainsString('<changefreq>hourly</changefreq>', $content);
179  self::assertStringContainsString('<priority>0.7</priority>', $content);
180 
181  self::assertGreaterThan(0, $response->getHeader('Content-Length')[0]);
182  }
183 
184  #[DataProvider('additionalWhereTypoScriptConfigurationsToCheck')]
185  #[Test]
186  public function ‪checkSiteMapWithDifferentTypoScriptConfigs(string $sitemap, array $expectedEntries, array $notExpectedEntries): void
187  {
188  $response = $this->executeFrontendSubRequest(
189  (new InternalRequest('http://localhost/'))->withQueryParameters(
190  [
191  'id' => 1,
192  'type' => 1533906435,
193  'sitemap' => $sitemap,
194  ]
195  )
196  );
197 
198  self::assertEquals(200, $response->getStatusCode());
199  self::assertArrayHasKey('Content-Length', $response->getHeaders());
200  $stream = $response->getBody();
201  $stream->rewind();
202  $content = $stream->getContents();
203 
204  foreach ($expectedEntries as $expectedEntry) {
205  self::assertStringContainsString($expectedEntry, $content);
206  }
207 
208  foreach ($notExpectedEntries as $notExpectedEntry) {
209  self::assertStringNotContainsString($notExpectedEntry, $content);
210  }
211 
212  self::assertGreaterThan(0, $response->getHeader('Content-Length')[0]);
213  }
214 
219  {
220  return [
221  [
222  'records_with_additional_where',
223  [
224  'http://localhost/?tx_example_category%5Bid%5D=1&amp;',
225  ],
226  [
227  'http://localhost/?tx_example_category%5Bid%5D=2&amp;',
228  'http://localhost/?tx_example_category%5Bid%5D=3&amp;',
229  ],
230  ],
231  [
232  'records_with_additional_where_starting_with_logical_operator',
233  [
234  'http://localhost/?tx_example_category%5Bid%5D=2&amp;',
235  ],
236  [
237  'http://localhost/?tx_example_category%5Bid%5D=1&amp;',
238  'http://localhost/?tx_example_category%5Bid%5D=3&amp;',
239  ],
240  ],
241  ];
242  }
243 }
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapRecordsTest\additionalWhereTypoScriptConfigurationsToCheck
‪static array[] additionalWhereTypoScriptConfigurationsToCheck()
Definition: XmlSitemapRecordsTest.php:218
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildLanguageConfiguration
‪buildLanguageConfiguration(string $identifier, string $base, array $fallbackIdentifiers=[], string $fallbackType=null)
Definition: SiteBasedTestTrait.php:108
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapRecordsTest\checkIfSiteMapIndexContainsSysCategoryLinks
‪checkIfSiteMapIndexContainsSysCategoryLinks(string $sitemap, string $host, array $expectedEntries, array $notExpectedEntries)
Definition: XmlSitemapRecordsTest.php:71
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapRecordsTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: XmlSitemapRecordsTest.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\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\XmlSitemap
Definition: AbstractXmlSitemapPagesTestCase.php:18
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapRecordsTest\$configurationToUseInTestInstance
‪array $configurationToUseInTestInstance
Definition: XmlSitemapRecordsTest.php:32
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapRecordsTest\checkIfSiteMapIndexContainsCustomChangeFreqAndPriorityValues
‪checkIfSiteMapIndexContainsCustomChangeFreqAndPriorityValues()
Definition: XmlSitemapRecordsTest.php:160
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapRecordsTest\sitemapEntriesToCheck
‪static array[] sitemapEntriesToCheck()
Definition: XmlSitemapRecordsTest.php:106
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:98
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapRecordsTest
Definition: XmlSitemapRecordsTest.php:29
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapRecordsTest\setUp
‪setUp()
Definition: XmlSitemapRecordsTest.php:40
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapRecordsTest\checkSiteMapWithDifferentTypoScriptConfigs
‪checkSiteMapWithDifferentTypoScriptConfigs(string $sitemap, array $expectedEntries, array $notExpectedEntries)
Definition: XmlSitemapRecordsTest.php:186