*/
use Psr\Http\Message\ServerRequestInterface;
+use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
*/
public function generateItems(): void
{
- if (empty($this->config['table'])) {
+ $table = $this->config['table'];
+
+ if (empty($table)) {
throw new MissingConfigurationException(
'No configuration found for sitemap ' . $this->getKey(),
1535576053
$priorityField = $this->config['priorityField'] ?? '';
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
- ->getQueryBuilderForTable($this->config['table']);
+ ->getQueryBuilderForTable($table);
$constraints = [];
+ if (!empty($GLOBALS['TCA'][$table]['ctrl']['languageField'])) {
+ $constraints[] = $queryBuilder->expr()->in(
+ $GLOBALS['TCA'][$table]['ctrl']['languageField'],
+ [
+ -1, // All languages
+ $this->getLanguageId() // Current language
+ ]
+ );
+ }
if (!empty($pids)) {
$recursiveLevel = isset($this->config['recursive']) ? (int)$this->config['recursive'] : 0;
}
$queryBuilder->select('*')
- ->from($this->config['table']);
+ ->from($table);
if (!empty($constraints)) {
$queryBuilder->where(
return $additionalParams;
}
+
+ /**
+ * @return int
+ * @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException
+ */
+ protected function getLanguageId(): int
+ {
+ $context = GeneralUtility::makeInstance(Context::class);
+ return (int)$context->getPropertyFromAspect('language', 'id');
+ }
}
],
]
);
- }
- /**
- * @test
- */
- public function checkIfSiteMapIndexContainsSysCategoryLinks(): void
- {
$this->writeSiteConfiguration(
'website-local',
$this->buildSiteConfiguration(1, 'http://localhost/'),
[
$this->buildDefaultLanguageConfiguration('EN', '/'),
+ $this->buildLanguageConfiguration('FR', '/fr'),
]
);
+ }
+ /**
+ * @test
+ * @dataProvider sitemapEntriesToCheck
+ */
+ public function checkIfSiteMapIndexContainsSysCategoryLinks($host, $expectedEntries, $notExpectedEntries): void
+ {
$response = $this->executeFrontendRequest(
- (new InternalRequest('http://localhost/'))->withQueryParameters(
+ (new InternalRequest($host))->withQueryParameters(
[
- 'id' => 1,
'type' => 1533906435,
'sitemap' => 'records',
]
$stream = $response->getBody();
$stream->rewind();
$content = $stream->getContents();
- self::assertContains('http://localhost/?tx_example_category%5Bid%5D=1&', $content);
- self::assertContains('http://localhost/?tx_example_category%5Bid%5D=2&', $content);
- self::assertContains('<priority>0.5</priority>', $content);
+
+ foreach ($expectedEntries as $expectedEntry) {
+ self::assertContains($expectedEntry, $content);
+ }
+
+ foreach ($notExpectedEntries as $notExpectedEntry) {
+ self::assertNotContains($notExpectedEntry, $content);
+ }
$this->assertGreaterThan(0, $response->getHeader('Content-Length')[0]);
}
+ /**
+ * @return array
+ */
+ public function sitemapEntriesToCheck(): array
+ {
+ return [
+ 'default-language' => [
+ 'http://localhost/',
+ [
+ 'http://localhost/?tx_example_category%5Bid%5D=1&',
+ 'http://localhost/?tx_example_category%5Bid%5D=2&',
+ '<priority>0.5</priority>'
+ ],
+ [
+ 'http://localhost/?tx_example_category%5Bid%5D=3&',
+ 'http://localhost/fr/?tx_example_category%5Bid%5D=3&',
+ ]
+ ],
+ 'french-language' => [
+ 'http://localhost/fr',
+ [
+ 'http://localhost/fr/?tx_example_category%5Bid%5D=3&',
+ '<priority>0.5</priority>'
+ ],
+ [
+ 'http://localhost/fr/?tx_example_category%5Bid%5D=1&',
+ 'http://localhost/fr/?tx_example_category%5Bid%5D=2&',
+ 'http://localhost/?tx_example_category%5Bid%5D=1&',
+ 'http://localhost/?tx_example_category%5Bid%5D=2&',
+ ]
+ ],
+ ];
+ }
+
/**
* @test
*/
public function checkIfSiteMapIndexContainsCustomChangeFreqAndPriorityValues(): void
{
- $this->writeSiteConfiguration(
- 'website-local',
- $this->buildSiteConfiguration(1, 'http://localhost/'),
- [
- $this->buildDefaultLanguageConfiguration('EN', '/'),
- ]
- );
-
$response = $this->executeFrontendRequest(
(new InternalRequest('http://localhost/'))->withQueryParameters(
[