View source
<?php
namespace Drupal\Tests\facets\Unit\Plugin\processor;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Exception\InvalidProcessorException;
use Drupal\facets\FacetSource\FacetSourcePluginManager;
use Drupal\facets\Plugin\facets\processor\UrlProcessorHandler;
use Drupal\facets\UrlProcessor\UrlProcessorInterface;
use Drupal\Tests\UnitTestCase;
class UrlProcessorHandlerTest extends UnitTestCase {
public function testEmptyProcessorConfiguration() {
$this
->expectException(InvalidProcessorException::class);
$this
->expectExceptionMessage("The UrlProcessorHandler doesn't have the required 'facet' in the configuration array.");
new UrlProcessorHandler([], 'test', []);
}
public function testInvalidProcessorConfiguration() {
$this
->expectException(InvalidProcessorException::class);
$this
->expectExceptionMessage("The UrlProcessorHandler doesn't have the required 'facet' in the configuration array.");
new UrlProcessorHandler([
'facet' => new \stdClass(),
], 'test', []);
}
public function testBuild() {
$facet = new Facet([
'id' => '_test',
], 'facets_facet');
$this
->createContainer();
$processor = new UrlProcessorHandler([
'facet' => $facet,
], 'url_processor_handler', []);
$processor
->build($facet, []);
}
public function testConfiguration() {
$facet = new Facet([], 'facets_facet');
$this
->createContainer();
$processor = new UrlProcessorHandler([
'facet' => $facet,
], 'url_processor_handler', []);
$config = $processor
->defaultConfiguration();
$this
->assertEquals([], $config);
}
public function testDescription() {
$facet = new Facet([], 'facets_facet');
$this
->createContainer();
$processor = new UrlProcessorHandler([
'facet' => $facet,
], 'url_processor_handler', []);
$this
->assertEquals('', $processor
->getDescription());
}
public function testIsHidden() {
$facet = new Facet([], 'facets_facet');
$this
->createContainer();
$processor = new UrlProcessorHandler([
'facet' => $facet,
], 'url_processor_handler', []);
$this
->assertEquals(FALSE, $processor
->isHidden());
}
public function testIsLocked() {
$facet = new Facet([], 'facets_facet');
$this
->createContainer();
$processor = new UrlProcessorHandler([
'facet' => $facet,
], 'url_processor_handler', []);
$this
->assertEquals(FALSE, $processor
->isLocked());
}
protected function createContainer() {
$url_processor = $this
->getMockBuilder(UrlProcessorInterface::class)
->disableOriginalConstructor()
->getMock();
$manager = $this
->getMockBuilder(FacetSourcePluginManager::class)
->disableOriginalConstructor()
->getMock();
$manager
->expects($this
->exactly(1))
->method('createInstance')
->willReturn($url_processor);
$storage = $this
->createMock(EntityStorageInterface::class);
$em = $this
->getMockBuilder(EntityTypeManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$em
->expects($this
->exactly(1))
->method('getStorage')
->willReturn($storage);
$container = new ContainerBuilder();
$container
->set('entity_type.manager', $em);
$container
->set('plugin.manager.facets.url_processor', $manager);
\Drupal::setContainer($container);
}
}