protected function EntityAutocompleteElementFormTest::setUp in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::setUp()
- 9 core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::setUp()
File
- core/
tests/ Drupal/ KernelTests/ Core/ Entity/ Element/ EntityAutocompleteElementFormTest.php, line 47
Class
- EntityAutocompleteElementFormTest
- Tests the EntityAutocomplete Form API element.
Namespace
Drupal\KernelTests\Core\Entity\ElementCode
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('entity_test_string_id');
// Create user 1 so that the user created later in the test has a different
// user ID.
// @todo Remove in https://www.drupal.org/node/540008.
User::create([
'uid' => 1,
'name' => 'user1',
])
->save();
Role::create([
'id' => 'test_role',
'label' => 'Can view test entities',
'permissions' => [
'view test entity',
],
])
->save();
$this->testUser = User::create([
'name' => 'foobar1',
'mail' => 'foobar1@example.com',
'roles' => [
'test_role',
],
]);
$this->testUser
->save();
\Drupal::service('current_user')
->setAccount($this->testUser);
$this->testAutocreateUser = User::create([
'name' => 'foobar2',
'mail' => 'foobar2@example.com',
]);
$this->testAutocreateUser
->save();
for ($i = 1; $i < 3; $i++) {
$entity = EntityTest::create([
'name' => $this
->randomMachineName(),
]);
$entity
->save();
$this->referencedEntities[] = $entity;
}
// Use special characters in the ID of some of the test entities so we can
// test if these are handled correctly.
for ($i = 0; $i < 2; $i++) {
$entity = EntityTestStringId::create([
'name' => $this
->randomMachineName(),
'id' => $this
->randomMachineName() . '&</\\:?',
]);
$entity
->save();
$this->referencedEntities[] = $entity;
}
}