summaryrefslogtreecommitdiffstats
path: root/tests/src/Unit/Plugin
diff options
context:
space:
mode:
authorborisson_2015-12-25 21:44:41 (GMT)
committerJoris Vercammen2015-12-25 21:44:41 (GMT)
commit3704ea070bb40d90d46c171e9287e2414183211d (patch)
tree2dfb8ebadb48661bdc6863046b379850e09ce50e /tests/src/Unit/Plugin
parent436f55bc3d8284d841395fed161cc07d7f7bba60 (diff)
Issue #2637594 by borisson_, StryKaizer: Make it easier to switch the url processor
Diffstat (limited to 'tests/src/Unit/Plugin')
-rw-r--r--tests/src/Unit/Plugin/processor/UrlProcessorHandlerTest.php80
-rw-r--r--tests/src/Unit/Plugin/url_processor/QueryStringTest.php (renamed from tests/src/Unit/Plugin/processor/QueryStringUrlProcessorTest.php)42
2 files changed, 105 insertions, 17 deletions
diff --git a/tests/src/Unit/Plugin/processor/UrlProcessorHandlerTest.php b/tests/src/Unit/Plugin/processor/UrlProcessorHandlerTest.php
new file mode 100644
index 0000000..c411be8
--- /dev/null
+++ b/tests/src/Unit/Plugin/processor/UrlProcessorHandlerTest.php
@@ -0,0 +1,80 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\facets\Plugin\url_processor\QueryStringTest.
+ */
+
+namespace Drupal\Tests\facets\Unit\Plugin\processor;
+
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\facets\Entity\Facet;
+use Drupal\facets\Plugin\facets\processor\UrlProcessorHandler;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * Unit test for processor.
+ *
+ * @group facets
+ */
+class UrlProcessorHandlerTest extends UnitTestCase {
+
+ /**
+ * Tests that the processor correctly throws an exception.
+ */
+ public function testEmptyProcessorConfiguration() {
+ $this->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/processor/QueryStringUrlProcessorTest.php b/tests/src/Unit/Plugin/url_processor/QueryStringTest.php
index 1b4c58f..df418fb 100644
--- a/tests/src/Unit/Plugin/processor/QueryStringUrlProcessorTest.php
+++ b/tests/src/Unit/Plugin/url_processor/QueryStringTest.php
@@ -2,14 +2,14 @@
/**
* @file
- * Contains \Drupal\Tests\facets\Plugin\Processor\QueryStringUrlProcessorTest.
+ * Contains \Drupal\Tests\facets\Plugin\url_processor\QueryStringTest.
*/
-namespace Drupal\Tests\facets\Unit\Plugin\Processor;
+namespace Drupal\Tests\facets\Unit\Plugin\url_processor;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Entity\FacetSource;
-use Drupal\facets\Plugin\facets\processor\QueryStringUrlProcessor;
+use Drupal\facets\Plugin\facets\url_processor\QueryString;
use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -21,12 +21,12 @@ use Symfony\Component\HttpFoundation\Request;
*
* @group facets
*/
-class QueryStringUrlProcessorTest extends UnitTestCase {
+class QueryStringTest extends UnitTestCase {
/**
* The processor to be tested.
*
- * @var \Drupal\facets\Plugin\facets\processor\QueryStringUrlProcessor
+ * @var \Drupal\facets\Plugin\facets\url_processor\QueryString
*/
protected $processor;
@@ -55,6 +55,14 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
}
/**
+ * Tests that the processor correctly throws an exception.
+ */
+ public function testEmptyProcessorConfiguration() {
+ $this->setExpectedException('\Drupal\facets\Exception\InvalidProcessorException', "The url processor doesn't have the required 'facet' in the configuration array.");
+ new QueryString([], 'test', [], new Request());
+ }
+
+ /**
* Basic test with one active item.
*/
public function testSetSingleActiveItem() {
@@ -66,8 +74,8 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
$request = new Request();
$request->query->set('f', ['test:badger']);
- $this->processor = new QueryStringUrlProcessor(['facet' => $facet], 'query_string', [], $request);
- $this->processor->preQuery($facet);
+ $this->processor = new QueryString(['facet' => $facet], 'query_string', [], $request);
+ $this->processor->setActiveItems($facet);
$this->assertEquals(['badger'], $facet->getActiveItems());
}
@@ -84,8 +92,8 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
$request = new Request();
$request->query->set('f', ['test:badger', 'test:mushroom', 'donkey:kong']);
- $this->processor = new QueryStringUrlProcessor(['facet' => $facet], 'query_string', [], $request);
- $this->processor->preQuery($facet);
+ $this->processor = new QueryString(['facet' => $facet], 'query_string', [], $request);
+ $this->processor->setActiveItems($facet);
$this->assertEquals(['badger', 'mushroom'], $facet->getActiveItems());
}
@@ -101,8 +109,8 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
$request = new Request();
$request->query->set('f', []);
- $this->processor = new QueryStringUrlProcessor(['facet' => $facet], 'query_string', [], $request);
- $results = $this->processor->build($facet, []);
+ $this->processor = new QueryString(['facet' => $facet], 'query_string', [], $request);
+ $results = $this->processor->buildUrls($facet, []);
$this->assertEmpty($results);
}
@@ -118,8 +126,8 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
$request = new Request();
$request->query->set('f', []);
- $this->processor = new QueryStringUrlProcessor(['facet' => $facet], 'query_string', [], $request);
- $results = $this->processor->build($facet, $this->originalResults);
+ $this->processor = new QueryString(['facet' => $facet], 'query_string', [], $request);
+ $results = $this->processor->buildUrls($facet, $this->originalResults);
/** @var \Drupal\facets\Result\ResultInterface $r */
foreach ($results as $r) {
@@ -143,8 +151,8 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
$request = new Request();
$request->query->set('f', ['king:kong']);
- $this->processor = new QueryStringUrlProcessor(['facet' => $facet], 'query_string', [], $request);
- $results = $this->processor->build($facet, $original_results);
+ $this->processor = new QueryString(['facet' => $facet], 'query_string', [], $request);
+ $results = $this->processor->buildUrls($facet, $original_results);
/** @var \Drupal\facets\Result\ResultInterface $r */
foreach ($results as $k => $r) {
@@ -188,8 +196,8 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
$request = new Request();
$request->query->set('ab', []);
- $this->processor = new QueryStringUrlProcessor(['facet' => $facet], 'query_string', [], $request);
- $results = $this->processor->build($facet, $this->originalResults);
+ $this->processor = new QueryString(['facet' => $facet], 'query_string', [], $request);
+ $results = $this->processor->buildUrls($facet, $this->originalResults);
/** @var \Drupal\facets\Result\ResultInterface $r */
foreach ($results as $r) {