function EntityReferenceRdfaTest::setUp

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

Overrides FieldKernelTestBase::setUp

File

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

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);
}

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