You are here

protected function RdfMappingResourceTestBase::createEntity in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/rdf/tests/src/Functional/Rest/RdfMappingResourceTestBase.php \Drupal\Tests\rdf\Functional\Rest\RdfMappingResourceTestBase::createEntity()

Creates the entity to be tested.

Return value

\Drupal\Core\Entity\EntityInterface The entity to be tested.

Overrides EntityResourceTestBase::createEntity

File

core/modules/rdf/tests/src/Functional/Rest/RdfMappingResourceTestBase.php, line 36

Class

RdfMappingResourceTestBase

Namespace

Drupal\Tests\rdf\Functional\Rest

Code

protected function createEntity() {

  // Create a "Camelids" node type.
  $camelids = NodeType::create([
    'name' => 'Camelids',
    'type' => 'camelids',
  ]);
  $camelids
    ->save();

  // Create the RDF mapping.
  $llama = RdfMapping::create([
    'targetEntityType' => 'node',
    'bundle' => 'camelids',
  ]);
  $llama
    ->setBundleMapping([
    'types' => [
      'sioc:Item',
      'foaf:Document',
    ],
  ])
    ->setFieldMapping('title', [
    'properties' => [
      'dc:title',
    ],
  ])
    ->setFieldMapping('created', [
    'properties' => [
      'dc:date',
      'dc:created',
    ],
    'datatype' => 'xsd:dateTime',
    'datatype_callback' => [
      'callable' => 'Drupal\\rdf\\CommonDataConverter::dateIso8601Value',
    ],
  ])
    ->save();
  return $llama;
}