[FEATURE] Add properties changefreq and priority to XML sitemap entries
[Packages/TYPO3.CMS.git] / typo3 / sysext / seo / Tests / Functional / XmlSitemap / XmlSitemapPagesTest.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 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalResponse;
22
23 /**
24 * Contains functional tests for the XmlSitemap Index
25 */
26 class XmlSitemapPagesTest extends AbstractTestCase
27 {
28 /**
29 * @var string[]
30 */
31 protected $coreExtensionsToLoad = [
32 'core', 'frontend', 'seo'
33 ];
34
35 /**
36 * @var string
37 */
38 protected $body;
39
40 /**
41 * @var InternalResponse
42 */
43 protected $response;
44
45 protected function setUp()
46 {
47 parent::setUp();
48 $this->importDataSet('EXT:seo/Tests/Functional/Fixtures/pages-sitemap.xml');
49 $this->setUpFrontendRootPage(
50 1,
51 [
52 'constants' => ['EXT:seo/Configuration/TypoScript/XmlSitemap/constants.typoscript'],
53 'setup' => ['EXT:seo/Configuration/TypoScript/XmlSitemap/setup.typoscript']
54 ]
55 );
56
57 $this->writeSiteConfiguration(
58 'website-local',
59 $this->buildSiteConfiguration(1, 'http://localhost/'),
60 [
61 $this->buildDefaultLanguageConfiguration('EN', '/')
62 ]
63 );
64
65 $this->response = $this->executeFrontendRequest(
66 (new InternalRequest('http://localhost/'))->withQueryParameters([
67 'id' => 1,
68 'type' => 1533906435,
69 'sitemap' => 'pages'
70 ])
71 );
72 }
73
74 /**
75 * @param string $urlPattern
76 * @test
77 * @dataProvider pagesToCheckDataProvider
78 */
79 public function checkIfPagesSiteMapContainsExpectedEntries($urlPattern): void
80 {
81 $this->assertEquals(200, $this->response->getStatusCode());
82 $this->assertArrayHasKey('Content-Length', $this->response->getHeaders());
83 $this->assertGreaterThan(0, $this->response->getHeader('Content-Length')[0]);
84
85 $this->assertRegExp($urlPattern, (string)$this->response->getBody());
86 }
87
88 /**
89 * @return array
90 */
91 public function pagesToCheckDataProvider(): array //18-03-2019 21:24:07
92 {
93 return [
94 'complete-entry' => ['/<url>\s+<loc>http:\/\/localhost\/complete\-entry<\/loc>\s+<lastmod>2017-04-10T08:00:00\+00:00<\/lastmod>\s+<changefreq>daily<\/changefreq>\s+<priority>0\.7<\/priority>\s+<\/url>/'],
95 'only-changefreq' => ['/<url>\s+<loc>http:\/\/localhost\/only\-changefreq<\/loc>\s+<lastmod>2017-04-10T08:00:00\+00:00<\/lastmod>\s+<changefreq>weekly<\/changefreq>\s+<priority>0\.5<\/priority>\s+<\/url>/'],
96 'clean' => ['/<url>\s+<loc>http:\/\/localhost\/clean<\/loc>\s+<lastmod>2017-04-10T08:00:00\+00:00<\/lastmod>\s+<priority>0\.5<\/priority>\s+<\/url>/'],
97 ];
98 }
99 }