You are here

protected function OgAdminRoutesControllerTest::setUp in Organic groups 8

Overrides UnitTestCase::setUp

File

tests/src/Unit/OgAdminRoutesControllerTest.php, line 108

Class

OgAdminRoutesControllerTest
Tests the OG admin routes overview route.

Namespace

Drupal\Tests\og\Unit

Code

protected function setUp() : void {
  $this->accessManager = $this
    ->prophesize(AccessManagerInterface::class);
  $this->routeMatch = $this
    ->prophesize(RouteMatchInterface::class);
  $this->group = $this
    ->prophesize(EntityInterface::class);
  $this->event = $this
    ->prophesize(OgAdminRoutesEvent::class);
  $this->eventDispatcher = $this
    ->prophesize(ContainerAwareEventDispatcher::class);
  $this->route = $this
    ->prophesize(Route::class);
  $this->entityTypeId = $this
    ->randomMachineName();
  $this->entityId = rand(20, 30);
  $this->url = $this
    ->prophesize(Url::class);
  $this->routesInfo = [
    $this
      ->randomMachineName() => [
      'title' => $this
        ->randomMachineName(),
      'description' => $this
        ->randomMachineName(),
    ],
    $this
      ->randomMachineName() => [
      'title' => $this
        ->randomMachineName(),
      'description' => $this
        ->randomMachineName(),
    ],
  ];
  $this->routeMatch
    ->getRouteObject()
    ->willReturn($this->route);
  $parameter_name = $this
    ->randomMachineName();
  $this->route
    ->getOption('_og_entity_type_id')
    ->willReturn($parameter_name);
  $this->routeMatch
    ->getParameter($parameter_name)
    ->willReturn($this->group
    ->reveal());
  $this->group
    ->getEntityTypeId()
    ->willReturn($this->entityTypeId);
  $this->group
    ->id()
    ->willReturn($this->entityId);
  $this->eventDispatcher
    ->dispatch(OgAdminRoutesEventInterface::EVENT_NAME, Argument::type(OgAdminRoutesEvent::class))
    ->willReturn($this->event
    ->reveal())
    ->shouldBeCalled();
  $this->event
    ->getRoutes($this->entityTypeId)
    ->willReturn($this->routesInfo)
    ->shouldBeCalled();

  // Set the container for the string translation service.
  $translation = $this
    ->getStringTranslationStub();
  $container = new ContainerBuilder();
  $container
    ->set('access_manager', $this->accessManager
    ->reveal());
  $container
    ->set('string_translation', $translation);
  \Drupal::setContainer($container);
}