1504a09559eecd8f53f005a791e859045771b4f6
[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
55 /**
56 * @test
57 */
58 public function checkIfSiteMapIndexContainsSysCategoryLinks(): void
59 {
60 $this->writeSiteConfiguration(
61 'website-local',
62 $this->buildSiteConfiguration(1, 'http://localhost/'),
63 [
64 $this->buildDefaultLanguageConfiguration('EN', '/'),
65 ]
66 );
67
68 $response = $this->executeFrontendRequest(
69 (new InternalRequest('http://localhost/'))->withQueryParameters(
70 [
71 'id' => 1,
72 'type' => 1533906435,
73 'sitemap' => 'records',
74 ]
75 )
76 );
77
78 $this->assertEquals(200, $response->getStatusCode());
79 $this->assertArrayHasKey('Content-Length', $response->getHeaders());
80 $stream = $response->getBody();
81 $stream->rewind();
82 $content = $stream->getContents();
83 self::assertContains('http://localhost/?tx_example_category%5Bid%5D=1&amp;', $content);
84 self::assertContains('http://localhost/?tx_example_category%5Bid%5D=2&amp;', $content);
85 self::assertContains('<priority>0.5</priority>', $content);
86
87 $this->assertGreaterThan(0, $response->getHeader('Content-Length')[0]);
88 }
89
90 /**
91 * @test
92 */
93 public function checkIfSiteMapIndexContainsCustomChangeFreqAndPriorityValues(): void
94 {
95 $this->writeSiteConfiguration(
96 'website-local',
97 $this->buildSiteConfiguration(1, 'http://localhost/'),
98 [
99 $this->buildDefaultLanguageConfiguration('EN', '/'),
100 ]
101 );
102
103 $response = $this->executeFrontendRequest(
104 (new InternalRequest('http://localhost/'))->withQueryParameters(
105 [
106 'id' => 1,
107 'type' => 1533906435,
108 'sitemap' => 'content',
109 ]
110 )
111 );
112
113 $this->assertEquals(200, $response->getStatusCode());
114 $this->assertArrayHasKey('Content-Length', $response->getHeaders());
115 $stream = $response->getBody();
116 $stream->rewind();
117 $content = $stream->getContents();
118
119 self::assertContains('<changefreq>hourly</changefreq>', $content);
120 self::assertContains('<priority>0.7</priority>', $content);
121
122 $this->assertGreaterThan(0, $response->getHeader('Content-Length')[0]);
123 }
124 }