You are here

protected function RenderedEntityTest::setUpFixtures in Entity API 8.0

Sets up the configuration and schema of views and views_test_data modules.

Because the schema of views_test_data.module is dependent on the test using it, it cannot be enabled normally.

Overrides ViewKernelTestBase::setUpFixtures

File

src/Tests/Plugin/views/field/RenderedEntityTest.php, line 64
Contains \Drupal\entity\Tests\Plugin\views\field\RenderedEntityTest.

Class

RenderedEntityTest
Tests the Drupal\entity\Plugin\views\field\RenderedEntity handler.

Namespace

Drupal\entity\Tests\Plugin\views\field

Code

protected function setUpFixtures() {
  $this
    ->installEntitySchema('user');
  $this
    ->installEntitySchema('entity_test');
  $this
    ->installConfig([
    'entity_test',
  ]);
  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 = Role::create([
    'id' => 'test_role',
  ]);
  $role
    ->grantPermission('bypass node access');
  $role
    ->save();
  $this->user = User::create([
    'name' => 'test user',
  ]);
  $this->user
    ->addRole($role
    ->id());
  $this->user
    ->save();
  parent::setUpFixtures();
}