public function testFacetQueriesAreReturned() { $attributeCodeString = 'price'; $attributeValueFrom = '*'; $attributeValueTo = '500'; $attributeValueCount = 2; $query = sprintf('%s:[%s TO %s]', $attributeCodeString, $attributeValueFrom, $attributeValueTo); $encodedQueryValue = sprintf('From %s to %s', $attributeValueFrom, $attributeValueTo); $responseArray = ['facet_counts' => ['facet_queries' => [$query => $attributeValueCount]]]; $selectedFilterAttributeCodes = []; $stubFacetFieldTransformation = $this->createMock(FacetFieldTransformation::class); $stubFacetFieldTransformation->method('encode')->willReturn($encodedQueryValue); $this->stubFacetFieldTransformationRegistry->method('hasTransformationForCode')->with($attributeCodeString)->willReturn(true); $this->stubFacetFieldTransformationRegistry->method('getTransformationByCode')->with($attributeCodeString)->willReturn($stubFacetFieldTransformation); $response = SolrResponse::fromSolrResponseArray($responseArray, $this->stubFacetFieldTransformationRegistry); $expectedFacetField = new FacetField(AttributeCode::fromString($attributeCodeString), new FacetFieldValue($encodedQueryValue, $attributeValueCount)); $this->assertEquals([$expectedFacetField], $response->getNonSelectedFacetFields($selectedFilterAttributeCodes)); }
public function testFacetFieldTransformationIsAppliedToFacetField() { $testRangedAttributeCode = 'foo'; $testNormalAttributeCode = 'bar'; $this->stubFacetFiltersToIncludeInResult->method('getFields')->willReturn([$this->createStubFacetFilterRequestField($testRangedAttributeCode), $this->createStubFacetFilterRequestField($testNormalAttributeCode)]); $testFilterSelection = [$testRangedAttributeCode => ['Value does not matter as it will be transformed.'], $testNormalAttributeCode => ['Does not matter either.']]; $rangeFrom = 'baz'; $rangeTo = 'qux'; $stubFacetFilterRange = $this->createMock(FacetFilterRange::class); $stubFacetFilterRange->method('from')->willReturn($rangeFrom); $stubFacetFilterRange->method('to')->willReturn($rangeTo); $stubRangedTransformation = $this->createMock(FacetFieldTransformation::class); $stubRangedTransformation->method('decode')->willReturn($stubFacetFilterRange); $transformedValue = 'Transformed value'; $stubNormalTransformation = $this->createMock(FacetFieldTransformation::class); $stubNormalTransformation->method('decode')->willReturn($transformedValue); $this->stubFacetFieldTransformationRegistry->method('hasTransformationForCode')->willReturn(true); $this->stubFacetFieldTransformationRegistry->method('getTransformationByCode')->willReturnMap([[$testRangedAttributeCode, $stubRangedTransformation], [$testNormalAttributeCode, $stubNormalTransformation]]); $solrFacetFilterRequest = new SolrFacetFilterRequest($this->stubFacetFiltersToIncludeInResult, $testFilterSelection, $this->stubFacetFieldTransformationRegistry); $expectedArray = ['facet' => 'on', 'facet.mincount' => 1, 'facet.limit' => -1, 'facet.sort' => 'index', 'facet.field' => [$testRangedAttributeCode, $testNormalAttributeCode], 'facet.query' => [], 'fq' => [sprintf('%s:([%s TO %s])', $testRangedAttributeCode, $rangeFrom, $rangeTo), sprintf('%s:("%s")', $testNormalAttributeCode, $transformedValue)]]; $this->assertSame($expectedArray, $solrFacetFilterRequest->toArray()); }