You are here

public function CrudTest::testFieldMapping in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/rdf/tests/src/Kernel/CrudTest.php \Drupal\Tests\rdf\Kernel\CrudTest::testFieldMapping()
  2. 9 core/modules/rdf/tests/src/Kernel/CrudTest.php \Drupal\Tests\rdf\Kernel\CrudTest::testFieldMapping()

Tests the handling of field mappings.

File

core/modules/rdf/tests/src/Kernel/CrudTest.php, line 81

Class

CrudTest
Tests the RDF mapping CRUD functions.

Namespace

Drupal\Tests\rdf\Kernel

Code

public function testFieldMapping() {
  $field_name = 'created';

  // Test that the field mapping can be saved.
  $mapping = [
    'properties' => [
      'dc:created',
    ],
    'datatype' => 'xsd:dateTime',
    'datatype_callback' => [
      'callable' => 'Drupal\\rdf\\CommonDataConverter::dateIso8601Value',
    ],
  ];
  rdf_get_mapping($this->entityType, $this->bundle)
    ->setFieldMapping($field_name, $mapping)
    ->save();
  $field_mapping = rdf_get_mapping($this->entityType, $this->bundle)
    ->getFieldMapping($field_name);
  $this
    ->assertEquals($mapping, $field_mapping, 'Field mapping saved.');

  // Test that the field mapping can be edited.
  $mapping = [
    'properties' => [
      'dc:date',
    ],
    'datatype' => 'foo:bar',
    'datatype_callback' => [
      'callable' => 'Drupal\\rdf\\CommonDataConverter::dateIso8601Value',
    ],
  ];
  rdf_get_mapping($this->entityType, $this->bundle)
    ->setFieldMapping($field_name, $mapping)
    ->save();
  $field_mapping = rdf_get_mapping($this->entityType, $this->bundle)
    ->getFieldMapping($field_name);
  $this
    ->assertEquals($mapping, $field_mapping, 'Field mapping updated.');
}