ShowOnlyDeepestLevelItemsProcessorTest.php in Facets 8
File
tests/src/Unit/Plugin/processor/ShowOnlyDeepestLevelItemsProcessorTest.php
View source
<?php
namespace Drupal\Tests\facets\Unit\Plugin\processor;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Plugin\facets\processor\ShowOnlyDeepestLevelItemsProcessor;
use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
class ShowOnlyDeepestLevelItemsProcessorTest extends UnitTestCase {
protected $processor;
public function setUp() {
parent::setUp();
$this->processor = new ShowOnlyDeepestLevelItemsProcessor([], 'test', []);
}
public function testRemoveItemsWithoutChildren() {
$facet = new Facet([
'id' => 'llama',
], 'facets_facet');
$results = [
new Result($facet, 'a', 'A', 5),
new Result($facet, 'b', 'B', 2),
new Result($facet, 'c', 'C', 4),
];
$child = new Result($facet, 'a_1', 'A 1', 3);
$results[0]
->setChildren([
$child,
]);
$built_results = $this->processor
->build($facet, $results);
sort($built_results);
$this
->assertCount(2, $built_results);
$this
->assertSame('b', $built_results[0]
->getRawValue());
$this
->assertSame('c', $built_results[1]
->getRawValue());
}
}