class HideNonNarrowingResultProcessorTest in Facets 8
Unit test for processor.
@group facets
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\facets\Unit\Plugin\processor\HideNonNarrowingResultProcessorTest
Expanded class hierarchy of HideNonNarrowingResultProcessorTest
File
- tests/
src/ Unit/ Plugin/ processor/ HideNonNarrowingResultProcessorTest.php, line 15
Namespace
Drupal\Tests\facets\Unit\Plugin\processorView source
class HideNonNarrowingResultProcessorTest extends UnitTestCase {
/**
* The processor to be tested.
*
* @var \Drupal\facets\processor\SortProcessorInterface
*/
protected $processor;
/**
* An array containing the results before the processor has ran.
*
* @var \Drupal\facets\Result\Result[]
*/
protected $originalResults;
/**
* Creates a new processor object for use in the tests.
*/
protected function setUp() {
parent::setUp();
$facet = new Facet([], 'facets_facet');
$this->originalResults = [
new Result($facet, 'llama', 'llama', 10),
new Result($facet, 'badger', 'badger', 15),
new Result($facet, 'duck', 'duck', 15),
];
$this->processor = new HideNonNarrowingResultProcessor([], 'hide_non_narrowing_result_processor', []);
}
/**
* Tests filtering of results.
*/
public function testNoFilterResults() {
$facet = new Facet([], 'facets_facet');
$facet
->setResults($this->originalResults);
$filtered_results = $this->processor
->build($facet, $this->originalResults);
$this
->assertCount(3, $filtered_results);
$this
->assertEquals(10, $filtered_results[0]
->getCount());
$this
->assertEquals('llama', $filtered_results[0]
->getDisplayValue());
$this
->assertEquals(15, $filtered_results[1]
->getCount());
$this
->assertEquals('badger', $filtered_results[1]
->getDisplayValue());
$this
->assertEquals(15, $filtered_results[2]
->getCount());
$this
->assertEquals('duck', $filtered_results[2]
->getDisplayValue());
}
/**
* Tests filtering of results.
*/
public function testFilterResults() {
$results = $this->originalResults;
$results[2]
->setActiveState(TRUE);
$facet = new Facet([], 'facets_facet');
$facet
->setResults($results);
$filtered_results = $this->processor
->build($facet, $results);
$this
->assertCount(2, $filtered_results);
// Llama is shown because it narrows results.
$this
->assertEquals(10, $filtered_results[0]
->getCount());
$this
->assertEquals('llama', $filtered_results[0]
->getDisplayValue());
// Duck is shown because it's already active.
$this
->assertEquals(15, $filtered_results[2]
->getCount());
$this
->assertEquals('duck', $filtered_results[2]
->getDisplayValue());
}
/**
* Tests configuration.
*/
public function testConfiguration() {
$config = $this->processor
->defaultConfiguration();
$this
->assertEquals([], $config);
}
/**
* Tests testDescription().
*/
public function testDescription() {
$this
->assertEquals('', $this->processor
->getDescription());
}
/**
* Tests isHidden().
*/
public function testIsHidden() {
$this
->assertEquals(FALSE, $this->processor
->isHidden());
}
/**
* Tests isLocked().
*/
public function testIsLocked() {
$this
->assertEquals(FALSE, $this->processor
->isLocked());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HideNonNarrowingResultProcessorTest:: |
protected | property | An array containing the results before the processor has ran. | |
HideNonNarrowingResultProcessorTest:: |
protected | property | The processor to be tested. | |
HideNonNarrowingResultProcessorTest:: |
protected | function |
Creates a new processor object for use in the tests. Overrides UnitTestCase:: |
|
HideNonNarrowingResultProcessorTest:: |
public | function | Tests configuration. | |
HideNonNarrowingResultProcessorTest:: |
public | function | Tests testDescription(). | |
HideNonNarrowingResultProcessorTest:: |
public | function | Tests filtering of results. | |
HideNonNarrowingResultProcessorTest:: |
public | function | Tests isHidden(). | |
HideNonNarrowingResultProcessorTest:: |
public | function | Tests isLocked(). | |
HideNonNarrowingResultProcessorTest:: |
public | function | Tests filtering of results. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |