EntityReferenceRdfaTest.php in Drupal 9
File
core/modules/rdf/tests/src/Kernel/Field/EntityReferenceRdfaTest.php
View source
<?php
namespace Drupal\Tests\rdf\Kernel\Field;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
class EntityReferenceRdfaTest extends FieldRdfaTestBase {
use EntityReferenceTestTrait;
protected $fieldType = 'entity_reference';
protected $entityType = 'entity_test';
protected $bundle = 'entity_test';
protected $targetEntity;
protected static $modules = [
'text',
'filter',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('entity_test_rev');
$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);
$mapping = rdf_get_mapping('entity_test', 'entity_test');
$mapping
->setFieldMapping($this->fieldName, [
'properties' => [
'schema:knows',
],
])
->save();
$this->targetEntity = $this->container
->get('entity_type.manager')
->getStorage($this->entityType)
->create([
'name' => $this
->randomMachineName(),
]);
$this->targetEntity
->save();
$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);
}
public function testAllFormatters() {
$entity_uri = $this
->getAbsoluteUri($this->targetEntity);
$this
->assertFormatterRdfa([
'type' => 'entity_reference_label',
], 'http://schema.org/knows', [
'value' => $entity_uri,
'type' => 'uri',
]);
$this
->assertFormatterRdfa([
'type' => 'entity_reference_entity_view',
], 'http://schema.org/knows', [
'value' => $entity_uri,
'type' => 'uri',
]);
}
}