‪TYPO3CMS  9.5
XmlSitemapRecordsTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
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 
20 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
21 
26 {
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->setUpFrontendRootPage(
42  1,
43  [
44  'constants' => ['EXT:seo/Configuration/TypoScript/XmlSitemap/constants.typoscript'],
45  'setup' => [
46  'EXT:seo/Configuration/TypoScript/XmlSitemap/setup.typoscript',
47  'EXT:seo/Tests/Functional/Fixtures/records.typoscript',
48  ],
49  ]
50  );
51 
53  'website-local',
54  $this->‪buildSiteConfiguration(1, 'http://localhost/'),
55  [
56  $this->‪buildDefaultLanguageConfiguration('EN', '/'),
57  $this->‪buildLanguageConfiguration('FR', '/fr'),
58  ]
59  );
60  }
61 
69  public function ‪checkIfSiteMapIndexContainsSysCategoryLinks(string $host, array $expectedEntries, array $notExpectedEntries): void
70  {
71  $response = $this->executeFrontendRequest(
72  (new InternalRequest($host))->withQueryParameters(
73  [
74  'type' => 1533906435,
75  'sitemap' => 'records',
76  ]
77  )
78  );
79 
80  $this->assertEquals(200, $response->getStatusCode());
81  $this->assertArrayHasKey('Content-Length', $response->getHeaders());
82  $this->assertEquals('application/xml;charset=utf-8', $response->getHeader('Content-Type')[0]);
83  $this->assertArrayHasKey('X-Robots-Tag', $response->getHeaders());
84  $this->assertEquals('noindex', $response->getHeader('X-Robots-Tag')[0]);
85  $this->assertArrayHasKey('Content-Length', $response->getHeaders());
86  $stream = $response->getBody();
87  $stream->rewind();
88  $content = $stream->getContents();
89 
90  foreach ($expectedEntries as $expectedEntry) {
91  self::assertContains($expectedEntry, $content);
92  }
93 
94  foreach ($notExpectedEntries as $notExpectedEntry) {
95  self::assertNotContains($notExpectedEntry, $content);
96  }
97 
98  $this->assertGreaterThan(0, $response->getHeader('Content-Length')[0]);
99  }
100 
104  public function ‪sitemapEntriesToCheck(): array
105  {
106  return [
107  'default-language' => [
108  'http://localhost/',
109  [
110  'http://localhost/?tx_example_category%5Bid%5D=1&amp;',
111  'http://localhost/?tx_example_category%5Bid%5D=2&amp;',
112  ],
113  [
114  'http://localhost/?tx_example_category%5Bid%5D=3&amp;',
115  'http://localhost/fr/?tx_example_category%5Bid%5D=3&amp;',
116  ]
117  ],
118  'french-language' => [
119  'http://localhost/fr',
120  [
121  'http://localhost/fr/?tx_example_category%5Bid%5D=3&amp;',
122  ],
123  [
124  'http://localhost/fr/?tx_example_category%5Bid%5D=1&amp;',
125  'http://localhost/fr/?tx_example_category%5Bid%5D=2&amp;',
126  'http://localhost/?tx_example_category%5Bid%5D=1&amp;',
127  'http://localhost/?tx_example_category%5Bid%5D=2&amp;',
128  ]
129  ],
130  ];
131  }
132 
140  public function ‪checkSiteMapWithDifferentTypoScriptConfigs(string $sitemap, array $expectedEntries, array $notExpectedEntries): void
141  {
142  $response = $this->executeFrontendRequest(
143  (new InternalRequest('http://localhost/'))->withQueryParameters(
144  [
145  'id' => 1,
146  'type' => 1533906435,
147  'sitemap' => $sitemap,
148  ]
149  )
150  );
151 
152  $this->assertEquals(200, $response->getStatusCode());
153  $this->assertArrayHasKey('Content-Length', $response->getHeaders());
154  $stream = $response->getBody();
155  $stream->rewind();
156  $content = $stream->getContents();
157 
158  foreach ($expectedEntries as $expectedEntry) {
159  self::assertStringContainsString($expectedEntry, $content);
160  }
161 
162  foreach ($notExpectedEntries as $notExpectedEntry) {
163  self::assertStringNotContainsString($notExpectedEntry, $content);
164  }
165 
166  $this->assertGreaterThan(0, $response->getHeader('Content-Length')[0]);
167  }
168 
173  {
174  return [
175  [
176  'records_with_additional_where',
177  [
178  'http://localhost/?tx_example_category%5Bid%5D=1&amp;',
179  ],
180  [
181  'http://localhost/?tx_example_category%5Bid%5D=2&amp;',
182  'http://localhost/?tx_example_category%5Bid%5D=3&amp;'
183  ]
184  ],
185  [
186  'records_with_additional_where_starting_with_logical_operator',
187  [
188  'http://localhost/?tx_example_category%5Bid%5D=2&amp;',
189  ],
190  [
191  'http://localhost/?tx_example_category%5Bid%5D=1&amp;',
192  'http://localhost/?tx_example_category%5Bid%5D=3&amp;'
193  ]
194  ],
195  ];
196  }
197 }
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildLanguageConfiguration
‪array buildLanguageConfiguration(string $identifier, string $base, array $fallbackIdentifiers=[], string $fallbackType=null)
Definition: SiteBasedTestTrait.php:140
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:56
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapRecordsTest\checkIfSiteMapIndexContainsSysCategoryLinks
‪checkIfSiteMapIndexContainsSysCategoryLinks(string $host, array $expectedEntries, array $notExpectedEntries)
Definition: XmlSitemapRecordsTest.php:68
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase
Definition: AbstractTestCase.php:29
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap
Definition: AbstractXmlSitemapPagesTest.php:4
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapRecordsTest\$coreExtensionsToLoad
‪string[] $coreExtensionsToLoad
Definition: XmlSitemapRecordsTest.php:29
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪array buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:122
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapRecordsTest\additionalWhereTypoScriptConfigurationsToCheck
‪array[] additionalWhereTypoScriptConfigurationsToCheck()
Definition: XmlSitemapRecordsTest.php:171
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪array buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:107
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapRecordsTest
Definition: XmlSitemapRecordsTest.php:26
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapRecordsTest\setUp
‪setUp()
Definition: XmlSitemapRecordsTest.php:35
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapRecordsTest\checkSiteMapWithDifferentTypoScriptConfigs
‪checkSiteMapWithDifferentTypoScriptConfigs(string $sitemap, array $expectedEntries, array $notExpectedEntries)
Definition: XmlSitemapRecordsTest.php:139
‪TYPO3\CMS\Seo\Tests\Functional\XmlSitemap\XmlSitemapRecordsTest\sitemapEntriesToCheck
‪array[] sitemapEntriesToCheck()
Definition: XmlSitemapRecordsTest.php:103