function EntityAutocompleteElementFormTest::setUp

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::setUp()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::setUp()
  3. 10 core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::setUp()

Overrides EntityKernelTestBase::setUp

File

core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php, line 49

Class

EntityAutocompleteElementFormTest
Tests the EntityAutocomplete Form API element.

Namespace

Drupal\KernelTests\Core\Entity\Element

Code

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;
    }
    $entity = EntityTest::create([
        'name' => '0',
    ]);
    $entity->save();
    $this->referencedEntities[] = $entity;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.