You are here

class UrlProcessorHandlerTest in Facets 8

Unit test for processor.

@group facets

Hierarchy

Expanded class hierarchy of UrlProcessorHandlerTest

File

tests/src/Unit/Plugin/processor/UrlProcessorHandlerTest.php, line 20

Namespace

Drupal\Tests\facets\Unit\Plugin\processor
View source
class UrlProcessorHandlerTest extends UnitTestCase {

  /**
   * Tests that the processor correctly throws an exception.
   */
  public function testEmptyProcessorConfiguration() {
    $this
      ->expectException(InvalidProcessorException::class);
    $this
      ->expectExceptionMessage("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
      ->expectException(InvalidProcessorException::class);
    $this
      ->expectExceptionMessage("The UrlProcessorHandler doesn't have the required 'facet' in the configuration array.");
    new UrlProcessorHandler([
      'facet' => new \stdClass(),
    ], 'test', []);
  }

  /**
   * Tests 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, []);
  }

  /**
   * 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.
   */
  protected function createContainer() {
    $url_processor = $this
      ->getMockBuilder(UrlProcessorInterface::class)
      ->disableOriginalConstructor()
      ->getMock();
    $manager = $this
      ->getMockBuilder(FacetSourcePluginManager::class)
      ->disableOriginalConstructor()
      ->getMock();
    $manager
      ->expects($this
      ->exactly(1))
      ->method('createInstance')
      ->willReturn($url_processor);
    $storage = $this
      ->createMock(EntityStorageInterface::class);
    $em = $this
      ->getMockBuilder(EntityTypeManagerInterface::class)
      ->disableOriginalConstructor()
      ->getMock();
    $em
      ->expects($this
      ->exactly(1))
      ->method('getStorage')
      ->willReturn($storage);
    $container = new ContainerBuilder();
    $container
      ->set('entity_type.manager', $em);
    $container
      ->set('plugin.manager.facets.url_processor', $manager);
    \Drupal::setContainer($container);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340
UrlProcessorHandlerTest::createContainer protected function Sets up a container.
UrlProcessorHandlerTest::testBuild public function Tests that the build method is correctly called.
UrlProcessorHandlerTest::testConfiguration public function Tests configuration.
UrlProcessorHandlerTest::testDescription public function Tests testDescription().
UrlProcessorHandlerTest::testEmptyProcessorConfiguration public function Tests that the processor correctly throws an exception.
UrlProcessorHandlerTest::testInvalidProcessorConfiguration public function Tests that the processor correctly throws an exception.
UrlProcessorHandlerTest::testIsHidden public function Tests isHidden().
UrlProcessorHandlerTest::testIsLocked public function Tests isLocked().