function MigrateUserRoleTest::testUserRole

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

Tests user role migration.

@dataProvider providerTestUserRole

Parameters

string[] $modules: A list of modules to install.

string[] $migrations: A list of migrations to execute.

string[][] $role_data: An array of role data keyed by the destination role id. The role data contains the source role id, an array of valid permissions and an array of invalid permissions.

File

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

Class

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

Namespace

Drupal\Tests\user\Kernel\Migrate\d6

Code

public function testUserRole(array $modules, array $migrations, array $role_data) : void {
    if ($modules) {
        // Install modules that have migrations that may provide permissions.
        \Drupal::service('module_installer')->install($modules);
        $this->installEntitySchema('block_content');
        $this->installConfig([
            'block_content',
            'comment',
        ]);
        $this->migrateContentTypes();
    }
    $this->executeMigrations($migrations);
    $id_map = $this->getMigration('d6_user_role')
        ->getIdMap();
    // After all the migrations are run, there are changes to the permissions.
    $this->assertRoles($role_data, $id_map);
    $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));
    $this->assertMessages($role_data, $id_map);
    $this->assertSame(4, $id_map->messageCount());
    // 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.
    $this->assertNoDuplicateRoles();
    // Test that the existing roles have not changed.
    $this->assertRoles($role_data, $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.