function RdfMappingTest::createEntity

Same name and namespace in other branches
  1. 8.9.x core/modules/jsonapi/tests/src/Functional/RdfMappingTest.php \Drupal\Tests\jsonapi\Functional\RdfMappingTest::createEntity()

Creates the entity to be tested.

Return value

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

Overrides ResourceTestBase::createEntity

File

core/modules/rdf/tests/src/Functional/Jsonapi/RdfMappingTest.php, line 56

Class

RdfMappingTest
JSON:API integration test for the "RdfMapping" config entity type.

Namespace

Drupal\Tests\rdf\Functional\Jsonapi

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

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