Skip to content

Commit

Permalink
[TEST] Handle float values in options facet parser
Browse files Browse the repository at this point in the history
Adds tests for #3722

Relates: #3722
  • Loading branch information
dkd-kaehm committed Oct 13, 2023
1 parent 61d1a92 commit cb5cdb7
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

namespace ApacheSolrForTypo3\Solr\Tests\Unit\Domain\Search\ResultSet\Facets\OptionBased\Options;

use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\Options\OptionsFacetParser;
use ApacheSolrForTypo3\Solr\System\Solr\ResponseAdapter;
use ApacheSolrForTypo3\Solr\Tests\Unit\SetUpUnitTestCase;

class OptionsFacetParserTest extends SetUpUnitTestCase
{
/**
* @test
*/
public function canListFloatValuesAsOptionsFromSolrResponse(): void
{
$responseAdapter = new ResponseAdapter(
/* @lang JSON */
'{
"facets": {
"floatOptions": {
"buckets": [
{ "val": 0.001, "count": 1 },
{ "val": 0.002, "count": 2 },
{ "val": 0.003, "count": 3 }
]
}
}
}'
);
$optionsFacetParser = $this->getAccessibleMock(
OptionsFacetParser::class,
null,
[],
'',
false
);
/** @link OptionsFacetParser::getOptionsFromSolrResponse */
$optionsArray = $optionsFacetParser->_call(
'getOptionsFromSolrResponse',
'floatOptions',
$responseAdapter,
);
self::assertCount(3, $optionsArray, 'EXT:solr can not list floats in facets.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ public function getType()
self::assertEquals('options', $myFacet->getType());
}

/**
* @return array
*/
public function getIncludeInAvailableFacetsDataProvider()
public function getIncludeInAvailableFacetsDataProvider(): array
{
return [
'default' => [null, true],
Expand All @@ -112,15 +109,23 @@ public function getIncludeInAvailableFacetsDataProvider()
}

/**
* @param mixed $includeInAvailableFacetsConfiguration
* @param mixed $expectedResult
* @dataProvider getIncludeInAvailableFacetsDataProvider
* @test
*/
public function getIncludeInAvailableFacets($includeInAvailableFacetsConfiguration, $expectedResult)
{
public function getIncludeInAvailableFacetsCastsSettingsToBoolProperly(
null|int|string $includeInAvailableFacetsConfiguration,
bool $expectedResult,
): void {
$resultSetMock = $this->createMock(SearchResultSet::class);
$myFacet = new OptionsFacet($resultSetMock, 'myFacet', 'myFacetFieldName', 'myTitle', ['includeInAvailableFacets' => $includeInAvailableFacetsConfiguration]);
$myFacet = new OptionsFacet(
$resultSetMock,
'myFacet',
'myFacetFieldName',
'myTitle',
[
'includeInAvailableFacets' => $includeInAvailableFacetsConfiguration,
],
);

self::assertSame($myFacet->getIncludeInAvailableFacets(), $expectedResult, 'Method getIncludeInAvailableFacets returns unexpected result');
}
Expand Down

0 comments on commit cb5cdb7

Please sign in to comment.