You are here

public function RouteGroupCacheContextTest::testGetContextOnGroupAddForm in Group 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Unit/RouteGroupCacheContextTest.php \Drupal\Tests\group\Unit\RouteGroupCacheContextTest::testGetContextOnGroupAddForm()

Tests getting the context value when on the group add form route.

@covers ::getContext

File

tests/src/Unit/RouteGroupCacheContextTest.php, line 78

Class

RouteGroupCacheContextTest
Tests the route.group cache context.

Namespace

Drupal\Tests\group\Unit

Code

public function testGetContextOnGroupAddForm() {
  $group = $this
    ->prophesize(GroupInterface::class);
  $group
    ->id()
    ->willReturn(NULL);
  $group
    ->bundle()
    ->willReturn('foo');
  $group_type = $this
    ->prophesize(GroupTypeInterface::class);
  $group_type
    ->id()
    ->willReturn('foo');
  $this->currentRouteMatch
    ->getParameter('group')
    ->willReturn(NULL);
  $this->currentRouteMatch
    ->getParameter('group_type')
    ->willReturn($group_type
    ->reveal());
  $this->currentRouteMatch
    ->getRouteName()
    ->willReturn('entity.group.add_form');
  $storage = $this
    ->prophesize(ContentEntityStorageInterface::class);
  $storage
    ->create([
    'type' => 'foo',
  ])
    ->willReturn($group
    ->reveal());
  $this->entityTypeManager
    ->getStorage('group')
    ->willReturn($storage
    ->reveal());
  $cache_context = new RouteGroupCacheContext($this->currentRouteMatch
    ->reveal(), $this->entityTypeManager
    ->reveal());
  $this
    ->assertSame('foo', $cache_context
    ->getContext());
}