[BUGFIX] Only show records from current language in XML Sitemap
[Packages/TYPO3.CMS.git] / typo3 / sysext / seo / Tests / Functional / XmlSitemap / XmlSitemapRecordsTest.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Seo\Tests\Functional\XmlSitemap;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase;
20 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
21
22 /**
23 * Contains functional tests for the XmlSitemap Index
24 */
25 class XmlSitemapRecordsTest extends AbstractTestCase
26 {
27 /**
28 * @var string[]
29 */
30 protected $coreExtensionsToLoad = [
31 'core',
32 'frontend',
33 'seo'
34 ];
35
36 protected function setUp()
37 {
38 parent::setUp();
39 $this->importDataSet('EXT:seo/Tests/Functional/Fixtures/pages-sitemap.xml');
40 $this->importDataSet('EXT:seo/Tests/Functional/Fixtures/sys_category.xml');
41 $this->importDataSet('EXT:seo/Tests/Functional/Fixtures/tt_content.xml');
42 $this->setUpFrontendRootPage(
43 1,
44 [
45 'constants' => ['EXT:seo/Configuration/TypoScript/XmlSitemap/constants.typoscript'],
46 'setup' => [
47 'EXT:seo/Configuration/TypoScript/XmlSitemap/setup.typoscript',
48 'EXT:seo/Tests/Functional/Fixtures/records.typoscript',
49 'EXT:seo/Tests/Functional/Fixtures/content.typoscript'
50 ],
51 ]
52 );
53
54 $this->writeSiteConfiguration(
55 'website-local',
56 $this->buildSiteConfiguration(1, 'http://localhost/'),
57 [
58 $this->buildDefaultLanguageConfiguration('EN', '/'),
59 $this->buildLanguageConfiguration('FR', '/fr'),
60 ]
61 );
62 }
63
64 /**
65 * @test
66 * @dataProvider sitemapEntriesToCheck
67 */
68 public function checkIfSiteMapIndexContainsSysCategoryLinks($host, $expectedEntries, $notExpectedEntries): void
69 {
70 $response = $this->executeFrontendRequest(
71 (new InternalRequest($host))->withQueryParameters(
72 [
73 'type' => 1533906435,
74 'sitemap' => 'records',
75 ]
76 )
77 );
78
79 $this->assertEquals(200, $response->getStatusCode());
80 $this->assertArrayHasKey('Content-Length', $response->getHeaders());
81 $stream = $response->getBody();
82 $stream->rewind();
83 $content = $stream->getContents();
84
85 foreach ($expectedEntries as $expectedEntry) {
86 self::assertContains($expectedEntry, $content);
87 }
88
89 foreach ($notExpectedEntries as $notExpectedEntry) {
90 self::assertNotContains($notExpectedEntry, $content);
91 }
92
93 $this->assertGreaterThan(0, $response->getHeader('Content-Length')[0]);
94 }
95
96 /**
97 * @return array
98 */
99 public function sitemapEntriesToCheck(): array
100 {
101 return [
102 'default-language' => [
103 'http://localhost/',
104 [
105 'http://localhost/?tx_example_category%5Bid%5D=1&amp;',
106 'http://localhost/?tx_example_category%5Bid%5D=2&amp;',
107 '<priority>0.5</priority>'
108 ],
109 [
110 'http://localhost/?tx_example_category%5Bid%5D=3&amp;',
111 'http://localhost/fr/?tx_example_category%5Bid%5D=3&amp;',
112 ]
113 ],
114 'french-language' => [
115 'http://localhost/fr',
116 [
117 'http://localhost/fr/?tx_example_category%5Bid%5D=3&amp;',
118 '<priority>0.5</priority>'
119 ],
120 [
121 'http://localhost/fr/?tx_example_category%5Bid%5D=1&amp;',
122 'http://localhost/fr/?tx_example_category%5Bid%5D=2&amp;',
123 'http://localhost/?tx_example_category%5Bid%5D=1&amp;',
124 'http://localhost/?tx_example_category%5Bid%5D=2&amp;',
125 ]
126 ],
127 ];
128 }
129
130 /**
131 * @test
132 */
133 public function checkIfSiteMapIndexContainsCustomChangeFreqAndPriorityValues(): void
134 {
135 $response = $this->executeFrontendRequest(
136 (new InternalRequest('http://localhost/'))->withQueryParameters(
137 [
138 'id' => 1,
139 'type' => 1533906435,
140 'sitemap' => 'content',
141 ]
142 )
143 );
144
145 $this->assertEquals(200, $response->getStatusCode());
146 $this->assertArrayHasKey('Content-Length', $response->getHeaders());
147 $stream = $response->getBody();
148 $stream->rewind();
149 $content = $stream->getContents();
150
151 self::assertContains('<changefreq>hourly</changefreq>', $content);
152 self::assertContains('<priority>0.7</priority>', $content);
153
154 $this->assertGreaterThan(0, $response->getHeader('Content-Length')[0]);
155 }
156 }