diff --git a/tests/FIlter/AggsTest.php b/tests/FIlter/AggsTest.php index 50fce3c7595a4649396b22be6cf7dce063a56258..f8dced8b77434cc210a00c29534b0b4a1689ca23 100644 --- a/tests/FIlter/AggsTest.php +++ b/tests/FIlter/AggsTest.php @@ -178,8 +178,8 @@ class AggsTest extends TestCase 0 => [ 'label' => null, 'value' => 'red', - 'count' => 0, - 'active' => false + 'count' => 1, + 'active' => true ], 1 => [ 'label' => null, @@ -405,8 +405,8 @@ class AggsTest extends TestCase 0 => [ 'label' => null, 'value' => 'red', - 'count' => 0, - 'active' => false + 'count' => 1, + 'active' => true ], 1 => [ 'label' => null, @@ -526,8 +526,8 @@ class AggsTest extends TestCase 1 => [ 'label' => null, 'value' => 'white', - 'count' => 0, - 'active' => false + 'count' => 1, + 'active' => true ] ], 'range' => [] @@ -583,4 +583,235 @@ class AggsTest extends TestCase $this->assertEqualsCanonicalizing($expected, FormatData::formatDataWFacets($result)); } + + public function testKeywordFilter() + { + $handler = SearchClient::getInstance(); + + $q = SearchQuery::createFromArray( + [ + 'filters' => [ + 'categoryId' => 't-short', + 'color' => ['white'], + 'brand' => ['nike'], + 'price' => ['min' => 100] + ] + ] + ); + $result = $handler->handle($q); + + $expected = [ + 'hits' => [ + 'h2' + ], + 'facets' => [ + 0 => [ + 'code' => 'brand', + 'label' => null, + 'type' => 'list', + 'items' => [ + 'list' => [ + 0 => [ + 'label' => null, + 'value' => 'nike', + 'count' => 1, + 'active' => true + ], + 1 => [ + 'label' => null, + 'value' => 'rebook', + 'count' => 1, + 'active' => true + ] + ], + 'range' => [] + ] + ], + 1 => [ + 'code' => 'color', + 'label' => null, + 'type' => 'list', + 'items' => [ + 'list' => [ + 0 => [ + 'label' => null, + 'value' => 'red', + 'count' => 1, + 'active' => true + ], + 1 => [ + 'label' => null, + 'value' => 'white', + 'count' => 1, + 'active' => true + ] + ], + 'range' => [] + ] + ], + 2 => [ + 'code' => 'size', + 'label' => null, + 'type' => 'list', + 'items' => [ + 'list' => [ + 0 => [ + 'label' => null, + 'value' => 'xl', + 'count' => 0, + 'active' => false + ], + 1 => [ + 'label' => null, + 'value' => 'xxl', + 'count' => 1, + 'active' => true + ] + ], + 'range' => [] + ] + ], + 3 => [ + 'code' => 'price', + 'label' => null, + 'type' => 'range', + 'items' => [ + 'list' => [], + 'range' => [ + 0 => [ + 'label' => null, + 'count' => 1, + 'active' => true, + 'fullRange' => [ + 'min' => 104.0, + 'max' => 106.0 + ], + 'activeRange' => [ + 'min' => 105.0, + 'max' => 105.0 + ] + ] + ] + ] + ] + ] + ]; + + $this->assertEqualsCanonicalizing($expected, FormatData::formatDataWFacets($result)); + } + + public function testKeywordFilterTwo() + { + $handler = SearchClient::getInstance(); + + $q = SearchQuery::createFromArray( + [ + 'filters' => [ + 'categoryId' => 't-short', + 'color' => ['white'], + 'brand' => ['nike', 'reebok'] + ] + ] + ); + $result = $handler->handle($q); + + $expected = [ + 'hits' => [ + 'h2' + ], + 'facets' => [ + 0 => [ + 'code' => 'brand', + 'label' => null, + 'type' => 'list', + 'items' => [ + 'list' => [ + 0 => [ + 'label' => null, + 'value' => 'nike', + 'count' => 1, + 'active' => true + ], + 1 => [ + 'label' => null, + 'value' => 'rebook', + 'count' => 1, + 'active' => true + ] + ], + 'range' => [] + ] + ], + 1 => [ + 'code' => 'color', + 'label' => null, + 'type' => 'list', + 'items' => [ + 'list' => [ + 0 => [ + 'label' => null, + 'value' => 'red', + 'count' => 1, + 'active' => true + ], + 1 => [ + 'label' => null, + 'value' => 'white', + 'count' => 1, + 'active' => true + ] + ], + 'range' => [] + ] + ], + 2 => [ + 'code' => 'size', + 'label' => null, + 'type' => 'list', + 'items' => [ + 'list' => [ + 0 => [ + 'label' => null, + 'value' => 'xl', + 'count' => 0, + 'active' => false + ], + 1 => [ + 'label' => null, + 'value' => 'xxl', + 'count' => 1, + 'active' => true + ] + ], + 'range' => [] + ] + ], + 3 => [ + 'code' => 'price', + 'label' => null, + 'type' => 'range', + 'items' => [ + 'list' => [], + 'range' => [ + 0 => [ + 'label' => null, + 'count' => 1, + 'active' => true, + 'fullRange' => [ + 'min' => 104.0, + 'max' => 106.0 + ], + 'activeRange' => [ + 'min' => 105.0, + 'max' => 105.0 + ] + ] + ] + ] + ] + ] + ]; + + $this->assertEqualsCanonicalizing($expected, FormatData::formatDataWFacets($result)); + } } \ No newline at end of file