class DependentFacetProcessorTest 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\DependentFacetProcessorTest
Expanded class hierarchy of DependentFacetProcessorTest
File
- tests/
src/ Unit/ Plugin/ processor/ DependentFacetProcessorTest.php, line 18
Namespace
Drupal\Tests\facets\Unit\Plugin\processorView source
class DependentFacetProcessorTest extends UnitTestCase {
/**
* An array of results.
*
* @var \Drupal\facets\Result\ResultInterface[]
*/
protected $results;
/**
* {@inheritdoc}
*/
public function setUp() {
$facet = new Facet([], 'facets_facet');
$this->results = [
new Result($facet, 'snow_owl', 'Snow owl', 2),
new Result($facet, 'forest_owl', 'Forest owl', 3),
new Result($facet, 'sand_owl', 'Sand owl', 8),
new Result($facet, 'church_owl', 'Church owl', 1),
new Result($facet, 'barn_owl', 'Barn owl', 1),
];
}
/**
* Tests to no-config case.
*/
public function testNotConfigured() {
$facetManager = $this
->prophesize(DefaultFacetManager::class)
->reveal();
$etm = $this
->prophesize(EntityTypeManagerInterface::class)
->reveal();
$dfp = new DependentFacetProcessor([], 'dependent_facet_processor', [], $facetManager, $etm);
$facet = new Facet([
'id' => 'owl',
'name' => 'øwl',
], 'facets_facet');
$computed = $dfp
->build($facet, $this->results);
$this
->assertEquals($computed, $this->results);
}
/**
* Tests the case where no facets are enabled.
*/
public function testNoEnabledFacets() {
$facetManager = $this
->prophesize(DefaultFacetManager::class)
->reveal();
$etm = $this
->prophesize(EntityTypeManagerInterface::class)
->reveal();
$configuration = [
'owl' => [
'enable' => FALSE,
'condition' => 'not_empty',
],
];
$dfp = new DependentFacetProcessor($configuration, 'dependent_facet_processor', [], $facetManager, $etm);
$facet = new Facet([
'id' => 'owl',
'name' => 'øwl',
], 'facets_facet');
$computed = $dfp
->build($facet, $this->results);
$this
->assertEquals($computed, $this->results);
}
/**
* Tests that facet is not empty.
*
* @dataProvider provideNegated
*/
public function testNotEmpty($negated) {
$facet = new Facet([
'id' => 'owl',
'name' => 'øwl',
], 'facets_facet');
$facet
->setActiveItem('snow_owl');
$facetManager = $this
->prophesize(DefaultFacetManager::class);
$facetManager
->returnProcessedFacet($facet)
->willReturn($facet);
$entityStorage = $this
->prophesize(EntityStorageInterface::class);
$entityStorage
->load('owl')
->willReturn($facet);
$etm = $this
->prophesize(EntityTypeManagerInterface::class);
$etm
->getStorage('facets_facet')
->willReturn($entityStorage
->reveal());
$configuration = [
'owl' => [
'enable' => TRUE,
'negate' => $negated,
'condition' => 'not_empty',
],
];
$dfp = new DependentFacetProcessor($configuration, 'dependent_facet_processor', [], $facetManager
->reveal(), $etm
->reveal());
$computed = $dfp
->build($facet, $this->results);
if ($negated) {
$this
->assertEquals($computed, []);
}
else {
$this
->assertEquals($computed, $this->results);
}
}
/**
* Provides test cases with data.
*
* @return array
* An array of test data.
*/
public function provideNegated() {
return [
'negated' => [
TRUE,
],
'normal' => [
FALSE,
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependentFacetProcessorTest:: |
protected | property | An array of results. | |
DependentFacetProcessorTest:: |
public | function | Provides test cases with data. | |
DependentFacetProcessorTest:: |
public | function |
Overrides UnitTestCase:: |
|
DependentFacetProcessorTest:: |
public | function | Tests the case where no facets are enabled. | |
DependentFacetProcessorTest:: |
public | function | Tests to no-config case. | |
DependentFacetProcessorTest:: |
public | function | Tests that facet is not empty. | |
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. |