You are here

public function EntityBrowserTest::testViewWidgetAccess in Entity Browser 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/Extension/EntityBrowserTest.php \Drupal\Tests\entity_browser\Kernel\Extension\EntityBrowserTest::testViewWidgetAccess()

Tests view widget access.

File

tests/src/Kernel/Extension/EntityBrowserTest.php, line 473

Class

EntityBrowserTest
Tests the entity_browser config entity.

Namespace

Drupal\Tests\entity_browser\Kernel\Extension

Code

public function testViewWidgetAccess() {
  $this
    ->installConfig([
    'entity_browser_test',
  ]);
  $this
    ->installEntitySchema('user');
  $this
    ->installEntitySchema('user_role');

  /** @var \Drupal\entity_browser\EntityBrowserInterface $entity */
  $entity = $this->controller
    ->load('test_entity_browser_file');
  $this
    ->assertFalse($entity
    ->getWidget('774798f1-5ec5-4b63-84bd-124cd51ec07d')
    ->access()
    ->isAllowed());

  // Create a user that has permission to access the view and try with it.

  /** @var \Drupal\user\RoleInterface $role */
  $role = $this->container
    ->get('entity_type.manager')
    ->getStorage('user_role')
    ->create([
    'name' => $this
      ->randomString(),
    'id' => $this
      ->randomMachineName(),
  ]);
  $role
    ->grantPermission('access content');
  $role
    ->save();
  $user = $this->container
    ->get('entity_type.manager')
    ->getStorage('user')
    ->create([
    'name' => $this
      ->randomString(),
    'mail' => 'info@example.com',
    'roles' => $role
      ->id(),
  ]);
  $user
    ->save();
  \Drupal::currentUser()
    ->setAccount($user);
  $this
    ->assertTrue($entity
    ->getWidget('774798f1-5ec5-4b63-84bd-124cd51ec07d')
    ->access()
    ->isAllowed());
}