mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-22 14:16:11 +01:00
TASK: Add tests for new facets
Add functional test to test facet configuration including: - Mapping (indexing) - Searching (retrieving of facets) - Filter (already existed, now based on facet case sensitive)
This commit is contained in:
parent
38f9087111
commit
3e2e889e27
3 changed files with 50 additions and 2 deletions
|
@ -44,12 +44,13 @@ abstract class AbstractFunctionalTestCase extends BaseFunctionalTestCase
|
||||||
'port' => getenv('ES_PORT') ?: \Elastica\Connection::DEFAULT_PORT,
|
'port' => getenv('ES_PORT') ?: \Elastica\Connection::DEFAULT_PORT,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Start with clean system for test.
|
||||||
$this->cleanUp();
|
$this->cleanUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
// Delete everything so next test starts clean.
|
// Make system clean again.
|
||||||
$this->cleanUp();
|
$this->cleanUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,42 @@ class FilterTest extends AbstractFunctionalTestCase
|
||||||
$result = $searchService->search($searchRequest);
|
$result = $searchService->search($searchRequest);
|
||||||
$this->assertSame(2, count($result), 'Did not receive both indexed elements without filter.');
|
$this->assertSame(2, count($result), 'Did not receive both indexed elements without filter.');
|
||||||
|
|
||||||
$searchRequest->setFilter(['CType' => 'html']);
|
$searchRequest->setFilter(['CType' => 'HTML']);
|
||||||
$result = $searchService->search($searchRequest);
|
$result = $searchService->search($searchRequest);
|
||||||
$this->assertSame('5', $result->getResults()[0]['uid'], 'Did not get the expected result entry.');
|
$this->assertSame('5', $result->getResults()[0]['uid'], 'Did not get the expected result entry.');
|
||||||
$this->assertSame(1, count($result), 'Did not receive the single filtered element.');
|
$this->assertSame(1, count($result), 'Did not receive the single filtered element.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function itsPossibleToFetchFacetsForField()
|
||||||
|
{
|
||||||
|
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class)
|
||||||
|
->get(IndexerFactory::class)
|
||||||
|
->getIndexer('tt_content')
|
||||||
|
->indexAllDocuments()
|
||||||
|
;
|
||||||
|
|
||||||
|
$searchService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class)
|
||||||
|
->get(SearchService::class);
|
||||||
|
|
||||||
|
$searchRequest = new SearchRequest('Search Word');
|
||||||
|
$result = $searchService->search($searchRequest);
|
||||||
|
|
||||||
|
$this->assertSame(1, count($result->getFacets()), 'Did not receive the single defined facet.');
|
||||||
|
|
||||||
|
$facet = $result->getFacets()[0];
|
||||||
|
$this->assertSame('contentTypes', $facet->getName(), 'Name of facet was not as expected.');
|
||||||
|
$this->assertSame('CType', $facet->getField(), 'Field of facet was not expected.');
|
||||||
|
|
||||||
|
$options = $facet->getOptions();
|
||||||
|
$this->assertSame(2, count($options), 'Did not receive the expected number of possible options for facet.');
|
||||||
|
$option = $options[0];
|
||||||
|
$this->assertSame('HTML', $option->getName(), 'Option did not have expected Name.');
|
||||||
|
$this->assertSame(1, $option->getCount(), 'Option did not have expected count.');
|
||||||
|
$option = $options[1];
|
||||||
|
$this->assertSame('Header', $option->getName(), 'Option did not have expected Name.');
|
||||||
|
$this->assertSame(1, $option->getCount(), 'Option did not have expected count.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,20 @@ plugin {
|
||||||
indexing {
|
indexing {
|
||||||
tt_content {
|
tt_content {
|
||||||
indexer = Leonmrni\SearchCore\Domain\Index\TcaIndexer
|
indexer = Leonmrni\SearchCore\Domain\Index\TcaIndexer
|
||||||
|
|
||||||
|
mapping {
|
||||||
|
CType {
|
||||||
|
type = keyword
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
searching {
|
||||||
|
facets {
|
||||||
|
contentTypes {
|
||||||
|
field = CType
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue