function MigrateUserRoleTest::testUserRole

Same name in this branch
  1. 9 core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserRoleTest.php \Drupal\Tests\user\Kernel\Migrate\d7\MigrateUserRoleTest::testUserRole()
Same name in other branches
  1. 8.9.x core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserRoleTest.php \Drupal\Tests\user\Kernel\Migrate\d6\MigrateUserRoleTest::testUserRole()
  2. 8.9.x core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserRoleTest.php \Drupal\Tests\user\Kernel\Migrate\d7\MigrateUserRoleTest::testUserRole()
  3. 10 core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserRoleTest.php \Drupal\Tests\user\Kernel\Migrate\d6\MigrateUserRoleTest::testUserRole()
  4. 10 core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserRoleTest.php \Drupal\Tests\user\Kernel\Migrate\d7\MigrateUserRoleTest::testUserRole()
  5. 11.x core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserRoleTest.php \Drupal\Tests\user\Kernel\Migrate\d6\MigrateUserRoleTest::testUserRole()
  6. 11.x core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserRoleTest.php \Drupal\Tests\user\Kernel\Migrate\d7\MigrateUserRoleTest::testUserRole()

Tests user role migration.

File

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

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.