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:
Daniel Siepmann 2017-07-06 15:51:29 +02:00
parent 38f9087111
commit 3e2e889e27
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
3 changed files with 50 additions and 2 deletions

View file

@ -44,12 +44,13 @@ abstract class AbstractFunctionalTestCase extends BaseFunctionalTestCase
'port' => getenv('ES_PORT') ?: \Elastica\Connection::DEFAULT_PORT,
]);
// Start with clean system for test.
$this->cleanUp();
}
public function tearDown()
{
// Delete everything so next test starts clean.
// Make system clean again.
$this->cleanUp();
}

View file

@ -53,9 +53,42 @@ class FilterTest extends AbstractFunctionalTestCase
$result = $searchService->search($searchRequest);
$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);
$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.');
}
/**
* @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.');
}
}

View file

@ -11,6 +11,20 @@ plugin {
indexing {
tt_content {
indexer = Leonmrni\SearchCore\Domain\Index\TcaIndexer
mapping {
CType {
type = keyword
}
}
}
}
searching {
facets {
contentTypes {
field = CType
}
}
}
}