installEntitySchema('user'); $this->installEntitySchema('comment'); $this->installConfig(['user']); $entity_manager = $this->container->get('entity.manager'); $this->commentStorage = $entity_manager->getStorage('comment'); $this->userStorage = $entity_manager->getStorage('user'); // Insert a row for the anonymous user. $this->userStorage ->create([ 'uid' => 0, 'name' => '', 'status' => 0, ]) ->save(); $admin_role = Role::create(['id' => 'admin']); $admin_role->grantPermission('administer comments'); $admin_role->save(); /* @var \Drupal\user\RoleInterface $anonymous_role */ $anonymous_role = Role::load(Role::ANONYMOUS_ID); $anonymous_role->grantPermission('access comments'); $anonymous_role->save(); $this->adminUser = $this->userStorage->create(['name' => $this->randomMachineName()]); $this->adminUser->addRole('admin'); $this->adminUser->save(); } }