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