Skip to content

Commit

Permalink
[TASK:T12] Fix tests for *\Facets\* namespace
Browse files Browse the repository at this point in the history
This change fixes tests for *\Facets\* namespace
and changes to new style constructor.

Relates: #3376
  • Loading branch information
dkd-kaehm committed May 15, 2023
1 parent f456e0f commit f22028d
Show file tree
Hide file tree
Showing 19 changed files with 141 additions and 319 deletions.
52 changes: 10 additions & 42 deletions Classes/Domain/Search/ResultSet/Facets/AbstractFacet.php
Expand Up @@ -33,33 +33,6 @@ abstract class AbstractFacet
*/
protected static string $type = self::TYPE_ABSTRACT;

/**
* The resultSet where this facet belongs to.
*
* @var SearchResultSet
*/
protected SearchResultSet $resultSet;

/**
* @var string
*/
protected string $name;

/**
* @var string
*/
protected string $field;

/**
* @var string
*/
protected string $label;

/**
* @var array
*/
protected array $configuration;

/**
* @var bool
*/
Expand All @@ -85,17 +58,12 @@ abstract class AbstractFacet
* @param array $configuration Facet configuration passed from typoscript
*/
public function __construct(
SearchResultSet $resultSet,
string $name,
string $field,
string $label = '',
array $configuration = []
protected SearchResultSet $resultSet,
protected string $name,
protected string $field,
protected string $label = '',
protected array $configuration = []
) {
$this->resultSet = $resultSet;
$this->name = $name;
$this->field = $field;
$this->label = $label;
$this->configuration = $configuration;
}

/**
Expand All @@ -121,7 +89,7 @@ public function getField(): string
/**
* @param string $label
*/
public function setLabel(string $label)
public function setLabel(string $label): void
{
$this->label = $label;
}
Expand All @@ -137,7 +105,7 @@ public function getLabel(): string
/**
* @param bool $isAvailable
*/
public function setIsAvailable(bool $isAvailable)
public function setIsAvailable(bool $isAvailable): void
{
$this->isAvailable = $isAvailable;
}
Expand All @@ -153,7 +121,7 @@ public function getIsAvailable(): bool
/**
* @param bool $isUsed
*/
public function setIsUsed(bool $isUsed)
public function setIsUsed(bool $isUsed): void
{
$this->isUsed = $isUsed;
}
Expand Down Expand Up @@ -185,7 +153,7 @@ public function getAllRequirementsMet(): bool
/**
* @param bool $allRequirementsMet
*/
public function setAllRequirementsMet(bool $allRequirementsMet)
public function setAllRequirementsMet(bool $allRequirementsMet): void
{
$this->allRequirementsMet = $allRequirementsMet;
}
Expand Down Expand Up @@ -270,7 +238,7 @@ abstract public function getAllFacetItems(): AbstractFacetItemCollection;
* @param mixed $defaultValue
* @return mixed
*/
protected function getFacetSettingOrDefaultValue(string $key, $defaultValue)
protected function getFacetSettingOrDefaultValue(string $key, mixed $defaultValue): mixed
{
if (!isset($this->configuration[$key])) {
return $defaultValue;
Expand Down
42 changes: 6 additions & 36 deletions Classes/Domain/Search/ResultSet/Facets/AbstractFacetItem.php
Expand Up @@ -25,50 +25,20 @@
*/
abstract class AbstractFacetItem
{
/**
* @var string
*/
protected string $label = '';

/**
* @var int
*/
protected int $documentCount = 0;

/**
* @var bool
*/
protected bool $selected = false;

/**
* @var array
*/
protected array $metrics = [];

/**
* @var AbstractFacet
*/
protected AbstractFacet $facet;

/**
* @param AbstractFacet $facet
* @param string $label
* @param int $documentCount
* @param bool $selected
* @param array|null $metrics
* @param array $metrics
*/
public function __construct(
AbstractFacet $facet,
string $label = '',
int $documentCount = 0,
bool $selected = false,
array $metrics = []
protected AbstractFacet $facet,
protected string $label = '',
protected int $documentCount = 0,
protected bool $selected = false,
protected array $metrics = []
) {
$this->facet = $facet;
$this->label = $label;
$this->documentCount = $documentCount;
$this->selected = $selected;
$this->metrics = $metrics;
}

/**
Expand Down
Expand Up @@ -50,7 +50,13 @@ public function __construct(
array $metrics = []
) {
$this->value = $value;
parent::__construct($facet, $label, $documentCount, $selected, $metrics);
parent::__construct(
$facet,
$label,
$documentCount,
$selected,
$metrics,
);
}

/**
Expand Down
Expand Up @@ -29,11 +29,6 @@
*/
class AbstractOptionsFacet extends AbstractFacet
{
/**
* @var OptionCollection
*/
protected OptionCollection $options;

/**
* OptionsFacet constructor
*
Expand All @@ -42,16 +37,17 @@ class AbstractOptionsFacet extends AbstractFacet
* @param string $field
* @param string $label
* @param array $configuration Facet configuration passed from typoscript
* @param OptionCollection $options
*/
public function __construct(
SearchResultSet $resultSet,
string $name,
string $field,
string $label = '',
array $configuration = []
array $configuration = [],
protected OptionCollection $options = new OptionCollection(),
) {
parent::__construct($resultSet, $name, $field, $label, $configuration);
$this->options = new OptionCollection();
}

/**
Expand Down
Expand Up @@ -36,16 +36,6 @@ class HierarchyFacet extends AbstractFacet
*/
protected static string $type = self::TYPE_HIERARCHY;

/**
* @var NodeCollection
*/
protected NodeCollection $childNodes;

/**
* @var NodeCollection
*/
protected NodeCollection $allNodes;

/**
* @var array
*/
Expand All @@ -59,17 +49,19 @@ class HierarchyFacet extends AbstractFacet
* @param string $field
* @param string $label
* @param array $configuration Facet configuration passed from typoscript
* @param NodeCollection $childNodes
* @param NodeCollection $allNodes
*/
public function __construct(
SearchResultSet $resultSet,
string $name,
string $field,
string $label = '',
array $configuration = []
array $configuration = [],
protected NodeCollection $childNodes = new NodeCollection(),
protected NodeCollection $allNodes = new NodeCollection(),
) {
parent::__construct($resultSet, $name, $field, $label, $configuration);
$this->childNodes = new NodeCollection();
$this->allNodes = new NodeCollection();
}

/**
Expand Down
Expand Up @@ -100,13 +100,13 @@ protected function sortFacetOptionsInNaturalOrder(array $flatOptionsListForHiera
/**
* Checks if options must be resorted.
*
* Apache Solr facet.sort can be set globally or per facet.
* Apache Solr `facet.sort` can be set globally or per facet.
* Relevant TypoScript paths:
* plugin.tx_solr.search.faceting.sortBy causes facet.sort Apache Solr parameter
* plugin.tx_solr.search.faceting.sortBy causes `facet.sort` Apache Solr parameter
* plugin.tx_solr.search.faceting.facets.[facetName].sortBy causes f.<fieldname>.facet.sort parameter
*
* see: https://lucene.apache.org/solr/guide/6_6/faceting.html#Faceting-Thefacet.sortParameter
* see: https://wiki.apache.org/solr/SimpleFacetParameters#facet.sort : "This parameter can be specified on a per field basis."
* see: https://solr.apache.org/guide/6_6/faceting.html#Faceting-Thefacet.sortParameter : "This parameter can be specified on a per-field basis with the syntax of f.<fieldname>.facet.sort."
*
* @param array $facetConfiguration
* @return bool
Expand Down Expand Up @@ -148,7 +148,7 @@ protected function getActiveFacetValuesFromRequest(SearchResultSet $resultSet, s
$activeFacetValues = [];
$values = $resultSet->getUsedSearchRequest()->getActiveFacetValuesByName($facetName);

foreach (is_array($values) ? $values : [] as $valueFromRequest) {
foreach ($values as $valueFromRequest) {
// Attach the 'depth' param again to the value
if (!str_contains($valueFromRequest, '-')) {
$valueFromRequest = HierarchyTool::substituteSlashes($valueFromRequest);
Expand Down
Expand Up @@ -18,55 +18,51 @@
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\AbstractOptionFacetItem;

/**
* Value object that represent an option of a options facet.
* Value object that represent an option of an options-facet.
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class Node extends AbstractOptionFacetItem
{
/**
* @var NodeCollection
*/
protected $childNodes;

/**
* @var Node
*/
protected $parentNode;

/**
* @var int
*/
protected $depth;

/**
* @var string
*/
protected $key;
protected int $depth;

/**
* @param HierarchyFacet $facet
* @param Node $parentNode
* @param Node|null $parentNode
* @param string $key
* @param string $label
* @param string $value
* @param int $documentCount
* @param bool $selected
* @param NodeCollection $childNodes
*/
public function __construct(HierarchyFacet $facet, $parentNode = null, $key = '', $label = '', $value = '', $documentCount = 0, $selected = false)
{
parent::__construct($facet, $label, $value, $documentCount, $selected);
$this->value = $value;
$this->childNodes = new NodeCollection();
$this->parentNode = $parentNode;
$this->key = $key;
public function __construct(
HierarchyFacet $facet,
protected ?Node $parentNode = null,
protected string $key = '',
$label = '',
$value = '',
$documentCount = 0,
bool $selected = false,
protected NodeCollection $childNodes = new NodeCollection(),
) {
parent::__construct(
$facet,
$label,
$value,
$documentCount,
$selected,
);
}

/**
* @return string
*/
public function getKey()
public function getKey(): string
{
return $this->key;
}
Expand All @@ -82,31 +78,31 @@ public function addChildNode(Node $node)
/**
* @return NodeCollection
*/
public function getChildNodes()
public function getChildNodes(): NodeCollection
{
return $this->childNodes;
}

/**
* @return Node|null
*/
public function getParentNode()
public function getParentNode(): ?Node
{
return $this->parentNode;
}

/**
* @return bool
*/
public function getHasParentNode()
public function getHasParentNode(): bool
{
return $this->parentNode !== null;
}

/**
* @return bool
*/
public function getHasChildNodeSelected()
public function getHasChildNodeSelected(): bool
{
/** @var Node $childNode */
foreach ($this->childNodes as $childNode) {
Expand Down
Expand Up @@ -39,7 +39,7 @@ public function add(?AbstractFacetItem $item): AbstractFacetItemCollection

/**
* @param int $position
* @return Node
* @return ?object Node
*/
public function getByPosition(int $position): ?object
{
Expand Down

0 comments on commit f22028d

Please sign in to comment.