You are here

public function CollectionRouteAccessTest::testCollectionRouteAccess in Entity API 8

Test the collection route access.

File

tests/src/Functional/CollectionRouteAccessTest.php, line 47

Class

CollectionRouteAccessTest
Tests the collection route access check.

Namespace

Drupal\Tests\entity\Functional

Code

public function testCollectionRouteAccess() {
  $entity = EnhancedEntity::create([
    'name' => 'rev 1',
    'type' => 'default',
  ]);
  $entity
    ->save();

  // User without any relevant permissions.
  $account = $this
    ->drupalCreateUser([
    'access administration pages',
  ]);
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet($entity
    ->toUrl('collection'));
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // User with "access overview" permissions.
  $account = $this
    ->drupalCreateUser([
    'access entity_test_enhanced overview',
  ]);
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet($entity
    ->toUrl('collection'));
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // User with full administration permissions.
  $account = $this
    ->drupalCreateUser([
    'administer entity_test_enhanced',
  ]);
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet($entity
    ->toUrl('collection'));
  $this
    ->assertSession()
    ->statusCodeEquals(200);
}