class EntityReferenceRdfaTest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/rdf/tests/src/Kernel/Field/EntityReferenceRdfaTest.php \Drupal\Tests\rdf\Kernel\Field\EntityReferenceRdfaTest
- 9 core/modules/rdf/tests/src/Kernel/Field/EntityReferenceRdfaTest.php \Drupal\Tests\rdf\Kernel\Field\EntityReferenceRdfaTest
Tests the RDFa output of the entity reference field formatter.
@group rdf
Hierarchy
- class \Drupal\Tests\rdf\Kernel\Field\FieldRdfaTestBase extends \Drupal\Tests\field\Kernel\FieldKernelTestBase uses RdfParsingTrait
- class \Drupal\Tests\rdf\Kernel\Field\EntityReferenceRdfaTest uses EntityReferenceTestTrait
Expanded class hierarchy of EntityReferenceRdfaTest
File
- core/
modules/ rdf/ tests/ src/ Kernel/ Field/ EntityReferenceRdfaTest.php, line 14
Namespace
Drupal\Tests\rdf\Kernel\FieldView source
class EntityReferenceRdfaTest extends FieldRdfaTestBase {
use EntityReferenceTestTrait;
/**
* {@inheritdoc}
*/
protected $fieldType = 'entity_reference';
/**
* The entity type used in this test.
*
* @var string
*/
protected $entityType = 'entity_test';
/**
* The bundle used in this test.
*
* @var string
*/
protected $bundle = 'entity_test';
/**
* The term for testing.
*
* @var \Drupal\taxonomy\Entity\Term
*/
protected $targetEntity;
/**
* {@inheritdoc}
*/
protected static $modules = [
'text',
'filter',
];
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);
}
/**
* Tests all the entity reference formatters.
*/
public function testAllFormatters() {
$entity_uri = $this
->getAbsoluteUri($this->targetEntity);
// Tests the label formatter.
$this
->assertFormatterRdfa([
'type' => 'entity_reference_label',
], 'http://schema.org/knows', [
'value' => $entity_uri,
'type' => 'uri',
]);
// Tests the entity formatter.
$this
->assertFormatterRdfa([
'type' => 'entity_reference_entity_view',
], 'http://schema.org/knows', [
'value' => $entity_uri,
'type' => 'uri',
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityReferenceRdfaTest:: |
protected | property | The bundle used in this test. | |
EntityReferenceRdfaTest:: |
protected | property | The entity type used in this test. | |
EntityReferenceRdfaTest:: |
protected | property |
The machine name of the field type to test. Overrides FieldRdfaTestBase:: |
|
EntityReferenceRdfaTest:: |
protected static | property |
Modules to enable. Overrides FieldRdfaTestBase:: |
|
EntityReferenceRdfaTest:: |
protected | property | The term for testing. | |
EntityReferenceRdfaTest:: |
protected | function | ||
EntityReferenceRdfaTest:: |
public | function | Tests all the entity reference formatters. | |
EntityReferenceTestTrait:: |
protected | function | Creates a field of an entity reference field storage on the specified bundle. | |
FieldRdfaTestBase:: |
protected | property | TRUE if verbose debugging is enabled. | |
FieldRdfaTestBase:: |
protected | property | The entity to render for testing. | |
FieldRdfaTestBase:: |
protected | property | The name of the field to create for testing. | |
FieldRdfaTestBase:: |
protected | property | ||
FieldRdfaTestBase:: |
protected | property | The URI to identify the entity. | |
FieldRdfaTestBase:: |
protected | function | Helper function to test the formatter's RDFa. | |
FieldRdfaTestBase:: |
protected | function | Creates the field for testing. | |
FieldRdfaTestBase:: |
protected | function | Gets the absolute URI of an entity. | |
FieldRdfaTestBase:: |
protected | function | Parses a content and return the html element. | |
FieldRdfaTestBase:: |
protected | function | Performs an xpath search on a certain content. | |
RdfParsingTrait:: |
protected | function | Counts the number of resources of the provided type. | |
RdfParsingTrait:: |
protected | function | Gets type of RDF Element. | |
RdfParsingTrait:: |
protected | function | Checks if a html document contains a resource with a given property value. | |
RdfParsingTrait:: |
protected | function | Checks if a html document contains a resource with a given property value. | |
RdfParsingTrait:: |
protected | function | Checks if RDF Node property is blank. |