diff --git a/src/Annotation/FacetsUrlProcessor.php b/src/Annotation/FacetsUrlProcessor.php index 1075384..8547812 100644 --- a/src/Annotation/FacetsUrlProcessor.php +++ b/src/Annotation/FacetsUrlProcessor.php @@ -1,7 +1,7 @@ setExpectedException('\Drupal\facets\Exception\InvalidProcessorException', "The UrlProcessorHandler doesn't have the required 'facet' in the configuration array."); + new UrlProcessorHandler([], 'test', []); + } + + /** + * Tests that the processor correctly throws an exception. + */ + public function testInvalidProcessorConfiguration() { + $this->setExpectedException('\Drupal\facets\Exception\InvalidProcessorException', "The UrlProcessorHandler doesn't have the required 'facet' in the configuration array."); + new UrlProcessorHandler(['facet' => new \stdClass()], 'test', []); + } + + /** + * Test that the build method is correctly called. + */ + public function testBuild() { + $facet = new Facet(['id' => '_test'], 'facets_facet'); + $this->createContainer(); + + $processor = new UrlProcessorHandler(['facet' => $facet], 'url_processor_handler', []); + // The actual results of this should be tested in the actual processor. + $processor->build($facet, []); + } + + /** + * Helper function to create a correct container. + */ + protected function createContainer() { + $url_processor = $this->getMockBuilder('\Drupal\facets\UrlProcessor\UrlProcessorInterface') + ->disableOriginalConstructor() + ->getMock(); + + $manager = $this->getMockBuilder('\Drupal\facets\FacetSource\FacetSourcePluginManager') + ->disableOriginalConstructor() + ->getMock(); + $manager->expects($this->exactly(1)) + ->method('createInstance') + ->willReturn($url_processor); + + $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface'); + $em = $this->getMockBuilder('\Drupal\Core\Entity\EntityTypeManagerInterface') + ->disableOriginalConstructor() + ->getMock(); + $em->expects($this->exactly(2)) + ->method('getStorage') + ->willReturn($storage); + + $container = new ContainerBuilder(); + $container->set('entity.manager', $em); + $container->set('entity_type.manager', $em); + $container->set('plugin.manager.facets.url_processor', $manager); + \Drupal::setContainer($container); + } + +} diff --git a/tests/src/Unit/Plugin/url_processor/QueryStringUrlProcessorTest.php b/tests/src/Unit/Plugin/url_processor/QueryStringTest.php similarity index 100% rename from tests/src/Unit/Plugin/url_processor/QueryStringUrlProcessorTest.php rename to tests/src/Unit/Plugin/url_processor/QueryStringTest.php