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