Skip to content

Commit

Permalink
Adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Richter committed Dec 11, 2024
1 parent 7079609 commit 9189c9e
Showing 1 changed file with 175 additions and 10 deletions.
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 9189c9e

Please sign in to comment.