HideWhenNotRenderedProcessorTest.php in Facets 8
File
modules/facets_summary/tests/src/Unit/Plugin/Processor/HideWhenNotRenderedProcessorTest.php
View source
<?php
namespace Drupal\Tests\facets_summary\Unit\Plugin\Processor;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\facets\FacetSource\FacetSourcePluginInterface;
use Drupal\facets\FacetSource\FacetSourcePluginManager;
use Drupal\facets_summary\Entity\FacetsSummary;
use Drupal\facets_summary\Plugin\facets_summary\processor\HideWhenNotRenderedProcessor;
use Drupal\Tests\UnitTestCase;
class HideWhenNotRenderedProcessorTest extends UnitTestCase {
protected $processor;
public function setUp() {
parent::setUp();
$this->processor = new HideWhenNotRenderedProcessor([], 'hide_when_not_rendered', []);
}
public function testIsHidden() {
$this
->assertFalse($this->processor
->isHidden());
}
public function testIsLocked() {
$this
->assertFalse($this->processor
->isLocked());
}
public function testBuild() {
$this
->createContainer(TRUE);
$summary = new FacetsSummary([], 'facets_summary');
$summary
->setFacetSourceId('foo');
$result = $this->processor
->build($summary, [
'foo',
], []);
$this
->assertEquals([
'foo',
], $result);
}
public function testBuildWithNoCurrentRequest() {
$this
->createContainer(FALSE);
$summary = new FacetsSummary([], 'facets_summary');
$summary
->setFacetSourceId('foo');
$result = $this->processor
->build($summary, [
'foo',
], []);
$this
->assertEquals([], $result);
}
protected function createContainer($renderedInCurrentRequestValue) {
$fsi = $this
->getMockBuilder(FacetSourcePluginInterface::class)
->disableOriginalConstructor()
->getMock();
$fsi
->method('isRenderedInCurrentRequest')
->willReturn($renderedInCurrentRequestValue);
$facetSourceManager = $this
->getMockBuilder(FacetSourcePluginManager::class)
->disableOriginalConstructor()
->getMock();
$facetSourceManager
->method('createInstance')
->willReturn($fsi);
$container = new ContainerBuilder();
$container
->set('plugin.manager.facets.facet_source', $facetSourceManager);
\Drupal::setContainer($container);
}
}