You are here

public function RolesTest::testRoles in Lightning Media 8

Same name and namespace in other branches
  1. 8.4 tests/src/Functional/RolesTest.php \Drupal\Tests\lightning_media\Functional\RolesTest::testRoles()
  2. 8.2 tests/src/Functional/RolesTest.php \Drupal\Tests\lightning_media\Functional\RolesTest::testRoles()
  3. 8.3 tests/src/Functional/RolesTest.php \Drupal\Tests\lightning_media\Functional\RolesTest::testRoles()

File

tests/src/Functional/RolesTest.php, line 52

Class

RolesTest
@group lightning @group lightning_media

Namespace

Drupal\Tests\lightning_media\Functional

Code

public function testRoles() {
  $account = $this
    ->drupalCreateUser();
  $account
    ->addRole('media_creator');
  $account
    ->save();
  $this
    ->drupalLogin($account);
  $media = Media::create([
    'bundle' => $this->mediaType,
    'name' => $this
      ->getRandomGenerator()
      ->word(16),
    'uid' => $account
      ->id(),
  ]);
  $media
    ->setPublished();
  $media
    ->save();
  $assert = $this
    ->assertSession();
  $this
    ->drupalGet('/admin/content/media');
  $this
    ->clickLink($media
    ->label());
  $assert
    ->statusCodeEquals(200);
  $assert
    ->linkExists('Edit');
  $assert
    ->linkExists('Delete');
  $this
    ->drupalLogout();
  $account = $this
    ->drupalCreateUser();
  $account
    ->addRole('media_manager');
  $account
    ->save();
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('/admin/content/media');
  $this
    ->clickLink($media
    ->label());
  $assert
    ->statusCodeEquals(200);
  $assert
    ->linkExists('Edit');
  $assert
    ->linkExists('Delete');
}