You are here

protected function QueryStringTest::setContainer in Facets 8

Sets up a container.

1 call to QueryStringTest::setContainer()
QueryStringTest::setUp in tests/src/Unit/Plugin/url_processor/QueryStringTest.php
Creates a new processor object for use in the tests.

File

tests/src/Unit/Plugin/url_processor/QueryStringTest.php, line 406

Class

QueryStringTest
Unit test for processor.

Namespace

Drupal\Tests\facets\Unit\Plugin\url_processor

Code

protected function setContainer() {
  $router = $this
    ->getMockBuilder(TestRouterInterface::class)
    ->disableOriginalConstructor()
    ->getMock();
  $router
    ->expects($this
    ->any())
    ->method('matchRequest')
    ->willReturn([
    '_raw_variables' => new ParameterBag([]),
    '_route' => 'test',
  ]);
  $validator = $this
    ->createMock(PathValidatorInterface::class);
  $fsi = $this
    ->getMockBuilder(FacetSourcePluginInterface::class)
    ->disableOriginalConstructor()
    ->getMock();
  $fsi
    ->method('getPath')
    ->willReturn('/test');
  $manager = $this
    ->getMockBuilder(FacetSourcePluginManager::class)
    ->disableOriginalConstructor()
    ->getMock();
  $manager
    ->method('createInstance')
    ->willReturn($fsi);
  $manager
    ->method('hasDefinition')
    ->with('facet_source__dummy')
    ->willReturn(TRUE);
  $facetentity = $this
    ->getMockBuilder(Facet::class)
    ->disableOriginalConstructor()
    ->getMock();
  $facetentity
    ->method('id')
    ->willReturn('king');
  $storage = $this
    ->createMock(EntityStorageInterface::class);
  $storage
    ->expects($this
    ->any())
    ->method('loadByProperties')
    ->willReturn([
    $facetentity,
  ]);
  $em = $this
    ->getMockBuilder(EntityTypeManagerInterface::class)
    ->disableOriginalConstructor()
    ->getMock();
  $em
    ->expects($this
    ->any())
    ->method('getStorage')
    ->willReturn($storage);
  $this->entityManager = $em;
  $container = new ContainerBuilder();
  $container
    ->set('router.no_access_checks', $router);
  $container
    ->set('plugin.manager.facets.facet_source', $manager);
  $container
    ->set('entity_type.manager', $em);
  $container
    ->set('path.validator', $validator);
  \Drupal::setContainer($container);
}