Skip to content

Commit

Permalink
[BUGFIX] Strip logical operator prefix in config.additionalWhere
Browse files Browse the repository at this point in the history
When building the additionalWhere clause in the
RecordsXmlSitemapDataProvider, a possible `AND` operator
must be removed. Doctrine's queryBuilder adds this prefix
automatically.

Resolves: #88865
Releases: master,9.5
Change-Id: I6fd1f170c1c3a3b46bcaab4f2a9589e98e489a79
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61612
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Richard Haeser <richard@maxserv.com>
Reviewed-by: Richard Haeser <richard@maxserv.com>
  • Loading branch information
tmotyl authored and Richard Haeser committed Sep 3, 2019
1 parent cfeae73 commit 0999310
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 4 deletions.
Expand Up @@ -19,6 +19,7 @@
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Seo\XmlSitemap\Exception\MissingConfigurationException;
Expand Down Expand Up @@ -92,7 +93,7 @@ public function generateItems(): void
}

if (!empty($this->config['additionalWhere'])) {
$constraints[] = $this->config['additionalWhere'];
$constraints[] = QueryHelper::stripLogicalOperatorPrefix($this->config['additionalWhere']);
}

$queryBuilder->select('*')
Expand Down
32 changes: 32 additions & 0 deletions typo3/sysext/seo/Tests/Functional/Fixtures/records.typoscript
Expand Up @@ -18,6 +18,38 @@ plugin.tx_seo {
}
}
}
records_with_additional_where {
provider = TYPO3\CMS\Seo\XmlSitemap\RecordsXmlSitemapDataProvider
config {
table = sys_category
additionalWhere = (uid=1)
sortField = sorting
lastModifiedField = tstamp
pid = 11
url {
pageId = 1
fieldToParameterMap {
uid = tx_example_category[id]
}
}
}
}
records_with_additional_where_starting_with_logical_operator {
provider = TYPO3\CMS\Seo\XmlSitemap\RecordsXmlSitemapDataProvider
config {
table = sys_category
additionalWhere = AND (uid=2)
sortField = sorting
lastModifiedField = tstamp
pid = 11
url {
pageId = 1
fieldToParameterMap {
uid = tx_example_category[id]
}
}
}
}
}
}
}
Expand Down
Expand Up @@ -45,7 +45,6 @@ protected function setUp()
'setup' => [
'EXT:seo/Configuration/TypoScript/XmlSitemap/setup.typoscript',
'EXT:seo/Tests/Functional/Fixtures/records.typoscript',
'EXT:seo/Tests/Functional/Fixtures/content.typoscript'
],
]
);
Expand All @@ -63,8 +62,11 @@ protected function setUp()
/**
* @test
* @dataProvider sitemapEntriesToCheck
* @var string $host
* @var array $expectedEntries
* @var array $notExpectedEntries
*/
public function checkIfSiteMapIndexContainsSysCategoryLinks($host, $expectedEntries, $notExpectedEntries): void
public function checkIfSiteMapIndexContainsSysCategoryLinks(string $host, array $expectedEntries, array $notExpectedEntries): void
{
$response = $this->executeFrontendRequest(
(new InternalRequest($host))->withQueryParameters(
Expand Down Expand Up @@ -93,7 +95,7 @@ public function checkIfSiteMapIndexContainsSysCategoryLinks($host, $expectedEntr
}

/**
* @return array
* @return array[]
*/
public function sitemapEntriesToCheck(): array
{
Expand Down Expand Up @@ -123,4 +125,69 @@ public function sitemapEntriesToCheck(): array
],
];
}

/**
* @test
* @dataProvider additionalWhereTypoScriptConfigurationsToCheck
* @var string $sitemap
* @var array $expectedEntries
* @var array $notExpectedEntries
*/
public function checkSiteMapWithDifferentTypoScriptConfigs(string $sitemap, array $expectedEntries, array $notExpectedEntries): void
{
$response = $this->executeFrontendRequest(
(new InternalRequest('http://localhost/'))->withQueryParameters(
[
'id' => 1,
'type' => 1533906435,
'sitemap' => $sitemap,
]
)
);

$this->assertEquals(200, $response->getStatusCode());
$this->assertArrayHasKey('Content-Length', $response->getHeaders());
$stream = $response->getBody();
$stream->rewind();
$content = $stream->getContents();

foreach ($expectedEntries as $expectedEntry) {
self::assertStringContainsString($expectedEntry, $content);
}

foreach ($notExpectedEntries as $notExpectedEntry) {
self::assertStringNotContainsString($notExpectedEntry, $content);
}

$this->assertGreaterThan(0, $response->getHeader('Content-Length')[0]);
}

/**
* @return array[]
*/
public function additionalWhereTypoScriptConfigurationsToCheck(): array
{
return [
[
'records_with_additional_where',
[
'http://localhost/?tx_example_category%5Bid%5D=1&amp;',
],
[
'http://localhost/?tx_example_category%5Bid%5D=2&amp;',
'http://localhost/?tx_example_category%5Bid%5D=3&amp;'
]
],
[
'records_with_additional_where_starting_with_logical_operator',
[
'http://localhost/?tx_example_category%5Bid%5D=2&amp;',
],
[
'http://localhost/?tx_example_category%5Bid%5D=1&amp;',
'http://localhost/?tx_example_category%5Bid%5D=3&amp;'
]
],
];
}
}

0 comments on commit 0999310

Please sign in to comment.