Commit f3d9a934 authored by mr.baileys's avatar mr.baileys

#2599332: Additional testing and validation for count limit maximum values.

parent 43a74cfd
......@@ -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);
}
......
......@@ -137,6 +137,34 @@ class CountLimitProcessorTest extends UnitTestCase {
$this->assertCount(2, $sorted_results);
}
/**
* 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.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment