summaryrefslogtreecommitdiffstats
path: root/tests/src/Unit/Plugin
diff options
context:
space:
mode:
authorJoris Vercammen2015-12-05 15:54:39 (GMT)
committerJoris Vercammen2015-12-05 15:54:39 (GMT)
commita23387db94cb0ad4a49d60ef9d9c43d95100b05c (patch)
treea4f5414ae21823e624e4e4832e37271430d0a5db /tests/src/Unit/Plugin
parentf3d9a9342cb457829e5019e43d59ffbd2cc89c49 (diff)
Fix drupal coding standards
Diffstat (limited to 'tests/src/Unit/Plugin')
-rw-r--r--tests/src/Unit/Plugin/processor/ActiveWidgetOrderProcessorTest.php10
-rw-r--r--tests/src/Unit/Plugin/processor/CountLimitProcessorTest.php22
-rw-r--r--tests/src/Unit/Plugin/processor/CountWidgetOrderProcessorTest.php10
-rw-r--r--tests/src/Unit/Plugin/processor/DisplayValueWidgetOrderProcessorTest.php30
-rw-r--r--tests/src/Unit/Plugin/processor/ExcludeSpecifiedItemsProcessorTest.php118
-rw-r--r--tests/src/Unit/Plugin/processor/HideNonNarrowingResultProcessorTest.php12
-rw-r--r--tests/src/Unit/Plugin/processor/QueryStringUrlProcessorTest.php42
-rw-r--r--tests/src/Unit/Plugin/processor/RawValueWidgetOrderProcessorTest.php30
-rw-r--r--tests/src/Unit/Plugin/processor/UidToUserNameCallbackProcessorTest.php16
-rw-r--r--tests/src/Unit/Plugin/query_type/SearchApiStringTest.php5
-rw-r--r--tests/src/Unit/Plugin/widget/CheckboxWidgetTest.php10
-rw-r--r--tests/src/Unit/Plugin/widget/LinksWidgetTest.php35
12 files changed, 238 insertions, 102 deletions
diff --git a/tests/src/Unit/Plugin/processor/ActiveWidgetOrderProcessorTest.php b/tests/src/Unit/Plugin/processor/ActiveWidgetOrderProcessorTest.php
index 7684701..81a8e3b 100644
--- a/tests/src/Unit/Plugin/processor/ActiveWidgetOrderProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/ActiveWidgetOrderProcessorTest.php
@@ -12,6 +12,8 @@ use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class ActiveWidgetOrderProcessorTest extends UnitTestCase {
@@ -28,7 +30,7 @@ class ActiveWidgetOrderProcessorTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -49,7 +51,7 @@ class ActiveWidgetOrderProcessorTest extends UnitTestCase {
$original_results[2]->setActiveState(TRUE);
$original_results[3]->setActiveState(TRUE);
- $this->original_results = $original_results;
+ $this->originalResults = $original_results;
$this->processor = new ActiveWidgetOrderProcessor([], 'active_widget_order', []);
}
@@ -58,7 +60,7 @@ class ActiveWidgetOrderProcessorTest extends UnitTestCase {
* Test sorting ascending.
*/
public function testAscending() {
- $sorted_results = $this->processor->sortResults($this->original_results, 'ASC');
+ $sorted_results = $this->processor->sortResults($this->originalResults, 'ASC');
$expected_values = [TRUE, TRUE, TRUE, FALSE, FALSE];
foreach ($expected_values as $index => $value) {
$this->assertEquals($value, $sorted_results[$index]->isActive());
@@ -69,7 +71,7 @@ class ActiveWidgetOrderProcessorTest extends UnitTestCase {
* Test sorting descending.
*/
public function testDescending() {
- $sorted_results = $this->processor->sortResults($this->original_results, 'DESC');
+ $sorted_results = $this->processor->sortResults($this->originalResults, 'DESC');
$expected_values = array_reverse([TRUE, TRUE, TRUE, FALSE, FALSE]);
foreach ($expected_values as $index => $value) {
$this->assertEquals($value, $sorted_results[$index]->isActive());
diff --git a/tests/src/Unit/Plugin/processor/CountLimitProcessorTest.php b/tests/src/Unit/Plugin/processor/CountLimitProcessorTest.php
index baf5c1d..edf4c27 100644
--- a/tests/src/Unit/Plugin/processor/CountLimitProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/CountLimitProcessorTest.php
@@ -14,6 +14,8 @@ use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class CountLimitProcessorTest extends UnitTestCase {
@@ -30,7 +32,7 @@ class CountLimitProcessorTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -38,7 +40,7 @@ class CountLimitProcessorTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
- $this->original_results = [
+ $this->originalResults = [
new Result('llama', 'llama', 10),
new Result('badger', 'badger', 5),
new Result('duck', 'duck', 15),
@@ -47,7 +49,7 @@ class CountLimitProcessorTest extends UnitTestCase {
$processor_id = 'count_limit';
$this->processor = new CountLimitProcessor([], $processor_id, []);
- $processorDefinitions = [
+ $processor_definitions = [
$processor_id => [
'id' => $processor_id,
'class' => 'Drupal\facets\Plugin\facets\processor\CountLimitProcessor',
@@ -59,7 +61,7 @@ class CountLimitProcessorTest extends UnitTestCase {
->getMock();
$manager->expects($this->once())
->method('getDefinitions')
- ->willReturn($processorDefinitions);
+ ->willReturn($processor_definitions);
$manager->expects($this->once())
->method('createInstance')
->willReturn($this->processor);
@@ -75,14 +77,14 @@ class CountLimitProcessorTest extends UnitTestCase {
*/
public function testNoFilter() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->setOption('processors', [
'count_limit' => [
'settings' => ['minimum_items' => 4],
],
]);
$this->processor->setConfiguration(['minimum_items' => 4]);
- $sorted_results = $this->processor->build($facet, $this->original_results);
+ $sorted_results = $this->processor->build($facet, $this->originalResults);
$this->assertCount(3, $sorted_results);
@@ -96,7 +98,7 @@ class CountLimitProcessorTest extends UnitTestCase {
*/
public function testMinEqualsValue() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->setOption('processors', [
'count_limit' => [
'settings' => ['minimum_items' => 5],
@@ -104,7 +106,7 @@ class CountLimitProcessorTest extends UnitTestCase {
]);
$this->processor->setConfiguration(['minimum_items' => 5]);
- $sorted_results = $this->processor->build($facet, $this->original_results);
+ $sorted_results = $this->processor->build($facet, $this->originalResults);
$this->assertCount(3, $sorted_results);
@@ -170,7 +172,7 @@ class CountLimitProcessorTest extends UnitTestCase {
*/
public function testFilterResults() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->setOption('processors', [
'count_limit' => [
'settings' => ['minimum_items' => 8],
@@ -178,7 +180,7 @@ class CountLimitProcessorTest extends UnitTestCase {
]);
$this->processor->setConfiguration(['minimum_items' => 8]);
- $sorted_results = $this->processor->build($facet, $this->original_results);
+ $sorted_results = $this->processor->build($facet, $this->originalResults);
$this->assertCount(2, $sorted_results);
diff --git a/tests/src/Unit/Plugin/processor/CountWidgetOrderProcessorTest.php b/tests/src/Unit/Plugin/processor/CountWidgetOrderProcessorTest.php
index c9385f7..2fdbebf 100644
--- a/tests/src/Unit/Plugin/processor/CountWidgetOrderProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/CountWidgetOrderProcessorTest.php
@@ -12,6 +12,8 @@ use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class CountWidgetOrderProcessorTest extends UnitTestCase {
@@ -28,7 +30,7 @@ class CountWidgetOrderProcessorTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -36,7 +38,7 @@ class CountWidgetOrderProcessorTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
- $this->original_results = [
+ $this->originalResults = [
new Result('llama', 'llama', 10),
new Result('badger', 'badger', 5),
new Result('duck', 'duck', 15),
@@ -50,7 +52,7 @@ class CountWidgetOrderProcessorTest extends UnitTestCase {
*/
public function testAscending() {
- $sorted_results = $this->processor->sortResults($this->original_results, 'ASC');
+ $sorted_results = $this->processor->sortResults($this->originalResults, 'ASC');
$this->assertEquals(5, $sorted_results[0]->getCount());
$this->assertEquals('badger', $sorted_results[0]->getDisplayValue());
@@ -65,7 +67,7 @@ class CountWidgetOrderProcessorTest extends UnitTestCase {
*/
public function testDescending() {
- $sorted_results = $this->processor->sortResults($this->original_results, 'DESC');
+ $sorted_results = $this->processor->sortResults($this->originalResults, 'DESC');
$this->assertEquals(15, $sorted_results[0]->getCount());
$this->assertEquals('duck', $sorted_results[0]->getDisplayValue());
diff --git a/tests/src/Unit/Plugin/processor/DisplayValueWidgetOrderProcessorTest.php b/tests/src/Unit/Plugin/processor/DisplayValueWidgetOrderProcessorTest.php
index a865d9b..dc7790c 100644
--- a/tests/src/Unit/Plugin/processor/DisplayValueWidgetOrderProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/DisplayValueWidgetOrderProcessorTest.php
@@ -12,6 +12,8 @@ use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class DisplayValueWidgetOrderProcessorTest extends UnitTestCase {
@@ -28,7 +30,7 @@ class DisplayValueWidgetOrderProcessorTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -36,7 +38,7 @@ class DisplayValueWidgetOrderProcessorTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
- $this->original_results = [
+ $this->originalResults = [
new Result('thetans', 'thetans', 10),
new Result('xenu', 'xenu', 5),
new Result('Tom', 'Tom', 15),
@@ -53,8 +55,16 @@ class DisplayValueWidgetOrderProcessorTest extends UnitTestCase {
* Test sorting ascending.
*/
public function testAscending() {
- $sorted_results = $this->processor->sortResults($this->original_results, 'ASC');
- $expected_values = ['2', '1977', 'FALSE', 'Hubbard', 'thetans', 'Tom', 'xenu'];
+ $sorted_results = $this->processor->sortResults($this->originalResults, 'ASC');
+ $expected_values = [
+ '2',
+ '1977',
+ 'FALSE',
+ 'Hubbard',
+ 'thetans',
+ 'Tom',
+ 'xenu',
+ ];
foreach ($expected_values as $index => $value) {
$this->assertEquals($value, $sorted_results[$index]->getDisplayValue());
}
@@ -64,8 +74,16 @@ class DisplayValueWidgetOrderProcessorTest extends UnitTestCase {
* Test sorting descending.
*/
public function testDescending() {
- $sorted_results = $this->processor->sortResults($this->original_results, 'DESC');
- $expected_values = array_reverse(['2', '1977', 'FALSE', 'Hubbard', 'thetans', 'Tom', 'xenu']);
+ $sorted_results = $this->processor->sortResults($this->originalResults, 'DESC');
+ $expected_values = array_reverse([
+ '2',
+ '1977',
+ 'FALSE',
+ 'Hubbard',
+ 'thetans',
+ 'Tom',
+ 'xenu',
+ ]);
foreach ($expected_values as $index => $value) {
$this->assertEquals($value, $sorted_results[$index]->getDisplayValue());
}
diff --git a/tests/src/Unit/Plugin/processor/ExcludeSpecifiedItemsProcessorTest.php b/tests/src/Unit/Plugin/processor/ExcludeSpecifiedItemsProcessorTest.php
index 2fad703..07fd5d7 100644
--- a/tests/src/Unit/Plugin/processor/ExcludeSpecifiedItemsProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/ExcludeSpecifiedItemsProcessorTest.php
@@ -13,6 +13,8 @@ use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase {
@@ -29,7 +31,7 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -37,7 +39,7 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
- $this->original_results = [
+ $this->originalResults = [
new Result('llama', 'llama', 10),
new Result('badger', 'badger', 5),
new Result('duck', 'duck', 15),
@@ -53,7 +55,7 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase {
$processor_id = 'exclude_specified_items';
$this->processor = new ExcludeSpecifiedItemsProcessor([], $processor_id, []);
- $processorDefinitions = [
+ $processor_definitions = [
$processor_id => [
'id' => $processor_id,
'class' => 'Drupal\facets\Plugin\facets\processor\ExcludeSpecifiedItemsProcessor',
@@ -65,7 +67,7 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase {
->getMock();
$manager->expects($this->once())
->method('getDefinitions')
- ->willReturn($processorDefinitions);
+ ->willReturn($processor_definitions);
$manager->expects($this->once())
->method('createInstance')
->willReturn($this->processor);
@@ -80,45 +82,45 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase {
*/
public function testNoFilter() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->setOption('processors', [
'exclude_specified_items' => [
'settings' => [
'exclude' => 'alpaca',
- 'regex' => 0
+ 'regex' => 0,
],
],
]);
$this->processor->setConfiguration([
'exclude' => 'alpaca',
- 'regex' => 0
+ 'regex' => 0,
]);
- $filtered_results = $this->processor->build($facet, $this->original_results);
+ $filtered_results = $this->processor->build($facet, $this->originalResults);
- $this->assertCount(count($this->original_results), $filtered_results);
+ $this->assertCount(count($this->originalResults), $filtered_results);
}
/**
- * Test filtering happens for string filter
+ * Test filtering happens for string filter.
*/
public function testStringFilter() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->setOption('processors', [
'exclude_specified_items' => [
'settings' => [
'exclude' => 'llama',
- 'regex' => 0
+ 'regex' => 0,
],
],
]);
$this->processor->setConfiguration([
'exclude' => 'llama',
- 'regex' => 0
+ 'regex' => 0,
]);
- $filtered_results = $this->processor->build($facet, $this->original_results);
+ $filtered_results = $this->processor->build($facet, $this->originalResults);
- $this->assertCount((count($this->original_results) -1), $filtered_results);
+ $this->assertCount((count($this->originalResults) - 1), $filtered_results);
foreach ($filtered_results as $result) {
$this->assertNotEquals('llama', $result->getDisplayValue());
@@ -126,67 +128,121 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase {
}
/**
- * Test filtering happens for regex filter
+ * Test filtering happens for regex filter.
*
* @dataProvider provideRegexTests
*/
- public function testRegexFilter($regex, $expectedResults) {
+ public function testRegexFilter($regex, $expected_results) {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->setOption('processors', [
'exclude_specified_items' => [
'settings' => [
'exclude' => $regex,
- 'regex' => 1
+ 'regex' => 1,
],
],
]);
$this->processor->setConfiguration([
'exclude' => $regex,
- 'regex' => 1
+ 'regex' => 1,
]);
- $filtered_results = $this->processor->build($facet, $this->original_results);
+ $filtered_results = $this->processor->build($facet, $this->originalResults);
- $this->assertCount(count($expectedResults), $filtered_results);
+ $this->assertCount(count($expected_results), $filtered_results);
foreach ($filtered_results as $res) {
- $this->assertTrue(in_array($res->getDisplayValue(), $expectedResults));
+ $this->assertTrue(in_array($res->getDisplayValue(), $expected_results));
}
}
/**
- * Provide multiple data sets for ::testRegexFilter
+ * Provide multiple data sets for ::testRegexFilter.
*/
public function provideRegexTests() {
return [
[
'test',
- ['llama', 'duck', 'badger', 'snake', 'snaake', 'snaaake', 'snaaaake', 'snaaaaake', 'snaaaaaake', 'snbke']
+ [
+ 'llama',
+ 'duck',
+ 'badger',
+ 'snake',
+ 'snaake',
+ 'snaaake',
+ 'snaaaake',
+ 'snaaaaake',
+ 'snaaaaaake',
+ 'snbke',
+ ],
],
[
'llama',
- ['badger', 'duck', 'snake', 'snaake', 'snaaake', 'snaaaake', 'snaaaaake', 'snaaaaaake', 'snbke']
+ [
+ 'badger',
+ 'duck',
+ 'snake',
+ 'snaake',
+ 'snaaake',
+ 'snaaaake',
+ 'snaaaaake',
+ 'snaaaaaake',
+ 'snbke',
+ ],
],
[
'duck',
- ['llama', 'badger', 'snake', 'snaake', 'snaaake', 'snaaaake', 'snaaaaake', 'snaaaaaake', 'snbke']
+ [
+ 'llama',
+ 'badger',
+ 'snake',
+ 'snaake',
+ 'snaaake',
+ 'snaaaake',
+ 'snaaaaake',
+ 'snaaaaaake',
+ 'snbke',
+ ],
],
[
'sn(.*)ke',
- ['llama', 'duck', 'badger']
+ [
+ 'llama',
+ 'duck',
+ 'badger',
+ ],
],
[
'sn(a*)ke',
- ['llama', 'duck', 'badger', 'snbke']
+ [
+ 'llama',
+ 'duck',
+ 'badger',
+ 'snbke',
+ ],
],
[
'sn(a+)ke',
- ['llama', 'duck', 'badger', 'snbke']
+ [
+ 'llama',
+ 'duck',
+ 'badger',
+ 'snbke',
+ ],
],
[
'sn(a{3,5})ke',
- ['llama', 'duck', 'badger', 'snake', 'snaake', 'snaaaaaake', 'snbke']
+ [
+ 'llama',
+ 'duck',
+ 'badger',
+ 'snake',
+ 'snaake',
+ 'snaaaaaake',
+ 'snbke',
+ ],
],
];
}
+
}
diff --git a/tests/src/Unit/Plugin/processor/HideNonNarrowingResultProcessorTest.php b/tests/src/Unit/Plugin/processor/HideNonNarrowingResultProcessorTest.php
index ba9d151..4d67c6a 100644
--- a/tests/src/Unit/Plugin/processor/HideNonNarrowingResultProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/HideNonNarrowingResultProcessorTest.php
@@ -13,6 +13,8 @@ use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class HideNonNarrowingResultProcessorTest extends UnitTestCase {
@@ -29,7 +31,7 @@ class HideNonNarrowingResultProcessorTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -37,7 +39,7 @@ class HideNonNarrowingResultProcessorTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
- $this->original_results = [
+ $this->originalResults = [
new Result('llama', 'llama', 10),
new Result('badger', 'badger', 15),
new Result('duck', 'duck', 15),
@@ -53,9 +55,9 @@ class HideNonNarrowingResultProcessorTest extends UnitTestCase {
public function testNoFilterResults() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
- $filtered_results = $this->processor->build($facet, $this->original_results);
+ $filtered_results = $this->processor->build($facet, $this->originalResults);
$this->assertCount(3, $filtered_results);
@@ -72,7 +74,7 @@ class HideNonNarrowingResultProcessorTest extends UnitTestCase {
*/
public function testFilterResults() {
- $results = $this->original_results;
+ $results = $this->originalResults;
$results[2]->setActiveState(TRUE);
$facet = new Facet([], 'facet');
diff --git a/tests/src/Unit/Plugin/processor/QueryStringUrlProcessorTest.php b/tests/src/Unit/Plugin/processor/QueryStringUrlProcessorTest.php
index a4b22eb..2315ddf 100644
--- a/tests/src/Unit/Plugin/processor/QueryStringUrlProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/QueryStringUrlProcessorTest.php
@@ -16,6 +16,8 @@ use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class QueryStringUrlProcessorTest extends UnitTestCase {
@@ -32,7 +34,7 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -40,7 +42,7 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
- $this->original_results = [
+ $this->originalResults = [
new Result('llama', 'Llama', 15),
new Result('badger', 'Badger', 5),
new Result('mushroom', 'Mushroom', 5),
@@ -49,12 +51,15 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
];
}
+ /**
+ * Basic test with one active item.
+ */
public function testSetSingleActiveItem() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->setFieldIdentifier('test');
- $request = new Request;
+ $request = new Request();
$request->query->set('f', ['test:badger']);
$this->processor = new QueryStringUrlProcessor([], 'query_string', [], $request);
@@ -63,12 +68,15 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
$this->assertEquals(['badger'], $facet->getActiveItems());
}
+ /**
+ * Basic test with multiple active items.
+ */
public function testSetMultipleActiveItems() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->setFieldIdentifier('test');
- $request = new Request;
+ $request = new Request();
$request->query->set('f', ['test:badger', 'test:mushroom', 'donkey:kong']);
$this->processor = new QueryStringUrlProcessor([], 'query_string', [], $request);
@@ -77,11 +85,14 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
$this->assertEquals(['badger', 'mushroom'], $facet->getActiveItems());
}
+ /**
+ * Basic test with an empty build.
+ */
public function testEmptyBuild() {
$facet = new Facet([], 'facet');
$facet->setFacetSourceId('facet_source__dummy');
- $request = new Request;
+ $request = new Request();
$request->query->set('f', []);
$this->processor = new QueryStringUrlProcessor([], 'query_string', [], $request);
@@ -89,18 +100,21 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
$this->assertEmpty($results);
}
+ /**
+ * Test with default build.
+ */
public function testBuild() {
$facet = new Facet([], 'facet');
$facet->setFieldIdentifier('test');
$facet->setFacetSourceId('facet_source__dummy');
- $request = new Request;
+ $request = new Request();
$request->query->set('f', []);
$this->setContainer();
$this->processor = new QueryStringUrlProcessor([], 'query_string', [], $request);
- $results = $this->processor->build($facet, $this->original_results);
+ $results = $this->processor->build($facet, $this->originalResults);
/** @var \Drupal\facets\Result\ResultInterface $r */
foreach ($results as $r) {
@@ -109,15 +123,18 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
}
}
+ /**
+ * Test with an active item already from url.
+ */
public function testBuildWithActiveItem() {
$facet = new Facet([], 'facet');
$facet->setFieldIdentifier('test');
$facet->setFacetSourceId('facet_source__dummy');
- $original_results = $this->original_results;
+ $original_results = $this->originalResults;
$original_results[2]->setActiveState(TRUE);
- $request = new Request;
+ $request = new Request();
$request->query->set('f', ['king:kong']);
$this->setContainer();
@@ -137,6 +154,9 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
}
}
+ /**
+ * Set the container for use in unit tests.
+ */
protected function setContainer() {
$router = $this->getMockBuilder('Drupal\Tests\Core\Routing\TestRouterInterface')
->disableOriginalConstructor()
diff --git a/tests/src/Unit/Plugin/processor/RawValueWidgetOrderProcessorTest.php b/tests/src/Unit/Plugin/processor/RawValueWidgetOrderProcessorTest.php
index f99a485..16396bb 100644
--- a/tests/src/Unit/Plugin/processor/RawValueWidgetOrderProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/RawValueWidgetOrderProcessorTest.php
@@ -12,6 +12,8 @@ use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class RawValueWidgetOrderProcessorTest extends UnitTestCase {
@@ -28,7 +30,7 @@ class RawValueWidgetOrderProcessorTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -36,7 +38,7 @@ class RawValueWidgetOrderProcessorTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
- $this->original_results = [
+ $this->originalResults = [
new Result('C', 'thetans', 10),
new Result('B', 'xenu', 5),
new Result('A', 'Tom', 15),
@@ -53,8 +55,16 @@ class RawValueWidgetOrderProcessorTest extends UnitTestCase {
* Test sorting ascending.
*/
public function testAscending() {
- $sorted_results = $this->processor->sortResults($this->original_results, 'ASC');
- $expected_values = ['Tom', 'xenu', 'thetans', 'Hubbard', 'FALSE', '2', '1977'];
+ $sorted_results = $this->processor->sortResults($this->originalResults, 'ASC');
+ $expected_values = [
+ 'Tom',
+ 'xenu',
+ 'thetans',
+ 'Hubbard',
+ 'FALSE',
+ '2',
+ '1977',
+ ];
foreach ($expected_values as $index => $value) {
$this->assertEquals($value, $sorted_results[$index]->getDisplayValue());
}
@@ -64,8 +74,16 @@ class RawValueWidgetOrderProcessorTest extends UnitTestCase {
* Test sorting descending.
*/
public function testDescending() {
- $sorted_results = $this->processor->sortResults($this->original_results, 'DESC');
- $expected_values = array_reverse(['Tom', 'xenu', 'thetans', 'Hubbard', 'FALSE', '2', '1977']);
+ $sorted_results = $this->processor->sortResults($this->originalResults, 'DESC');
+ $expected_values = array_reverse([
+ 'Tom',
+ 'xenu',
+ 'thetans',
+ 'Hubbard',
+ 'FALSE',
+ '2',
+ '1977',
+ ]);
foreach ($expected_values as $index => $value) {
$this->assertEquals($value, $sorted_results[$index]->getDisplayValue());
}
diff --git a/tests/src/Unit/Plugin/processor/UidToUserNameCallbackProcessorTest.php b/tests/src/Unit/Plugin/processor/UidToUserNameCallbackProcessorTest.php
index efa3174..38f371a 100644
--- a/tests/src/Unit/Plugin/processor/UidToUserNameCallbackProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/UidToUserNameCallbackProcessorTest.php
@@ -14,6 +14,8 @@ use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class UidToUserNameCallbackProcessorTest extends UnitTestCase {
@@ -38,7 +40,7 @@ class UidToUserNameCallbackProcessorTest extends UnitTestCase {
/**
- * Test that results were correctly changed
+ * Test that results were correctly changed.
*/
public function testResultsChanged() {
$original_results = [
@@ -69,21 +71,21 @@ class UidToUserNameCallbackProcessorTest extends UnitTestCase {
* Creates and sets up the container to be used in tests.
*/
protected function createMocks() {
- $userStorage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
- $entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
- $entityManager->expects($this->any())
+ $user_storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
+ $entity_manager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
+ $entity_manager->expects($this->any())
->method('getStorage')
- ->willReturn($userStorage);
+ ->willReturn($user_storage);
$user1 = $this->getMock('\Drupal\Core\Session\AccountInterface');
$user1->method('getDisplayName')
->willReturn('Admin');
- $userStorage->method('load')
+ $user_storage->method('load')
->willReturn($user1);
$container = new ContainerBuilder();
- $container->set('entity.manager', $entityManager);
+ $container->set('entity.manager', $entity_manager);
\Drupal::setContainer($container);
}
diff --git a/tests/src/Unit/Plugin/query_type/SearchApiStringTest.php b/tests/src/Unit/Plugin/query_type/SearchApiStringTest.php
index f49754c..cecd79f 100644
--- a/tests/src/Unit/Plugin/query_type/SearchApiStringTest.php
+++ b/tests/src/Unit/Plugin/query_type/SearchApiStringTest.php
@@ -5,7 +5,7 @@
* Contains \Drupal\Tests\facets\Plugin\query_string\SearchApiStringTest.
*/
-namespace Drupal\Tests\facets\Unit\Plugin\query_string;
+namespace Drupal\Tests\facets\Unit\Plugin\query_type;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Plugin\facets\query_type\SearchApiString;
@@ -13,9 +13,10 @@ use Drupal\search_api\Plugin\views\query\SearchApiQuery;
use Drupal\Tests\UnitTestCase;
/**
+ * Unit test for query type.
+ *
* @group facets
*/
-
class SearchApiStringTest extends UnitTestCase {
/**
diff --git a/tests/src/Unit/Plugin/widget/CheckboxWidgetTest.php b/tests/src/Unit/Plugin/widget/CheckboxWidgetTest.php
index 0dfa350..7b3c6c1 100644
--- a/tests/src/Unit/Plugin/widget/CheckboxWidgetTest.php
+++ b/tests/src/Unit/Plugin/widget/CheckboxWidgetTest.php
@@ -14,6 +14,8 @@ use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
+ * Unit test for widget.
+ *
* @group facets
*/
class CheckboxWidgetTest extends UnitTestCase {
@@ -30,7 +32,7 @@ class CheckboxWidgetTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -49,7 +51,7 @@ class CheckboxWidgetTest extends UnitTestCase {
foreach ($original_results as $original_result) {
$original_result->setUrl(new \Drupal\Core\Url('test'));
}
- $this->original_results = $original_results;
+ $this->originalResults = $original_results;
$link_generator = $this->getMockBuilder('\Drupal\Core\Utility\LinkGenerator')
->disableOriginalConstructor()
@@ -75,7 +77,7 @@ class CheckboxWidgetTest extends UnitTestCase {
*/
public function testDefaultSettings() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$output = $this->widget->build($facet);
@@ -93,7 +95,7 @@ class CheckboxWidgetTest extends UnitTestCase {
*/
public function testShowAmount() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->set('widget_configs', ['show_numbers' => 1]);
$output = $this->widget->build($facet);
diff --git a/tests/src/Unit/Plugin/widget/LinksWidgetTest.php b/tests/src/Unit/Plugin/widget/LinksWidgetTest.php
index 5159b64..2f26246 100644
--- a/tests/src/Unit/Plugin/widget/LinksWidgetTest.php
+++ b/tests/src/Unit/Plugin/widget/LinksWidgetTest.php
@@ -14,6 +14,8 @@ use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
+ * Unit test for widget.
+ *
* @group facets
*/
class LinksWidgetTest extends UnitTestCase {
@@ -30,7 +32,7 @@ class LinksWidgetTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -49,7 +51,7 @@ class LinksWidgetTest extends UnitTestCase {
foreach ($original_results as $original_result) {
$original_result->setUrl(new \Drupal\Core\Url('test'));
}
- $this->original_results = $original_results;
+ $this->originalResults = $original_results;
$link_generator = $this->getMockBuilder('\Drupal\Core\Utility\LinkGenerator')
->disableOriginalConstructor()
@@ -66,11 +68,11 @@ class LinksWidgetTest extends UnitTestCase {
}
/**
- * Test widget
+ * Test widget.
*/
public function testNoFilterResults() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->set('widget_configs', ['show_numbers' => 1]);
$output = $this->widget->build($facet);
@@ -85,10 +87,10 @@ class LinksWidgetTest extends UnitTestCase {
}
/**
- * Test widget
+ * Test widget.
*/
public function testHideEmptyCount() {
- $original_results = $this->original_results;
+ $original_results = $this->originalResults;
$original_results[1] = new Result('badger', 'Badger', 0);
$facet = new Facet([], 'facet');
@@ -107,10 +109,10 @@ class LinksWidgetTest extends UnitTestCase {
}
/**
- * Test widget
+ * Test widget.
*/
public function testActiveItems() {
- $original_results = $this->original_results;
+ $original_results = $this->originalResults;
$original_results[0]->setActiveState(TRUE);
$original_results[3]->setActiveState(TRUE);
@@ -123,7 +125,12 @@ class LinksWidgetTest extends UnitTestCase {
$this->assertInternalType('array', $output);
$this->assertCount(4, $output['#items']);
- $expected_links = ['(-) Llama (10)', 'Badger (20)', 'Duck (15)', '(-) Alpaca (9)'];
+ $expected_links = [
+ '(-) Llama (10)',
+ 'Badger (20)',
+ 'Duck (15)',
+ '(-) Alpaca (9)',
+ ];
foreach ($expected_links as $index => $value) {
$this->assertEquals($value, $output['#items'][$index]);
}
@@ -133,7 +140,7 @@ class LinksWidgetTest extends UnitTestCase {
* Test widget, make sure hiding and showing numbers works.
*/
public function testHideNumbers() {
- $original_results = $this->original_results;
+ $original_results = $this->originalResults;
$original_results[1]->setActiveState(TRUE);
$facet = new Facet([], 'facet');
@@ -159,11 +166,15 @@ class LinksWidgetTest extends UnitTestCase {
$this->assertInternalType('array', $output);
$this->assertCount(4, $output['#items']);
- $expected_links = ['Llama (10)', '(-) Badger (20)', 'Duck (15)', 'Alpaca (9)'];
+ $expected_links = [
+ 'Llama (10)',
+ '(-) Badger (20)',
+ 'Duck (15)',
+ 'Alpaca (9)',
+ ];
foreach ($expected_links as $index => $value) {
$this->assertEquals($value, $output['#items'][$index]);
}
}
}
-