public function GroupRoleSynchronizationTest::testConfigImport in Group 2.0.x
Same name and namespace in other branches
- 8 tests/src/Kernel/GroupRoleSynchronizationTest.php \Drupal\Tests\group\Kernel\GroupRoleSynchronizationTest::testConfigImport()
Tests whether an imported group type receives synchronized group roles.
@covers \Drupal\group\Entity\Storage\GroupRoleStorage::createSynchronized @uses \Drupal\group\EventSubscriber\ConfigSubscriber::onConfigImport
File
- tests/
src/ Kernel/ GroupRoleSynchronizationTest.php, line 146
Class
- GroupRoleSynchronizationTest
- Tests whether group roles are actually synchronized.
Namespace
Drupal\Tests\group\KernelCode
public function testConfigImport() {
$role = $this
->createUserRole('editor');
// The system.site key is required for import validation.
// See: https://www.drupal.org/project/drupal/issues/2995062
$this
->installConfig([
'system',
]);
// Simulate config data to import.
$active = $this->container
->get('config.storage');
$sync = $this->container
->get('config.storage.sync');
$this
->copyConfig($active, $sync);
// Manually add the 'import' group type to the synchronization directory.
$test_dir = __DIR__ . '/../../modules/group_test_config/sync';
$sync_dir = Settings::get('config_sync_directory');
$file_system = $this->container
->get('file_system');
$file_system
->copy("{$test_dir}/group.type.import.yml", "{$sync_dir}/group.type.import.yml");
$file_system
->copy("{$test_dir}/user.role.import.yml", "{$sync_dir}/user.role.import.yml");
$file_system
->copy("{$test_dir}/group.role.import-eea2d6f47.yml", "{$sync_dir}/group.role.import-eea2d6f47.yml");
// Import the content of the sync directory.
$this
->configImporter()
->import();
// Check that the synchronized group roles give priority to the Yaml files.
$group_role_id = $this->groupRoleSynchronizer
->getGroupRoleId('import', 'import');
/** @var \Drupal\group\Entity\GroupRoleInterface $from_yaml */
$from_yaml = $this->entityTypeManager
->getStorage('group_role')
->load($group_role_id);
$this
->assertEquals([
'view group',
], $from_yaml
->getPermissions(), 'Synchronized role was created from Yaml file.');
// Check that synchronized group roles are being created without Yaml files.
$group_roles = $this->entityTypeManager
->getStorage('group_role')
->loadMultiple();
$group_role_id = $this->groupRoleSynchronizer
->getGroupRoleId('import', $role
->id());
$this
->assertArrayHasKey($group_role_id, $group_roles, 'Synchronized role found for imported group type');
}