function FieldRenderedEntityTest::setUpFixtures

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/Handler/FieldRenderedEntityTest.php \Drupal\Tests\views\Kernel\Handler\FieldRenderedEntityTest::setUpFixtures()
  2. 8.9.x core/modules/views/tests/src/Kernel/Handler/FieldRenderedEntityTest.php \Drupal\Tests\views\Kernel\Handler\FieldRenderedEntityTest::setUpFixtures()
  3. 11.x core/modules/views/tests/src/Kernel/Handler/FieldRenderedEntityTest.php \Drupal\Tests\views\Kernel\Handler\FieldRenderedEntityTest::setUpFixtures()

Overrides ViewsKernelTestBase::setUpFixtures

File

core/modules/views/tests/src/Kernel/Handler/FieldRenderedEntityTest.php, line 47

Class

FieldRenderedEntityTest
Tests the core Drupal\views\Plugin\views\field\RenderedEntity handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

protected function setUpFixtures() {
    $this->installEntitySchema('user');
    $this->installEntitySchema('entity_test');
    $this->installConfig([
        'entity_test',
    ]);
    // 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();
    EntityViewMode::create([
        'id' => 'entity_test.foobar',
        'targetEntityType' => 'entity_test',
        'status' => TRUE,
        'enabled' => TRUE,
        'label' => 'My view mode',
    ])->save();
    $display = EntityViewDisplay::create([
        'targetEntityType' => 'entity_test',
        'bundle' => 'entity_test',
        'mode' => 'foobar',
        'label' => 'My view mode',
        'status' => TRUE,
    ]);
    $display->save();
    $field_storage = FieldStorageConfig::create([
        'field_name' => 'test_field',
        'entity_type' => 'entity_test',
        'type' => 'string',
    ]);
    $field_storage->save();
    $field_config = FieldConfig::create([
        'field_name' => 'test_field',
        'entity_type' => 'entity_test',
        'bundle' => 'entity_test',
    ]);
    $field_config->save();
    // Create some test entities.
    for ($i = 1; $i <= 3; $i++) {
        EntityTest::create([
            'name' => "Article title {$i}",
            'test_field' => "Test {$i}",
        ])->save();
    }
    Role::create([
        'id' => 'test_role',
        'label' => 'Can view test entities',
        'permissions' => [
            'view test entity',
        ],
    ])->save();
    $this->user = User::create([
        'name' => 'test user',
        'roles' => [
            'test_role',
        ],
    ]);
    $this->user
        ->save();
    parent::setUpFixtures();
}

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