‪TYPO3CMS  ‪main
XmlSitemapPagesTest.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 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
22 
27 {
29  'FE' => [
30  'cacheHash' => [
31  'enforceValidation' => false,
32  ],
33  ],
34  ];
35 
39  #[DataProvider('pagesToCheckDataProvider')]
40  #[Test]
41  public function ‪checkIfPagesSiteMapContainsExpectedEntries($urlPattern): void
42  {
43  $response = $this->‪getResponse();
44  self::assertEquals(200, $response->getStatusCode());
45  self::assertArrayHasKey('Content-Length', $response->getHeaders());
46  self::assertGreaterThan(0, $response->getHeader('Content-Length')[0]);
47  self::assertArrayHasKey('Content-Type', $response->getHeaders());
48  self::assertEquals('application/xml;charset=utf-8', $response->getHeader('Content-Type')[0]);
49  self::assertArrayHasKey('X-Robots-Tag', $response->getHeaders());
50  self::assertEquals('noindex', $response->getHeader('X-Robots-Tag')[0]);
51 
52  self::assertMatchesRegularExpression($urlPattern, (string)$response->getBody());
53  }
54 
55  #[Test]
57  {
58  self::assertStringNotContainsString(
59  '<loc>http://localhost/canonicalized-page</loc>',
60  (string)$this->‪getResponse()->getBody()
61  );
62  }
63 
64  #[Test]
66  {
67  self::assertStringNotContainsString(
68  '<loc>http://localhost/no-index</loc>',
69  (string)$this->‪getResponse()->getBody()
70  );
71  }
72 
76  #[Test]
78  {
79  self::assertStringNotContainsString(
80  '<loc>http://localhost/hidden-in-default</loc>',
81  (string)$this->‪getResponse()->getBody()
82  );
83  }
84 
88  #[Test]
90  {
91  self::assertStringNotContainsString(
92  '<loc>http://localhost/de/dummy-1-2-5-fr</loc>',
93  (string)$this->‪getResponse('http://localhost/de/')->getBody()
94  );
95  }
96 
97  public static function ‪pagesToCheckDataProvider(): array //18-03-2019 21:24:07
98  {
99  return [
100  'complete-entry' => ['#<url>\s+<loc>http://localhost/complete\-entry</loc>\s+<lastmod>\d+-\d+-\d+T\d+:\d+:\d+\+\d+:\d+</lastmod>\s+<changefreq>daily</changefreq>\s+<priority>0\.7</priority>\s+</url>#'],
101  'only-changefreq' => ['#<url>\s+<loc>http://localhost/only\-changefreq</loc>\s+<lastmod>\d+-\d+-\d+T\d+:\d+:\d+\+\d+:\d+</lastmod>\s+<changefreq>weekly</changefreq>\s+<priority>0\.5</priority>\s+</url>#'],
102  'clean' => ['#<url>\s+<loc>http://localhost/clean</loc>\s+<lastmod>\d+-\d+-\d+T\d+:\d+:\d+\+\d+:\d+</lastmod>\s+<priority>0\.5</priority>\s+</url>#'],
103  ];
104  }
105 
106  #[Test]
108  {
109  self::assertEquals(
110  4,
111  (new \SimpleXMLElement((string)$this->‪getResponse('http://localhost/fr/')->getBody()))->count()
112  );
113  }
114 
115  #[Test]
117  {
118  self::assertStringNotContainsString(
119  '<loc>http://localhost/dummy-1-4</loc>',
120  (string)$this->‪getResponse('http://localhost/fr/')->getBody()
121  );
122  }
123 
124  #[Test]
126  {
127  self::assertStringContainsString(
128  '<loc>http://localhost/de/dummy-1-3-fr</loc>',
129  (string)$this->‪getResponse('http://localhost/de/')->getBody()
130  );
131  }
132 
133  #[Test]
135  {
136  $this->setUpFrontendRootPage(
137  1,
138  [
139  'constants' => [
140  'EXT:seo/Configuration/TypoScript/XmlSitemap/constants.typoscript',
141  'EXT:seo/Tests/Functional/Fixtures/excludePagesRecursive.typoscript',
142  ],
143  'setup' => ['EXT:seo/Configuration/TypoScript/XmlSitemap/setup.typoscript'],
144  ]
145  );
146 
147  $xml = (string)$this->‪getResponse()->getBody();
148  self::assertStringNotContainsString(
149  '<loc>http://localhost/dummy-1-2</loc>',
150  $xml
151  );
152  self::assertStringNotContainsString(
153  '<loc>http://localhost/dummy-1-2-5</loc>',
154  $xml
155  );
156  self::assertStringNotContainsString(
157  '<loc>http://localhost/dummy-1-2-6</loc>',
158  $xml
159  );
160 
161  self::assertStringContainsString(
162  '<loc>http://localhost/</loc>',
163  $xml
164  );
165 
166  self::assertStringContainsString(
167  '<loc>http://localhost/dummy-1-3</loc>',
168  $xml
169  );
170  }
171 }
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\$configurationToUseInTestInstance
‪array $configurationToUseInTestInstance
Definition: XmlSitemapPagesTest.php:28
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesSitemapRespectFallbackStrategy
‪pagesSitemapRespectFallbackStrategy()
Definition: XmlSitemapPagesTest.php:125
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\AbstractXmlSitemapPagesTestCase\getResponse
‪getResponse(string $uri='http://localhost/')
Definition: AbstractXmlSitemapPagesTestCase.php:60
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\AbstractXmlSitemapPagesTestCase
Definition: AbstractXmlSitemapPagesTestCase.php:25
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap
Definition: AbstractXmlSitemapPagesTestCase.php:18
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest
Definition: XmlSitemapPagesTest.php:27
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesSitemapInAlternativeLanguageDoesNotContainSiteThatIsHiddenIfNotTranslated
‪pagesSitemapInAlternativeLanguageDoesNotContainSiteThatIsHiddenIfNotTranslated()
Definition: XmlSitemapPagesTest.php:89
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesSitemapDoesNotContainUrlWithCanonicalSet
‪pagesSitemapDoesNotContainUrlWithCanonicalSet()
Definition: XmlSitemapPagesTest.php:56
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesSitemapDoesNotContainUrlWithNoIndexSet
‪pagesSitemapDoesNotContainUrlWithNoIndexSet()
Definition: XmlSitemapPagesTest.php:65
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesToCheckDataProvider
‪static pagesToCheckDataProvider()
Definition: XmlSitemapPagesTest.php:97
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesSitemapDoesNotContainUrlsOfExcludedPages
‪pagesSitemapDoesNotContainUrlsOfExcludedPages()
Definition: XmlSitemapPagesTest.php:134
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesSitemapInDefaultLanguageDoesNotContainSiteThatIsHiddenInDefaultLanguage
‪pagesSitemapInDefaultLanguageDoesNotContainSiteThatIsHiddenInDefaultLanguage()
Definition: XmlSitemapPagesTest.php:77
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\checkIfPagesSiteMapContainsExpectedEntries
‪checkIfPagesSiteMapContainsExpectedEntries($urlPattern)
Definition: XmlSitemapPagesTest.php:41
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesSitemapDoesNotContainUntranslatedPages
‪pagesSitemapDoesNotContainUntranslatedPages()
Definition: XmlSitemapPagesTest.php:116
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesSitemapContainsTranslatedPages
‪pagesSitemapContainsTranslatedPages()
Definition: XmlSitemapPagesTest.php:107