View source
<?php
namespace Drupal\Tests\facets\Unit\Plugin\processor;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Plugin\facets\processor\BooleanItemProcessor;
use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
class BooleanItemProcessorTest extends UnitTestCase {
protected $processor;
protected $originalResults;
protected function setUp() {
parent::setUp();
$facet = new Facet([], 'facets_facet');
$this->originalResults = [
new Result($facet, 0, 0, 10),
new Result($facet, 1, 1, 15),
];
$this->processor = new BooleanItemProcessor([], 'boolean_item_processor', []);
}
public function testBuild() {
$facet = new Facet([], 'facets_facet');
$facet
->setResults($this->originalResults);
$filtered_results = $this->processor
->build($facet, $this->originalResults);
$this
->assertEquals('Off', $filtered_results[0]
->getDisplayValue());
$this
->assertEquals('On', $filtered_results[1]
->getDisplayValue());
$configuration = [
'on_value' => 'True',
'off_value' => 'False',
];
$this->processor
->setConfiguration($configuration);
$filtered_results = $this->processor
->build($facet, $this->originalResults);
$this
->assertEquals('False', $filtered_results[0]
->getDisplayValue());
$this
->assertEquals('True', $filtered_results[1]
->getDisplayValue());
}
public function testConfiguration() {
$config = $this->processor
->defaultConfiguration();
$this
->assertEquals([
'on_value' => 'On',
'off_value' => 'Off',
], $config);
}
public function testDescription() {
$this
->assertEquals('', $this->processor
->getDescription());
}
public function testIsHidden() {
$this
->assertEquals(FALSE, $this->processor
->isHidden());
}
public function testIsLocked() {
$this
->assertEquals(FALSE, $this->processor
->isLocked());
}
}