summaryrefslogtreecommitdiffstats
path: root/tests/src/Unit/Plugin
diff options
context:
space:
mode:
authorJoris Vercammen2015-11-17 13:36:33 (GMT)
committerJoris Vercammen2015-11-17 13:36:33 (GMT)
commitc3cf0717a53ab176e40d0e4c541d8509b4dbf85b (patch)
treeb16a5eb574c97e9201f7141cd5c4a4f14b913a22 /tests/src/Unit/Plugin
parent8027f9437d43b9a6fe46c941f0d6c27d53c193d9 (diff)
Issue #2616590 by borisson_: Uid to username processor (Build processor) for users
Diffstat (limited to 'tests/src/Unit/Plugin')
-rw-r--r--tests/src/Unit/Plugin/processor/UidToUserNameCallbackProcessorTest.php90
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/src/Unit/Plugin/processor/UidToUserNameCallbackProcessorTest.php b/tests/src/Unit/Plugin/processor/UidToUserNameCallbackProcessorTest.php
new file mode 100644
index 0000000..88d2e4b
--- /dev/null
+++ b/tests/src/Unit/Plugin/processor/UidToUserNameCallbackProcessorTest.php
@@ -0,0 +1,90 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\facetapi\Plugin\Processor\UidToUserNameCallbackProcessorTest.
+ */
+
+namespace Drupal\Tests\facetapi\Unit\Plugin\Processor;
+
+use Drupal\facetapi\Entity\Facet;
+use Drupal\facetapi\Plugin\facetapi\processor\UidToUserNameCallbackProcessor;
+use Drupal\facetapi\Result\Result;
+use Drupal\Tests\UnitTestCase;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+
+/**
+ * @group facetapi
+ */
+class UidToUserNameCallbackProcessorTest extends UnitTestCase {
+
+ /**
+ * The processor to be tested.
+ *
+ * @var \Drupal\facetapi\processor\WidgetOrderProcessorInterface
+ */
+ protected $processor;
+
+ /**
+ * Creates a new processor object for use in the tests.
+ */
+ protected function setUp() {
+ parent::setUp();
+
+ $this->processor = new UidToUserNameCallbackProcessor([], 'uid_to_username_callback', []);
+
+ $this->createMocks();
+ }
+
+
+ /**
+ * Test that results were correctly changed
+ */
+ public function testResultsChanged() {
+ $original_results = [
+ new Result(1, 1, 5),
+ ];
+
+ $facet = new Facet([], 'facet');
+ $facet->setResults($original_results);
+
+ $expected_results = [
+ ['uid' => 1, 'name' => 'Admin'],
+ ];
+
+ foreach ($expected_results as $key => $expected) {
+ $this->assertEquals($expected['uid'], $original_results[$key]->getRawValue());
+ $this->assertEquals($expected['uid'], $original_results[$key]->getDisplayValue());
+ }
+
+ $filtered_results = $this->processor->build($facet, $original_results);
+
+ foreach ($expected_results as $key => $expected) {
+ $this->assertEquals($expected['uid'], $filtered_results[$key]->getRawValue());
+ $this->assertEquals($expected['name'], $filtered_results[$key]->getDisplayValue());
+ }
+ }
+
+ /**
+ * 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())
+ ->method('getStorage')
+ ->willReturn($userStorage);
+
+ $user1 = $this->getMock('\Drupal\Core\Session\AccountInterface');
+ $user1->method('getDisplayName')
+ ->willReturn('Admin');
+
+ $userStorage->method('load')
+ ->willReturn($user1);
+
+ $container = new ContainerBuilder();
+ $container->set('entity.manager', $entityManager);
+ \Drupal::setContainer($container);
+ }
+
+}