Skip to content

Commit

Permalink
merge changes in test
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-sc committed Dec 11, 2024
2 parents 58d55f7 + 757a7da commit d223804
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 30 deletions.
42 changes: 22 additions & 20 deletions Classes/Common/QueryParamsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,37 +162,38 @@ private static function getAggs(array $settings, string $index): array

private static function getFilter(array $field): array
{
/*
if (
isset($field['type']) &&
$field['type'] == 'terms'
) {
*/
return [
'terms' => [
$field['name']. '.keyword' => $field['value']
$field['name'] . '.keyword' => $field['value']
]
];
//}
}

/* return [
$field['name'] => [
'nested' => [
'path' => $field['name']
],
'aggs' => [
'names' => [
'terms' => [
'script' => [
'source' => $field['script'],
'lang' => 'painless'
],
'size' => 15,
]
if (
isset($field['type']) &&
$field['type'] == 'keyword'
) {
return [
'terms' => [
$field['name'] => $field['value']
]
];
}

return [
'nested' => [
'path' => $field['name'],
'query' => [
'match' => [
$field['name'] . '.' . $field['path'] => $field['value']
]
]
]
];*/
];
}

/**
Expand All @@ -201,7 +202,8 @@ private static function getFilter(array $field): array
private function setCommonParams(): void
{
// set index name
$this->query['index'] = $this->indexName;
$index = $this->indexName;
$this->query['index'] = $index;

// set body
if (!isset($this->params['searchText']) || $this->params['searchText'] == '') {
Expand Down
185 changes: 175 additions & 10 deletions Tests/Unit/Common/QueryParamsBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ final class QueryParamsBuilderTest extends UnitTestCase
const EX_EXTENSION2 = 'ex-extension2';
const EX_FIELD1 = 'ex-field1';
const EX_FIELD2 = 'ex-field2';
const EX_FIELD3 = 'ex-field3';
const EX_PAGE = 3;
const EX_SCRIPT = 'ex-script';
const EX_PATH = 'ex-path';

private QueryParamsBuilder $subject;
private array $settings = [];
Expand Down Expand Up @@ -61,8 +63,13 @@ protected function setUp(): void
],
1 => [
'field' => self::EX_FIELD2,
'type' => 'keyword',
],
2 => [
'field' => self::EX_FIELD3,
'type' => 'nested',
'script' => self::EX_SCRIPT
'script' => self::EX_SCRIPT,
'path' => self::EX_PATH
]
]
],
Expand All @@ -77,8 +84,7 @@ protected function setUp(): void
],
1 => [
'field' => self::EX_FIELD2,
'type' => 'nested',
'script' => self::EX_SCRIPT
'type' => 'keyword'
]
]
]
Expand Down Expand Up @@ -152,8 +158,13 @@ public function IndexParamIsProcessedCorrectly(): void
]
],
self::EX_FIELD2 => [
'terms' => [
'field' => self::EX_FIELD2
]
],
self::EX_FIELD3 => [
'nested' => [
'path' => self::EX_FIELD2
'path' => self::EX_FIELD3
],
'aggs' => [
'names' => [
Expand Down Expand Up @@ -223,13 +234,13 @@ public function pageParamIsProcessedCorrectly(): void
/**
* @test
*/
public function filterParamIsProcessedCorrectly(): void
public function termsFilterParamIsProcessedCorrectly(): void
{
$this->subject->
setSettings($this->settings)->
setSearchParams([
'index' => self:: EX_INDEX,
'f_filter' => self::EX_VAL
'f_' . self::EX_FIELD1 => self::EX_VAL
]);
GeneralUtility::addInstance(ExtensionConfiguration::class, $this->extConf);

Expand All @@ -252,8 +263,13 @@ public function filterParamIsProcessedCorrectly(): void
]
],
self::EX_FIELD2 => [
'terms' => [
'field' => self::EX_FIELD2
]
],
self::EX_FIELD3 => [
'nested' => [
'path' => self::EX_FIELD2
'path' => self::EX_FIELD3
],
'aggs' => [
'names' => [
Expand All @@ -275,7 +291,156 @@ public function filterParamIsProcessedCorrectly(): void
],
'filter' => [
[ 'term' => [
'filter.keyword' => self::EX_VAL
self::EX_FIELD1 . '.keyword' => self::EX_VAL
]
]
]
]
]
]
];

self::assertEquals($expected, $this->subject->getQueryParams());
}

/**
* @test
*/
public function keywordFilterParamIsProcessedCorrectly(): void
{
$this->subject->
setSettings($this->settings)->
setSearchParams([
'index' => self:: EX_INDEX,
'f_' . self::EX_FIELD2 => self::EX_VAL
]);
GeneralUtility::addInstance(ExtensionConfiguration::class, $this->extConf);

$expected = [
'index' => self::EX_INDEX,
'size' => PaginatorTest::ITEMS_PER_PAGE,
'body' => [
'_source' => [
QueryParamsBuilder::TYPE_FIELD,
QueryParamsBuilder::HEADER_FIELD,
QueryParamsBuilder::BODY_FIELD,
QueryParamsBuilder::FOOTER_FIELD,
QueryParamsBuilder::SEARCHABLE_FIELD

],
'aggs' => [
self::EX_FIELD1 => [
'terms' => [
'field' => self::EX_FIELD1 . '.keyword'
]
],
self::EX_FIELD2 => [
'terms' => [
'field' => self::EX_FIELD2
]
],
self::EX_FIELD3 => [
'nested' => [
'path' => self::EX_FIELD3
],
'aggs' => [
'names' => [
'terms' => [
'script' => [
'source' => self::EX_SCRIPT,
'lang' => 'painless'
],
'size' => 15
]
]
]
]
],
'query' => [
'bool' => [
'must' => [
[ 'match_all' => new \StdClass() ]
],
'filter' => [
[ 'term' => [
self::EX_FIELD2 => self::EX_VAL
]
]
]
]
]
]
];

self::assertEquals($expected, $this->subject->getQueryParams());
}

/**
* @test
*/
public function nestedFilterParamIsProcessedCorrectly(): void
{
$this->subject->
setSettings($this->settings)->
setSearchParams([
'index' => self:: EX_INDEX,
'f_' . self::EX_FIELD3 => self::EX_VAL
]);
GeneralUtility::addInstance(ExtensionConfiguration::class, $this->extConf);

$expected = [
'index' => self::EX_INDEX,
'size' => PaginatorTest::ITEMS_PER_PAGE,
'body' => [
'_source' => [
QueryParamsBuilder::TYPE_FIELD,
QueryParamsBuilder::HEADER_FIELD,
QueryParamsBuilder::BODY_FIELD,
QueryParamsBuilder::FOOTER_FIELD,
QueryParamsBuilder::SEARCHABLE_FIELD

],
'aggs' => [
self::EX_FIELD1 => [
'terms' => [
'field' => self::EX_FIELD1 . '.keyword'
]
],
self::EX_FIELD2 => [
'terms' => [
'field' => self::EX_FIELD2
]
],
self::EX_FIELD3 => [
'nested' => [
'path' => self::EX_FIELD3
],
'aggs' => [
'names' => [
'terms' => [
'script' => [
'source' => self::EX_SCRIPT,
'lang' => 'painless'
],
'size' => 15
]
]
]
]
],
'query' => [
'bool' => [
'must' => [
[ 'match_all' => new \StdClass() ]
],
'filter' => [
[ 'nested' => [
'path' => self::EX_FIELD3,
'query' => [
'match' => [
self::EX_FIELD3 . '.' . self::EX_PATH => self::EX_VAL
]
]
]
]
]
Expand All @@ -296,7 +461,7 @@ public function countQueryIsBuiltCorrectly(): void
setSettings($this->settings)->
setSearchParams([
'index' => self:: EX_INDEX,
'f_filter' => self::EX_VAL
'f_' . self::EX_FIELD1 => self::EX_VAL
]);

$expected = [
Expand All @@ -309,7 +474,7 @@ public function countQueryIsBuiltCorrectly(): void
],
'filter' => [
[ 'term' => [
'filter.keyword' => self::EX_VAL
self::EX_FIELD1 . '.keyword' => self::EX_VAL
]
]
]
Expand Down

0 comments on commit d223804

Please sign in to comment.