LinkitKernelTestBase.php in Linkit 8.5
File
tests/src/Kernel/LinkitKernelTestBase.php
View source
<?php
namespace Drupal\Tests\linkit\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
abstract class LinkitKernelTestBase extends KernelTestBase {
public static $modules = [
'system',
'user',
'filter',
'text',
'linkit',
'linkit_test',
];
protected function setUp() {
parent::setUp();
$this
->installSchema('system', 'sequences');
$this
->installEntitySchema('user');
$this
->installConfig([
'filter',
]);
if ($this->container
->get('entity_type.manager')
->hasDefinition('path_alias')) {
$this
->installEntitySchema('path_alias');
}
}
protected function createUser(array $values = [], array $permissions = []) {
if ($permissions) {
$role = Role::create([
'id' => mb_strtolower($this
->randomMachineName(8)),
'label' => $this
->randomMachineName(8),
]);
$role
->save();
user_role_grant_permissions($role
->id(), $permissions);
$values['roles'][] = $role
->id();
}
$account = User::create($values + [
'name' => $this
->randomMachineName(),
'status' => 1,
]);
$account
->enforceIsNew();
$account
->save();
return $account;
}
}