‪TYPO3CMS  11.5
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 
24 {
29  'FE' => [
30  'cacheHash' => [
31  'enforceValidation' => false,
32  ],
33  ],
34  ];
35 
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 
59  {
60  self::assertStringNotContainsString(
61  '<loc>http://localhost/canonicalized-page</loc>',
62  (string)$this->‪getResponse()->getBody()
63  );
64  }
65 
70  {
71  self::assertStringNotContainsString(
72  '<loc>http://localhost/no-index</loc>',
73  (string)$this->‪getResponse()->getBody()
74  );
75  }
76 
83  {
84  self::assertStringNotContainsString(
85  '<loc>http://localhost/hidden-in-default</loc>',
86  (string)$this->‪getResponse()->getBody()
87  );
88  }
89 
96  {
97  self::assertStringNotContainsString(
98  '<loc>http://localhost/de/dummy-1-2-5-fr</loc>',
99  (string)$this->‪getResponse('http://localhost/de/')->getBody()
100  );
101  }
102 
106  public function ‪pagesToCheckDataProvider(): array //18-03-2019 21:24:07
107  {
108  return [
109  '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>#'],
110  '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>#'],
111  '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>#'],
112  ];
113  }
114 
118  public function ‪pagesSitemapContainsTranslatedPages(): void
119  {
120  self::assertEquals(
121  4,
122  (new \SimpleXMLElement((string)$this->‪getResponse('http://localhost/fr/')->getBody()))->count()
123  );
124  }
125 
129  public function ‪pagesSitemapDoesNotContainUntranslatedPages(): void
130  {
131  self::assertStringNotContainsString(
132  '<loc>http://localhost/dummy-1-4</loc>',
133  (string)$this->‪getResponse('http://localhost/fr/')->getBody()
134  );
135  }
136 
140  public function ‪pagesSitemapRespectFallbackStrategy(): void
141  {
142  self::assertStringContainsString(
143  '<loc>http://localhost/de/dummy-1-3-fr</loc>',
144  (string)$this->‪getResponse('http://localhost/de/')->getBody()
145  );
146  }
147 
152  {
153  $this->setUpFrontendRootPage(
154  1,
155  [
156  'constants' => [
157  'EXT:seo/Configuration/TypoScript/XmlSitemap/constants.typoscript',
158  'EXT:seo/Tests/Functional/Fixtures/excludePagesRecursive.typoscript',
159  ],
160  'setup' => ['EXT:seo/Configuration/TypoScript/XmlSitemap/setup.typoscript'],
161  ]
162  );
163 
164  $xml = (string)$this->‪getResponse()->getBody();
165  self::assertStringNotContainsString(
166  '<loc>http://localhost/dummy-1-2</loc>',
167  $xml
168  );
169  self::assertStringNotContainsString(
170  '<loc>http://localhost/dummy-1-2-5</loc>',
171  $xml
172  );
173  self::assertStringNotContainsString(
174  '<loc>http://localhost/dummy-1-2-6</loc>',
175  $xml
176  );
177 
178  self::assertStringContainsString(
179  '<loc>http://localhost/</loc>',
180  $xml
181  );
182 
183  self::assertStringContainsString(
184  '<loc>http://localhost/dummy-1-3</loc>',
185  $xml
186  );
187  }
188 }
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesSitemapRespectFallbackStrategy
‪pagesSitemapRespectFallbackStrategy()
Definition: XmlSitemapPagesTest.php:139
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap
Definition: AbstractXmlSitemapPagesTest.php:18
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest
Definition: XmlSitemapPagesTest.php:24
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesSitemapInAlternativeLanguageDoesNotContainSiteThatIsHiddenIfNotTranslated
‪pagesSitemapInAlternativeLanguageDoesNotContainSiteThatIsHiddenIfNotTranslated()
Definition: XmlSitemapPagesTest.php:94
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesSitemapDoesNotContainUrlWithCanonicalSet
‪pagesSitemapDoesNotContainUrlWithCanonicalSet()
Definition: XmlSitemapPagesTest.php:57
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesSitemapDoesNotContainUrlWithNoIndexSet
‪pagesSitemapDoesNotContainUrlWithNoIndexSet()
Definition: XmlSitemapPagesTest.php:68
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\getResponse
‪array< string, $configurationToUseInTestInstance=array('FE'=>['cacheHash'=>['enforceValidation'=> false,],],);public checkIfPagesSiteMapContainsExpectedEntries( $urlPattern):void { $response=$this-> getResponse()
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesToCheckDataProvider
‪array pagesToCheckDataProvider()
Definition: XmlSitemapPagesTest.php:105
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesSitemapDoesNotContainUrlsOfExcludedPages
‪pagesSitemapDoesNotContainUrlsOfExcludedPages()
Definition: XmlSitemapPagesTest.php:150
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesSitemapInDefaultLanguageDoesNotContainSiteThatIsHiddenInDefaultLanguage
‪pagesSitemapInDefaultLanguageDoesNotContainSiteThatIsHiddenInDefaultLanguage()
Definition: XmlSitemapPagesTest.php:81
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase\$configurationToUseInTestInstance
‪$configurationToUseInTestInstance
Definition: AbstractTestCase.php:40
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\AbstractXmlSitemapPagesTest
Definition: AbstractXmlSitemapPagesTest.php:25
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesSitemapDoesNotContainUntranslatedPages
‪pagesSitemapDoesNotContainUntranslatedPages()
Definition: XmlSitemapPagesTest.php:128
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapPagesTest\pagesSitemapContainsTranslatedPages
‪pagesSitemapContainsTranslatedPages()
Definition: XmlSitemapPagesTest.php:117