You are here

protected function EntityReferenceRdfaTest::setUp in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/rdf/tests/src/Kernel/Field/EntityReferenceRdfaTest.php \Drupal\Tests\rdf\Kernel\Field\EntityReferenceRdfaTest::setUp()

Set the default field storage backend for fields created during tests.

Overrides FieldKernelTestBase::setUp

File

core/modules/rdf/tests/src/Kernel/Field/EntityReferenceRdfaTest.php, line 49

Class

EntityReferenceRdfaTest
Tests the RDFa output of the entity reference field formatter.

Namespace

Drupal\Tests\rdf\Kernel\Field

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installEntitySchema('entity_test_rev');

  // Give anonymous users permission to view test entities.
  $this
    ->installConfig([
    'user',
  ]);
  Role::load(RoleInterface::ANONYMOUS_ID)
    ->grantPermission('view test entity')
    ->save();
  $this
    ->createEntityReferenceField($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->entityType);

  // Add the mapping.
  $mapping = rdf_get_mapping('entity_test', 'entity_test');
  $mapping
    ->setFieldMapping($this->fieldName, [
    'properties' => [
      'schema:knows',
    ],
  ])
    ->save();

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

  // Create the entity that will have the entity reference field.
  $this->entity = $this->container
    ->get('entity_type.manager')
    ->getStorage($this->entityType)
    ->create([
    'name' => $this
      ->randomMachineName(),
  ]);
  $this->entity
    ->save();
  $this->entity->{$this->fieldName}->entity = $this->targetEntity;
  $this->uri = $this
    ->getAbsoluteUri($this->entity);
}