You are here

protected function EntityReferenceKernelTest::setUp in Entity Usage 8

Overrides EntityKernelTestBase::setUp

File

tests/src/Kernel/EntityReferenceKernelTest.php, line 84

Class

EntityReferenceKernelTest
Tests basic usage tracking on generic entities.

Namespace

Drupal\Tests\entity_usage\Kernel

Code

protected function setUp() {
  parent::setUp();
  $this->injectedDatabase = $this->container
    ->get('database');
  $this
    ->installSchema('entity_usage', [
    'entity_usage',
  ]);
  $this->tableName = 'entity_usage';
  $this
    ->createEntityReferenceField($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->entityType, 'default', [], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);

  // Set up an additional field.
  FieldStorageConfig::create([
    'field_name' => 'body',
    'entity_type' => $this->entityType,
    'type' => 'text',
    'settings' => array(),
  ])
    ->save();
  FieldConfig::create([
    'entity_type' => $this->entityType,
    'bundle' => $this->bundle,
    'field_name' => 'body',
    'label' => 'Body',
  ])
    ->save();
  FilterFormat::create([
    'format' => 'full_html',
    'name' => 'Full HTML',
  ])
    ->save();

  // Create the entity to be referenced.
  $this->referencedEntity = $this->container
    ->get('entity_type.manager')
    ->getStorage($this->entityType)
    ->create([
    'name' => $this
      ->randomMachineName(),
  ]);
  $this->referencedEntity
    ->save();

  // Create two test entities.
  $this->testEntities = $this
    ->getTestEntities();
  $this->testEntities[0]->body = [
    'value' => '<p>Lorem ipsum 1</p>',
    'format' => 'full_html',
  ];
  $this->testEntities[0]
    ->save();
  $this->testEntities[1]->body = [
    'value' => '<p>Lorem ipsum 2</p>',
    'format' => 'full_html',
  ];
  $this->testEntities[1]
    ->save();
}