Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-31275: Added tests for SearchService findLocations method covering IsEmpty Criterion #2915

Merged
merged 3 commits into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions eZ/Publish/API/Repository/Tests/SearchServiceLocationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,84 @@ public function testFindFacetedLocation(LocationQuery $query, $fixture)
$this->assertQueryFixture($query, $fixture);
}

/**
* Create movie Content with subtitle field set to null.
*
* @return \eZ\Publish\API\Repository\Values\Content\Content[]
*/
protected function createMovieContent()
mateuszbieniek marked this conversation as resolved.
Show resolved Hide resolved
{
$movies = [];

$repository = $this->getRepository();
$contentTypeService = $repository->getContentTypeService();
$contentService = $repository->getContentService();

$createStruct = $contentTypeService->newContentTypeCreateStruct('movie');
$createStruct->mainLanguageCode = 'eng-GB';
$createStruct->remoteId = 'movie-123';
$createStruct->names = ['eng-GB' => 'Movie'];
$createStruct->creatorId = 14;
$createStruct->creationDate = new \DateTime();

$fieldTitle = $contentTypeService->newFieldDefinitionCreateStruct('title', 'ezstring');
$fieldTitle->names = ['eng-GB' => 'Title'];
$fieldTitle->fieldGroup = 'main';
$fieldTitle->position = 1;
$fieldTitle->isTranslatable = false;
$fieldTitle->isSearchable = true;
$fieldTitle->isRequired = true;
$createStruct->addFieldDefinition($fieldTitle);

$fieldSubtitle = $contentTypeService->newFieldDefinitionCreateStruct('subtitle', 'ezstring');
$fieldSubtitle->names = ['eng-GB' => 'Subtitle'];
$fieldSubtitle->fieldGroup = 'main';
$fieldSubtitle->position = 2;
$fieldSubtitle->isTranslatable = false;
$fieldSubtitle->isSearchable = true;
$fieldSubtitle->isRequired = false;
$createStruct->addFieldDefinition($fieldSubtitle);

$contentTypeGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Content');
$contentTypeDraft = $contentTypeService->createContentType($createStruct, [$contentTypeGroup]);
$contentTypeService->publishContentTypeDraft($contentTypeDraft);
$contentType = $contentTypeService->loadContentType($contentTypeDraft->id);

$createStructRambo = $contentService->newContentCreateStruct($contentType, 'eng-GB');
$createStructRambo->remoteId = 'movie-456';
$createStructRambo->alwaysAvailable = false;
$createStructRambo->setField('title', 'Rambo');
$locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2);

$ramboDraft = $contentService->createContent($createStructRambo, [$locationCreateStruct]);
$movies[] = $contentService->publishVersion($ramboDraft->getVersionInfo());
$this->refreshSearch($repository);

$createStructRobocop = $contentService->newContentCreateStruct($contentType, 'eng-GB');
$createStructRobocop->remoteId = 'movie-789';
$createStructRobocop->alwaysAvailable = false;
$createStructRobocop->setField('title', 'Robocop');
$createStructRobocop->setField('subtitle', '');
$locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2);

$robocopDraft = $contentService->createContent($createStructRobocop, [$locationCreateStruct]);
$movies[] = $contentService->publishVersion($robocopDraft->getVersionInfo());
$this->refreshSearch($repository);

$createStructLastHope = $contentService->newContentCreateStruct($contentType, 'eng-GB');
$createStructLastHope->remoteId = 'movie-101112';
$createStructLastHope->alwaysAvailable = false;
$createStructLastHope->setField('title', 'Star Wars');
$createStructLastHope->setField('subtitle', 'Last Hope');
$locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2);

$lastHopeDraft = $contentService->createContent($createStructLastHope, [$locationCreateStruct]);
$movies[] = $contentService->publishVersion($lastHopeDraft->getVersionInfo());
$this->refreshSearch($repository);

return $movies;
}

/**
* Create test Content with ezcountry field having multiple countries selected.
*
Expand Down Expand Up @@ -101,6 +179,68 @@ protected function createMultipleCountriesContent()
return $content;
}

/**
* Test for the findLocations() method.
*
* @see \eZ\Publish\API\Repository\SearchService::findLocations()
*/
public function testFieldIsEmptyInLocation()
{
$testContents = $this->createMovieContent();

$query = new LocationQuery(
[
'query' => new Criterion\IsFieldEmpty('subtitle'),
]
);

$repository = $this->getRepository();
$searchService = $repository->getSearchService();
$result = $searchService->findLocations($query);

$this->assertEquals(2, $result->totalCount);

$this->assertEquals(
$testContents[0]->contentInfo->mainLocationId,
$result->searchHits[0]->valueObject->id
);

$this->assertEquals(
$testContents[1]->contentInfo->mainLocationId,
$result->searchHits[1]->valueObject->id
);
}

/**
* Test for the findLocations() method.
*
* @see \eZ\Publish\API\Repository\SearchService::findLocations()
*/
public function testFieldIsNotEmptyInLocation()
{
$testContents = $this->createMovieContent();

$query = new LocationQuery(
[
'query' => new Criterion\IsFieldEmpty(
'subtitle',
false
),
]
);

$repository = $this->getRepository();
$searchService = $repository->getSearchService();
$result = $searchService->findLocations($query);

$this->assertEquals(1, $result->totalCount);

$this->assertEquals(
$testContents[2]->contentInfo->mainLocationId,
$result->searchHits[0]->valueObject->id
);
}

/**
* Test for the findLocations() method.
*
Expand Down
6 changes: 3 additions & 3 deletions eZ/Publish/API/Repository/Tests/SearchServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1289,12 +1289,12 @@ public function testFieldIsEmpty()
/**
* Test for the findContent() method.
*
* @param \eZ\Publish\API\Repository\Values\Content\Content[]
* @see \eZ\Publish\API\Repository\SearchService::findContent()
* @depends \eZ\Publish\API\Repository\Tests\SearchServiceTest::testFieldIsEmpty
*/
public function testFieldIsNotEmpty(array $testContents)
public function testFieldIsNotEmpty()
{
$testContents = $this->createMovieContent();

$query = new Query(
[
'query' => new Criterion\IsFieldEmpty(
Expand Down