You are here

protected function RdfMappingTest::createEntity in Drupal 9

Same name and namespace in other branches
  1. 8 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/jsonapi/tests/src/Functional/RdfMappingTest.php, line 53

Class

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

Namespace

Drupal\Tests\jsonapi\Functional

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