You are here

public function MigrateUserRoleTest::testUserRole in Drupal 10

Same name in this branch
  1. 10 core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserRoleTest.php \Drupal\Tests\user\Kernel\Migrate\d6\MigrateUserRoleTest::testUserRole()
  2. 10 core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserRoleTest.php \Drupal\Tests\user\Kernel\Migrate\d7\MigrateUserRoleTest::testUserRole()
Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserRoleTest.php \Drupal\Tests\user\Kernel\Migrate\d6\MigrateUserRoleTest::testUserRole()
  2. 9 core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserRoleTest.php \Drupal\Tests\user\Kernel\Migrate\d6\MigrateUserRoleTest::testUserRole()

Tests user role migration.

File

core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserRoleTest.php, line 122

Class

MigrateUserRoleTest
Upgrade user roles to user.role.*.yml.

Namespace

Drupal\Tests\user\Kernel\Migrate\d6

Code

public function testUserRole() {
  $id_map = $this
    ->getMigration('d6_user_role')
    ->getIdMap();
  $this
    ->assertRoles($id_map);

  // Test there are no duplicated roles.
  $roles = [
    'anonymous1',
    'authenticated1',
    'administrator1',
    'migrate_test_role_11',
    'migrate_test_role_21',
    'migrate_test_role_3_that_is_longer_than_thirty_two_characters1',
  ];
  $this
    ->assertEmpty(Role::loadMultiple($roles));

  // Remove the map row for the migrate_test_role_1 role and rerun the
  // migration. This will re-import the migrate_test_role_1 role migration
  // again.
  $this->sourceDatabase
    ->insert('role')
    ->fields([
    'rid' => 6,
    'name' => 'migrate test role 4',
  ])
    ->execute();
  $this->sourceDatabase
    ->insert('permission')
    ->fields([
    'pid' => 7,
    'rid' => 6,
    'perm' => 'access content',
    'tid' => 0,
  ])
    ->execute();
  $id_map
    ->delete([
    'rid' => 3,
  ]);
  $this
    ->executeMigration('d6_user_role');

  // Test there are no duplicated roles.
  $roles[] = 'migrate_test_role_41';
  $this
    ->assertEmpty(Role::loadMultiple($roles));

  // Test that the existing roles have not changed.
  $this
    ->assertRoles($id_map);

  // Test the migration of the new role, migrate_test_role_4.
  $permissions = [
    'access content',
  ];
  $this
    ->assertRole('migrate_test_role_4', $permissions, 6, $id_map);
}