diff --git a/typo3/sysext/core/Classes/Domain/Repository/PageRepository.php b/typo3/sysext/core/Classes/Domain/Repository/PageRepository.php index 7138edd5ad76392c0967c7104a13a94d1e6423b1..d065411a6a8a72a6a591a53eaf3f78e48efc7799 100644 --- a/typo3/sysext/core/Classes/Domain/Repository/PageRepository.php +++ b/typo3/sysext/core/Classes/Domain/Repository/PageRepository.php @@ -440,7 +440,7 @@ class PageRepository implements LoggerAwareInterface * @param array $page the page translation record or the page in the default language * @param LanguageAspect $languageAspect * @return bool true if the given page translation record is suited for the given language ID - * @internal only in use for HMENU generation for now + * @internal */ public function isPageSuitableForLanguage(array $page, LanguageAspect $languageAspect): bool { diff --git a/typo3/sysext/seo/Tests/Functional/Fixtures/pages-sitemap.xml b/typo3/sysext/seo/Tests/Functional/Fixtures/pages-sitemap.xml index 4ce70947ae82423ef0b9f5c7e0098aa0d34349c1..633d377a1279efe3c3b5af67cba8416e5ab64b17 100644 --- a/typo3/sysext/seo/Tests/Functional/Fixtures/pages-sitemap.xml +++ b/typo3/sysext/seo/Tests/Functional/Fixtures/pages-sitemap.xml @@ -116,6 +116,22 @@ <deleted>0</deleted> <canonical_link>https://www.typo3.org</canonical_link> </pages> + <pages> + <uid>16</uid> + <pid>1</pid> + <title>Hidden in Default</title> + <slug>/hidden-in-default</slug> + <deleted>0</deleted> + <l18n_cfg>1</l18n_cfg> + </pages> + <pages> + <uid>17</uid> + <pid>1</pid> + <title>No Index</title> + <slug>/no-index</slug> + <deleted>0</deleted> + <no_index>1</no_index> + </pages> <pages> <uid>100</uid> <pid>0</pid> @@ -146,6 +162,16 @@ <sys_language_uid>1</sys_language_uid> <l10n_parent>3</l10n_parent> </pages> + <pages> + <uid>105</uid> + <pid>2</pid> + <title>Dummy 1-2-5 fr</title> + <slug>/dummy-1-2-5-fr</slug> + <deleted>0</deleted> + <sys_language_uid>1</sys_language_uid> + <l10n_parent>5</l10n_parent> + <l18n_cfg>2</l18n_cfg> + </pages> <pages> <uid>200</uid> <pid>0</pid> diff --git a/typo3/sysext/seo/Tests/Functional/XmlSitemap/AbstractXmlSitemapPagesTest.php b/typo3/sysext/seo/Tests/Functional/XmlSitemap/AbstractXmlSitemapPagesTest.php new file mode 100644 index 0000000000000000000000000000000000000000..82a88c30b9246b94ef45b882b4980548a6782679 --- /dev/null +++ b/typo3/sysext/seo/Tests/Functional/XmlSitemap/AbstractXmlSitemapPagesTest.php @@ -0,0 +1,74 @@ +<?php +declare(strict_types = 1); + +namespace TYPO3\CMS\Seo\Tests\Functional\XmlSitemap; + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +use TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase; +use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; +use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalResponse; + +class AbstractXmlSitemapPagesTest extends AbstractTestCase +{ + /** + * @var array + */ + protected const LANGUAGE_PRESETS = [ + 'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8', 'iso' => 'en', 'hrefLang' => 'en-US', 'direction' => ''], + 'FR' => ['id' => 1, 'title' => 'French', 'locale' => 'fr_FR.UTF8', 'iso' => 'fr', 'hrefLang' => 'fr-FR', 'direction' => ''], + 'DE' => ['id' => 2, 'title' => 'German', 'locale' => 'de_DE.UTF8', 'iso' => 'de', 'hrefLang' => 'de-DE', 'direction' => ''], + ]; + + /** + * @var string[] + */ + protected $coreExtensionsToLoad = [ + 'core', 'frontend', 'seo' + ]; + + protected function setUp(): void + { + parent::setUp(); + $this->importDataSet('EXT:seo/Tests/Functional/Fixtures/pages-sitemap.xml'); + $this->setUpFrontendRootPage( + 1, + [ + 'constants' => ['EXT:seo/Configuration/TypoScript/XmlSitemap/constants.typoscript'], + 'setup' => ['EXT:seo/Configuration/TypoScript/XmlSitemap/setup.typoscript'] + ] + ); + + $this->writeSiteConfiguration( + 'website-local', + $this->buildSiteConfiguration(1, 'http://localhost/'), + [ + $this->buildDefaultLanguageConfiguration('EN', '/'), + $this->buildLanguageConfiguration('FR', '/fr/'), + $this->buildLanguageConfiguration('DE', '/de/', ['FR']) + ] + ); + } + + protected function getResponse(string $uri = 'http://localhost/'): InternalResponse + { + return $this->executeFrontendRequest( + (new InternalRequest($uri))->withQueryParameters([ + 'id' => 1, + 'type' => 1533906435, + 'sitemap' => 'pages' + ]) + ); + } +} diff --git a/typo3/sysext/seo/Tests/Functional/XmlSitemap/XmlSitemapPagesTest.php b/typo3/sysext/seo/Tests/Functional/XmlSitemap/XmlSitemapPagesTest.php index f42d034e7c6a54c0a8dd3fb6bd47481496fceff6..91bd3092fed16ec5ba5ca2f7dd1e1717199ef161 100644 --- a/typo3/sysext/seo/Tests/Functional/XmlSitemap/XmlSitemapPagesTest.php +++ b/typo3/sysext/seo/Tests/Functional/XmlSitemap/XmlSitemapPagesTest.php @@ -16,60 +16,12 @@ namespace TYPO3\CMS\Seo\Tests\Functional\XmlSitemap; * The TYPO3 project - inspiring people to share! */ -use TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase; -use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; -use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalResponse; - /** * Contains functional tests for the XmlSitemap Index */ -class XmlSitemapPagesTest extends AbstractTestCase +class XmlSitemapPagesTest extends AbstractXmlSitemapPagesTest { - /** - * @var array - */ - protected const LANGUAGE_PRESETS = [ - 'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8', 'iso' => 'en', 'hrefLang' => 'en-US', 'direction' => ''], - 'FR' => ['id' => 1, 'title' => 'French', 'locale' => 'fr_FR.UTF8', 'iso' => 'fr', 'hrefLang' => 'fr-FR', 'direction' => ''], - 'DE' => ['id' => 2, 'title' => 'German', 'locale' => 'de_DE.UTF8', 'iso' => 'de', 'hrefLang' => 'de-DE', 'direction' => ''], - ]; - - /** - * @var string[] - */ - protected $coreExtensionsToLoad = [ - 'core', 'frontend', 'seo' - ]; - - /** - * @var string - */ - protected $body; - - protected function setUp(): void - { - parent::setUp(); - $this->importDataSet('EXT:seo/Tests/Functional/Fixtures/pages-sitemap.xml'); - $this->setUpFrontendRootPage( - 1, - [ - 'constants' => ['EXT:seo/Configuration/TypoScript/XmlSitemap/constants.typoscript'], - 'setup' => ['EXT:seo/Configuration/TypoScript/XmlSitemap/setup.typoscript'] - ] - ); - - $this->writeSiteConfiguration( - 'website-local', - $this->buildSiteConfiguration(1, 'http://localhost/'), - [ - $this->buildDefaultLanguageConfiguration('EN', '/'), - $this->buildLanguageConfiguration('FR', '/fr/'), - $this->buildLanguageConfiguration('DE', '/de/', ['FR']) - ] - ); - } - /** * @param string $urlPattern * @test @@ -100,6 +52,43 @@ class XmlSitemapPagesTest extends AbstractTestCase ); } + /** + * @test + */ + public function pagesSitemapDoesNotContainUrlWithNoIndexSet(): void + { + self::assertStringNotContainsString( + '<loc>http://localhost/no-index</loc>', + (string)$this->getResponse()->getBody() + ); + } + + /** + * Tests for exclusion depending on the l18n_cfg field + * + * @test + */ + public function pagesSitemapInDefaultLanguageDoesNotContainSiteThatIsHiddenInDefaultLanguage(): void + { + self::assertStringNotContainsString( + '<loc>http://localhost/hidden-in-default</loc>', + (string)$this->getResponse()->getBody() + ); + } + + /** + * Tests for exclusion depending on the l18n_cfg field + * + * @test + */ + public function pagesSitemapInAlternativeLanguageDoesNotContainSiteThatIsHiddenIfNotTranslated(): void + { + self::assertStringNotContainsString( + '<loc>http://localhost/de/dummy-1-2-5-fr</loc>', + (string)$this->getResponse('http://localhost/de/')->getBody() + ); + } + /** * @return array */ @@ -117,14 +106,16 @@ class XmlSitemapPagesTest extends AbstractTestCase */ public function pagesSitemapContainsTranslatedPages(): void { - $xml = new \SimpleXMLElement((string)$this->getResponse('http://localhost/fr/')->getBody()); - self::assertEquals(3, $xml->count()); + self::assertEquals( + 4, + (new \SimpleXMLElement((string)$this->getResponse('http://localhost/fr/')->getBody()))->count() + ); } /** * @test */ - public function pagesSitemapDoesNotContainsUntranslatedPages(): void + public function pagesSitemapDoesNotContainUntranslatedPages(): void { self::assertStringNotContainsString( '<loc>http://localhost/dummy-1-4</loc>', @@ -137,18 +128,9 @@ class XmlSitemapPagesTest extends AbstractTestCase */ public function pagesSitemapRespectFallbackStrategy(): void { - $xml = new \SimpleXMLElement((string)$this->getResponse('http://localhost/de/')->getBody()); - self::assertEquals(4, $xml->count()); - } - - protected function getResponse(string $uri = 'http://localhost/'): InternalResponse - { - return $this->executeFrontendRequest( - (new InternalRequest($uri))->withQueryParameters([ - 'id' => 1, - 'type' => 1533906435, - 'sitemap' => 'pages' - ]) + self::assertStringContainsString( + '<loc>http://localhost/de/dummy-1-3-fr</loc>', + (string)$this->getResponse('http://localhost/de/')->getBody() ); } } diff --git a/typo3/sysext/seo/Tests/Functional/XmlSitemap/XmlSitemapPagesWithHideIfNotTranslatedTest.php b/typo3/sysext/seo/Tests/Functional/XmlSitemap/XmlSitemapPagesWithHideIfNotTranslatedTest.php new file mode 100644 index 0000000000000000000000000000000000000000..30c578a7d8b6f6fe52217b670f1d2b9bd430417a --- /dev/null +++ b/typo3/sysext/seo/Tests/Functional/XmlSitemap/XmlSitemapPagesWithHideIfNotTranslatedTest.php @@ -0,0 +1,92 @@ +<?php +declare(strict_types = 1); + +namespace TYPO3\CMS\Seo\Tests\Functional\XmlSitemap; + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +/** + * Contains functional tests for the XmlSitemap Index with + * $GLOBALS['TYPO3_CONF_VARS']['FE']['hidePagesIfNotTranslatedByDefault'] = true + */ +class XmlSitemapPagesWithHideIfNotTranslatedTest extends AbstractXmlSitemapPagesTest +{ + /** + * This inverts the meaning of the + * "Hide page if no translation for current language exists" + * checkbox (l18n_cfg & 2). + * + * @var array + */ + protected $configurationToUseInTestInstance = [ + 'FE' => [ + 'hidePagesIfNotTranslatedByDefault' => true + ] + ]; + + /** + * Page marked as "Hide page if no translation for current language exists". + * With "hidePagesIfNotTranslatedByDefault" enabled we expect to see the page + * because it does NOT exist in the requested language (DE). + * + * @test + */ + public function pagesSitemapInAlternativeLanguageDoesContainSiteThatIsHiddenIfNotTranslated(): void + { + self::assertStringContainsString( + '<loc>http://localhost/de/dummy-1-2-5-fr</loc>', + (string)$this->getResponse('http://localhost/de/')->getBody() + ); + } + + /** + * Behavior is not changed with "hidePagesIfNotTranslatedByDefault" + * + * @test + */ + public function pagesSitemapContainsTranslatedPages(): void + { + self::assertEquals( + 4, + (new \SimpleXMLElement((string)$this->getResponse('http://localhost/fr/')->getBody()))->count() + ); + } + + /** + * Behavior is not changed with "hidePagesIfNotTranslatedByDefault" + * + * @test + */ + public function pagesSitemapDoesNotContainUntranslatedPages(): void + { + self::assertStringNotContainsString( + '<loc>http://localhost/dummy-1-4</loc>', + (string)$this->getResponse('http://localhost/fr/')->getBody() + ); + } + + /** + * Fallback strategy for pages is butchered by + * "hidePagesIfNotTranslatedByDefault" completely. + * + * @test + */ + public function pagesSitemapDoesNotCareAboutFallbackStrategy(): void + { + self::assertStringNotContainsString( + '<loc>http://localhost/de/dummy-1-3-fr</loc>', + (string)$this->getResponse('http://localhost/de/')->getBody() + ); + } +}