You are here

public function EntityCloneRoleTest::testRoleEntityClone in Entity Clone 8

Test role entity clone.

File

tests/src/Functional/EntityCloneRoleTest.php, line 58

Class

EntityCloneRoleTest
Create a role and test a clone.

Namespace

Drupal\Tests\entity_clone\Functional

Code

public function testRoleEntityClone() {
  $edit = [
    'label' => 'Test role for clone',
    'id' => 'test_role_for_clone',
  ];
  $this
    ->drupalPostForm("/admin/people/roles/add", $edit, t('Save'));
  $roles = \Drupal::entityTypeManager()
    ->getStorage('user_role')
    ->loadByProperties([
    'id' => $edit['id'],
  ]);
  $role = reset($roles);
  $edit = [
    'id' => 'test_role_cloned',
    'label' => 'Test role cloned',
  ];
  $this
    ->drupalPostForm('entity_clone/user_role/' . $role
    ->id(), $edit, t('Clone'));
  $roles = \Drupal::entityTypeManager()
    ->getStorage('user_role')
    ->loadByProperties([
    'id' => $edit['id'],
  ]);
  $role = reset($roles);
  $this
    ->assertInstanceOf(Role::class, $role, 'Test role cloned found in database.');
}