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. 10 core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::setUp()
  3. 11.x 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 46

Class

EntityAutocompleteElementFormTest
Tests the EntityAutocomplete Form API element.

Namespace

Drupal\KernelTests\Core\Entity\Element

Code

protected function setUp() {
    parent::setUp();
    $this->installSchema('system', [
        'key_value_expire',
    ]);
    $this->installEntitySchema('entity_test_string_id');
    \Drupal::service('router.builder')->rebuild();
    $this->testUser = User::create([
        'name' => 'foobar1',
        'mail' => 'foobar1@example.com',
    ]);
    $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;
    }
}

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