function CrudTest::testFieldMapping

Same name and namespace in other branches
  1. 8.9.x 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 85

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.');
}

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