Commit f27b7e3b authored by borisson_'s avatar borisson_
Browse files

Extended test coverage

parent 8766ecb0
......@@ -7,9 +7,12 @@
namespace Drupal\Tests\facets\Unit\Plugin\processor;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Plugin\facets\processor\ActiveWidgetOrderProcessor;
use Drupal\facets\Processor\ProcessorPluginManager;
use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* Unit test for processor.
......@@ -78,4 +81,53 @@ class ActiveWidgetOrderProcessorTest extends UnitTestCase {
}
}
/**
* Tests configuration.
*/
public function testConfiguration() {
$config = $this->processor->defaultConfiguration();
$this->assertEquals(['sort' => 'ASC'], $config);
}
/**
* Tests build.
*/
public function testBuild() {
$processor_definitions = [
'active_widget_order' => [
'id' => 'active_widget_order',
'class' => 'Drupal\facets\Plugin\facets\processor\ActiveWidgetOrderProcessor',
],
];
$manager = $this->getMockBuilder(ProcessorPluginManager::class)
->disableOriginalConstructor()
->getMock();
$manager->expects($this->once())
->method('getDefinitions')
->willReturn($processor_definitions);
$manager->expects($this->once())
->method('createInstance')
->willReturn($this->processor);
$container_builder = new ContainerBuilder();
$container_builder->set('plugin.manager.facets.processor', $manager);
\Drupal::setContainer($container_builder);
$facet = new Facet(
[
'id' => 'the_zoo',
'results' => $this->originalResults,
'processor_configs' => $processor_definitions,
],
'facets_facet'
);
$built = $this->processor->build($facet, $this->originalResults);
$this->assertEquals('Minimus', $built[0]->getDisplayValue());
$this->assertEquals('Old Major', $built[1]->getDisplayValue());
$this->assertEquals('Mr. Whymper', $built[2]->getDisplayValue());
$this->assertEquals('Boxer', $built[3]->getDisplayValue());
$this->assertEquals('Clover', $built[4]->getDisplayValue());
}
}
......@@ -59,10 +59,10 @@ class CountLimitProcessorTest extends UnitTestCase {
$manager = $this->getMockBuilder('Drupal\facets\Processor\ProcessorPluginManager')
->disableOriginalConstructor()
->getMock();
$manager->expects($this->once())
$manager->expects($this->any())
->method('getDefinitions')
->willReturn($processor_definitions);
$manager->expects($this->once())
$manager->expects($this->any())
->method('createInstance')
->willReturn($this->processor);
......@@ -192,4 +192,33 @@ class CountLimitProcessorTest extends UnitTestCase {
$this->assertEquals('duck', $sorted_results[2]->getDisplayValue());
}
/**
* Tests configuration.
*/
public function testConfiguration() {
$config = $this->processor->defaultConfiguration();
$this->assertEquals(['minimum_items' => 1, 'maximum_items' => 0], $config);
}
/**
* Tests testDescription().
*/
public function testDescription() {
$this->assertEquals('', $this->processor->getDescription());
}
/**
* Tests isHidden().
*/
public function testIsHidden() {
$this->assertEquals(FALSE, $this->processor->isHidden());
}
/**
* Tests isLocked().
*/
public function testIsLocked() {
$this->assertEquals(FALSE, $this->processor->isLocked());
}
}
......@@ -7,9 +7,12 @@
namespace Drupal\Tests\facets\Unit\Plugin\processor;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Plugin\facets\processor\CountWidgetOrderProcessor;
use Drupal\facets\Processor\ProcessorPluginManager;
use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* Unit test for processor.
......@@ -77,4 +80,51 @@ class CountWidgetOrderProcessorTest extends UnitTestCase {
$this->assertEquals('badger', $sorted_results[2]->getDisplayValue());
}
/**
* Tests configuration.
*/
public function testConfiguration() {
$config = $this->processor->defaultConfiguration();
$this->assertEquals(['sort' => 'ASC'], $config);
}
/**
* Tests build.
*/
public function testBuild() {
$processor_definitions = [
'count_widget_order' => [
'id' => 'count_widget_order',
'class' => 'Drupal\facets\Plugin\facets\processor\CountWidgetOrderProcessor',
],
];
$manager = $this->getMockBuilder(ProcessorPluginManager::class)
->disableOriginalConstructor()
->getMock();
$manager->expects($this->once())
->method('getDefinitions')
->willReturn($processor_definitions);
$manager->expects($this->once())
->method('createInstance')
->willReturn($this->processor);
$container_builder = new ContainerBuilder();
$container_builder->set('plugin.manager.facets.processor', $manager);
\Drupal::setContainer($container_builder);
$facet = new Facet(
[
'id' => 'the_zoo',
'results' => $this->originalResults,
'processor_configs' => $processor_definitions,
],
'facets_facet'
);
$built = $this->processor->build($facet, $this->originalResults);
$this->assertEquals('badger', $built[0]->getDisplayValue());
$this->assertEquals('llama', $built[1]->getDisplayValue());
$this->assertEquals('duck', $built[2]->getDisplayValue());
}
}
......@@ -7,9 +7,12 @@
namespace Drupal\Tests\facets\Unit\Plugin\processor;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Plugin\facets\processor\DisplayValueWidgetOrderProcessor;
use Drupal\facets\Processor\ProcessorPluginManager;
use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* Unit test for processor.
......@@ -104,4 +107,56 @@ class DisplayValueWidgetOrderProcessorTest extends UnitTestCase {
$this->assertEquals('Test AA', $sorted_results[1]->getDisplayValue());
}
/**
* Tests configuration.
*/
public function testConfiguration() {
$config = $this->processor->defaultConfiguration();
$this->assertEquals(['sort' => 'ASC'], $config);
}
/**
* Tests build.
*/
public function testBuild() {
$processor_definitions = [
'display_value_widget_order' => [
'id' => 'display_value_widget_order',
'class' => 'Drupal\facets\Plugin\facets\processor\DisplayValueWidgetOrderProcessor',
],
];
$manager = $this->getMockBuilder(ProcessorPluginManager::class)
->disableOriginalConstructor()
->getMock();
$manager->expects($this->once())
->method('getDefinitions')
->willReturn($processor_definitions);
$manager->expects($this->once())
->method('createInstance')
->willReturn($this->processor);
$container_builder = new ContainerBuilder();
$container_builder->set('plugin.manager.facets.processor', $manager);
\Drupal::setContainer($container_builder);
$facet = new Facet(
[
'id' => 'the_zoo',
'results' => $this->originalResults,
'processor_configs' => $processor_definitions,
],
'facets_facet'
);
$built = $this->processor->build($facet, $this->originalResults);
$this->assertEquals('2', $built[0]->getDisplayValue());
$this->assertEquals('1977', $built[1]->getDisplayValue());
$this->assertEquals('FALSE', $built[2]->getDisplayValue());
$this->assertEquals('Hubbard', $built[3]->getDisplayValue());
$this->assertEquals('thetans', $built[4]->getDisplayValue());
$this->assertEquals('Tom', $built[5]->getDisplayValue());
$this->assertEquals('xenu', $built[6]->getDisplayValue());
}
}
......@@ -8,6 +8,7 @@ namespace Drupal\Tests\facets\Unit\Plugin\processor;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Plugin\facets\processor\ExcludeSpecifiedItemsProcessor;
use Drupal\facets\Processor\ProcessorInterface;
use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
......@@ -65,10 +66,10 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase {
$manager = $this->getMockBuilder('Drupal\facets\Processor\ProcessorPluginManager')
->disableOriginalConstructor()
->getMock();
$manager->expects($this->once())
$manager->expects($this->any())
->method('getDefinitions')
->willReturn($processor_definitions);
$manager->expects($this->once())
$manager->expects($this->any())
->method('createInstance')
->willReturn($this->processor);
......@@ -245,4 +246,33 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase {
];
}
/**
* Tests configuration.
*/
public function testConfiguration() {
$config = $this->processor->defaultConfiguration();
$this->assertEquals(['exclude' => '', 'regex' => 0], $config);
}
/**
* Tests testDescription().
*/
public function testDescription() {
$this->assertEquals('', $this->processor->getDescription());
}
/**
* Tests isHidden().
*/
public function testIsHidden() {
$this->assertEquals(FALSE, $this->processor->isHidden());
}
/**
* Tests isLocked().
*/
public function testIsLocked() {
$this->assertEquals(FALSE, $this->processor->isLocked());
}
}
......@@ -92,4 +92,34 @@ class HideNonNarrowingResultProcessorTest extends UnitTestCase {
$this->assertEquals('duck', $filtered_results[2]->getDisplayValue());
}
/**
* Tests configuration.
*/
public function testConfiguration() {
$config = $this->processor->defaultConfiguration();
$this->assertEquals([], $config);
}
/**
* Tests testDescription().
*/
public function testDescription() {
$this->assertEquals('', $this->processor->getDescription());
}
/**
* Tests isHidden().
*/
public function testIsHidden() {
$this->assertEquals(FALSE, $this->processor->isHidden());
}
/**
* Tests isLocked().
*/
public function testIsLocked() {
$this->assertEquals(FALSE, $this->processor->isLocked());
}
}
......@@ -7,9 +7,12 @@
namespace Drupal\Tests\facets\Unit\Plugin\processor;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Plugin\facets\processor\RawValueWidgetOrderProcessor;
use Drupal\facets\Processor\ProcessorPluginManager;
use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* Unit test for processor.
......@@ -89,4 +92,55 @@ class RawValueWidgetOrderProcessorTest extends UnitTestCase {
}
}
/**
* Tests configuration.
*/
public function testConfiguration() {
$config = $this->processor->defaultConfiguration();
$this->assertEquals(['sort' => 'ASC'], $config);
}
/**
* Tests build.
*/
public function testBuild() {
$processor_definitions = [
'raw_value_widget_order' => [
'id' => 'raw_value_widget_order',
'class' => 'Drupal\facets\Plugin\facets\processor\RawValueWidgetOrderProcessor',
],
];
$manager = $this->getMockBuilder(ProcessorPluginManager::class)
->disableOriginalConstructor()
->getMock();
$manager->expects($this->once())
->method('getDefinitions')
->willReturn($processor_definitions);
$manager->expects($this->once())
->method('createInstance')
->willReturn($this->processor);
$container_builder = new ContainerBuilder();
$container_builder->set('plugin.manager.facets.processor', $manager);
\Drupal::setContainer($container_builder);
$facet = new Facet(
[
'id' => 'the_zoo',
'results' => $this->originalResults,
'processor_configs' => $processor_definitions,
],
'facets_facet'
);
$built = $this->processor->build($facet, $this->originalResults);
$this->assertEquals('Tom', $built[0]->getDisplayValue());
$this->assertEquals('xenu', $built[1]->getDisplayValue());
$this->assertEquals('thetans', $built[2]->getDisplayValue());
$this->assertEquals('Hubbard', $built[3]->getDisplayValue());
$this->assertEquals('FALSE', $built[4]->getDisplayValue());
$this->assertEquals('2', $built[5]->getDisplayValue());
$this->assertEquals('1977', $built[6]->getDisplayValue());
}
}
......@@ -88,4 +88,12 @@ class UidToUserNameCallbackProcessorTest extends UnitTestCase {
\Drupal::setContainer($container);
}
/**
* Tests configuration.
*/
public function testConfiguration() {
$config = $this->processor->defaultConfiguration();
$this->assertEquals([], $config);
}
}
......@@ -47,6 +47,52 @@ class UrlProcessorHandlerTest extends UnitTestCase {
$processor->build($facet, []);
}
/**
* Tests configuration.
*/
public function testConfiguration() {
$facet = new Facet([], 'facets_facet');
$this->createContainer();
$processor = new UrlProcessorHandler(['facet' => $facet], 'url_processor_handler', []);
$config = $processor->defaultConfiguration();
$this->assertEquals([], $config);
}
/**
* Tests testDescription().
*/
public function testDescription() {
$facet = new Facet([], 'facets_facet');
$this->createContainer();
$processor = new UrlProcessorHandler(['facet' => $facet], 'url_processor_handler', []);
$this->assertEquals('', $processor->getDescription());
}
/**
* Tests isHidden().
*/
public function testIsHidden() {
$facet = new Facet([], 'facets_facet');
$this->createContainer();
$processor = new UrlProcessorHandler(['facet' => $facet], 'url_processor_handler', []);
$this->assertEquals(FALSE, $processor->isHidden());
}
/**
* Tests isLocked().
*/
public function testIsLocked() {
$facet = new Facet([], 'facets_facet');
$this->createContainer();
$processor = new UrlProcessorHandler(['facet' => $facet], 'url_processor_handler', []);
$this->assertEquals(FALSE, $processor->isLocked());
}
/**
* Sets up a container.
*/
......
......@@ -83,4 +83,21 @@ class SearchApiStringTest extends UnitTestCase {
$this->assertEmpty($results);
}
/**
* Tests string query type without results.
*/
public function testConfiguration() {
$query = new SearchApiQuery([], 'search_api_query', []);
$facet = new Facet([], 'facets_facet');
$default_config = ['facet' => $facet, 'query' => $query];
$query_type = new SearchApiString($default_config, 'search_api_string', []);
$this->assertEquals([], $query_type->defaultConfiguration());
$this->assertEquals($default_config, $query_type->getConfiguration());
$query_type->setConfiguration(['owl' => 'Long-eared owl']);
$this->assertEquals(['owl' => 'Long-eared owl'], $query_type->getConfiguration());
}
}
......@@ -15,6 +15,7 @@ use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Unit test for processor.
......@@ -62,6 +63,23 @@ class QueryStringTest extends UnitTestCase {
new QueryString([], 'test', [], new Request());
}
/**
* Tests that the processor correctly throws an exception.
*/
public function testCreate() {
$facet = new Facet([], 'facet');
$request_stack = new RequestStack();
$request = new Request();
$request_stack->push($request);
$container = new ContainerBuilder();
$container->set('request_stack', $request_stack);
$qs = QueryString::create($container, ['facet' => $facet], 'query_string', []);
$this->assertInstanceOf(QueryString::class, $qs);
}
/**
* Tests with one active item.
*/
......@@ -115,7 +133,7 @@ class QueryStringTest extends UnitTestCase {
}
/**
* Test swith default build.
* Tests with default build.
*/
public function testBuild() {
$facet = new Facet([], 'facet');
......@@ -129,6 +147,8 @@ class QueryStringTest extends UnitTestCase {
$this->processor = new QueryString(['facet' => $facet], 'query_string', [], $request);
$results = $this->processor->buildUrls($facet, $this->originalResults);
$this->assertEquals('f', $this->processor->getFilterKey());
/** @var \Drupal\facets\Result\ResultInterface $r */
foreach ($results as $r) {
$this->assertInstanceOf('\Drupal\facets\Result\ResultInterface', $r);
......
......@@ -12,6 +12,7 @@ use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\facets\Processor\ProcessorInterface;
use Drupal\facets\Processor\ProcessorPluginManager;
use Drupal\Tests\UnitTestCase;
use Zend\Stdlib\ArrayObject;
......@@ -116,4 +117,20 @@ class ProcessorPluginManagerTest extends UnitTestCase {
$this->assertSame($definitions, $this->sut->getDefinitions());
}
/**
* Tests processing stages.
*/
public function testGetProcessingStages() {
$namespaces = new ArrayObject();
$sut = new ProcessorPluginManager($namespaces, $this->cache, $this->moduleHandler, $this->translator);
$stages = [
ProcessorInterface::STAGE_PRE_QUERY,
ProcessorInterface::STAGE_POST_QUERY,
ProcessorInterface::STAGE_BUILD
];
$this->assertEquals($stages, array_keys($sut->getProcessingStages()));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment