summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormr.baileys2015-12-05 15:16:20 (GMT)
committermr.baileys2015-12-05 15:16:20 (GMT)
commitf3d9a9342cb457829e5019e43d59ffbd2cc89c49 (patch)
tree1320585862ed55b9acaaa04cb65c05b8ae63f593
parent43a74cfd5e720aec04ea366e6ca804e0368e03f7 (diff)
#2599332: Additional testing and validation for count limit maximum values.
-rw-r--r--src/Plugin/facets/processor/CountLimitProcessor.php6
-rw-r--r--tests/src/Unit/Plugin/processor/CountLimitProcessorTest.php28
2 files changed, 33 insertions, 1 deletions
diff --git a/src/Plugin/facets/processor/CountLimitProcessor.php b/src/Plugin/facets/processor/CountLimitProcessor.php
index 4b72a5e..30c2c1e 100644
--- a/src/Plugin/facets/processor/CountLimitProcessor.php
+++ b/src/Plugin/facets/processor/CountLimitProcessor.php
@@ -76,7 +76,11 @@ class CountLimitProcessor extends ProcessorPluginBase implements BuildProcessorI
* {@inheritdoc}
*/
public function validateConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) {
- return parent::validateConfigurationForm($form, $form_state, $facet); // TODO: Change the autogenerated stub
+ $values = $form_state->getValues();
+ if (!empty($values['maximum_items']) && !empty($values['minimum_items']) && $values['maximum_items'] <= $values['minimum_items']) {
+ $form_state->setErrorByName('maximum_items', t('If both minimum and maximum item count are specified, the maximum item count should be higher than the minimum item count.'));
+ }
+ return parent::validateConfigurationForm($form, $form_state, $facet);
}
diff --git a/tests/src/Unit/Plugin/processor/CountLimitProcessorTest.php b/tests/src/Unit/Plugin/processor/CountLimitProcessorTest.php
index 30c4c6d..baf5c1d 100644
--- a/tests/src/Unit/Plugin/processor/CountLimitProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/CountLimitProcessorTest.php
@@ -138,6 +138,34 @@ class CountLimitProcessorTest extends UnitTestCase {
}
/**
+ * Test maximum values.
+ */
+ public function testMaxValue() {
+ $facet = new Facet([], 'facet');
+ $facet->setResults($this->original_results);
+ $facet->setOption('processors', [
+ 'count_limit' => [],
+ ]);
+
+ $this->processor->setConfiguration(['maximum_items' => 14]);
+ $sorted_results = $this->processor->build($facet, $this->original_results);
+ $this->assertCount(2, $sorted_results);
+ $this->assertEquals('llama', $sorted_results[0]->getDisplayValue());
+ $this->assertEquals('badger', $sorted_results[1]->getDisplayValue());
+
+ $this->processor->setConfiguration(['maximum_items' => 140]);
+ $sorted_results = $this->processor->build($facet, $this->original_results);
+ $this->assertCount(3, $sorted_results);
+ $this->assertEquals('llama', $sorted_results[0]->getDisplayValue());
+ $this->assertEquals('badger', $sorted_results[1]->getDisplayValue());
+ $this->assertEquals('duck', $sorted_results[2]->getDisplayValue());
+
+ $this->processor->setConfiguration(['maximum_items' => 1]);
+ $sorted_results = $this->processor->build($facet, $this->original_results);
+ $this->assertCount(0, $sorted_results);
+ }
+
+ /**
* Test filtering of results.
*/
public function testFilterResults() {