From 407db1669cdb339c744fa9fff4e76b6e32ee7b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Thu, 1 Mar 2018 11:23:58 +0100 Subject: [PATCH] EZP-28799: Subtree criterion Content Search does not work correctly with multiple Locations (#2238) * EZP-28799: test Subtree criterion handler with negative matches * EZP-28799: fix Subtree criterion handler with negative matches --- .../Regression/EZP28799SubtreeSearchTest.php | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Repository/Tests/Regression/EZP28799SubtreeSearchTest.php diff --git a/Repository/Tests/Regression/EZP28799SubtreeSearchTest.php b/Repository/Tests/Regression/EZP28799SubtreeSearchTest.php new file mode 100644 index 000000000..45866972a --- /dev/null +++ b/Repository/Tests/Regression/EZP28799SubtreeSearchTest.php @@ -0,0 +1,105 @@ +getRepository()->getContentService(); + $contentTypeService = $this->getRepository()->getContentTypeService(); + $locationService = $this->getRepository()->getLocationService(); + + $contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); + $locationCreateStruct = $locationService->newLocationCreateStruct($rootLocationId); + + $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); + $contentCreateStruct->setField('name', 'LEFT'); + + $draft = $contentService->createContent($contentCreateStruct, [$locationCreateStruct]); + $leftFolder = $contentService->publishVersion($draft->versionInfo); + + $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); + $contentCreateStruct->setField('name', 'RIGHT'); + + $draft = $contentService->createContent($contentCreateStruct, [$locationCreateStruct]); + $rightFolder = $contentService->publishVersion($draft->versionInfo); + + $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); + $contentCreateStruct->setField('name', 'TARGET'); + + $locationCreateStructLeft = $locationService->newLocationCreateStruct( + $leftFolder->contentInfo->mainLocationId + ); + $locationCreateStructRight = $locationService->newLocationCreateStruct( + $rightFolder->contentInfo->mainLocationId + ); + $draft = $contentService->createContent( + $contentCreateStruct, + [ + $locationCreateStructLeft, + $locationCreateStructRight, + ] + ); + $targetFolder = $contentService->publishVersion($draft->versionInfo); + + return [$leftFolder, $rightFolder, $targetFolder]; + } + + public function testConflictingConditions() + { + list($leftFolder, $rightFolder, $targetFolder) = $this->createTestContent(); + $locationService = $this->getRepository()->getLocationService(); + $leftLocation = $locationService->loadLocation($leftFolder->contentInfo->mainLocationId); + + $query = new Query([ + 'filter' => new Query\Criterion\LogicalAnd([ + new Query\Criterion\ContentId($targetFolder->contentInfo->id), + new Query\Criterion\Subtree($leftLocation->pathString), + new Query\Criterion\LogicalNot( + new Query\Criterion\Subtree($leftLocation->pathString) + ), + ]), + ]); + + $searchService = $this->getRepository()->getSearchService(); + $result = $searchService->findContent($query); + + $this->assertSame(0, $result->totalCount); + } + + public function testNegativeSubtree() + { + list($leftFolder, $rightFolder, $targetFolder) = $this->createTestContent(); + $locationService = $this->getRepository()->getLocationService(); + $leftLocation = $locationService->loadLocation($leftFolder->contentInfo->mainLocationId); + + $query = new Query([ + 'filter' => new Query\Criterion\LogicalAnd([ + new Query\Criterion\ContentId($targetFolder->contentInfo->id), + new Query\Criterion\LogicalNot( + new Query\Criterion\Subtree($leftLocation->pathString) + ), + ]), + ]); + + $searchService = $this->getRepository()->getSearchService(); + $result = $searchService->findContent($query); + + $this->assertSame(0, $result->totalCount); + } +}