View source
<?php
namespace Drupal\Tests\rdf\Kernel;
use Drupal\KernelTests\KernelTestBase;
class CrudTest extends KernelTestBase {
protected static $modules = [
'entity_test',
'rdf',
'system',
];
protected $prefix;
protected $entityType;
protected $bundle;
protected function setUp() : void {
parent::setUp();
$this->prefix = 'rdf.mapping';
$this->entityType = $this->bundle = 'entity_test';
}
public function testMappingCreation() {
$mapping_config_name = "{$this->prefix}.{$this->entityType}.{$this->bundle}";
rdf_get_mapping($this->entityType, $this->bundle)
->save();
$mapping_config = \Drupal::configFactory()
->listAll('rdf.mapping.');
$this
->assertContains($mapping_config_name, $mapping_config, 'Rdf mapping config saved.');
}
public function testBundleMapping() {
$types = [
'sioc:Post',
'foaf:Document',
];
rdf_get_mapping($this->entityType, $this->bundle)
->setBundleMapping([
'types' => $types,
])
->save();
$bundle_mapping = rdf_get_mapping($this->entityType, $this->bundle)
->getBundleMapping();
$this
->assertEquals($types, $bundle_mapping['types'], 'Bundle mapping saved.');
$types = [
'schema:BlogPosting',
];
rdf_get_mapping($this->entityType, $this->bundle)
->setBundleMapping([
'types' => $types,
])
->save();
$bundle_mapping = rdf_get_mapping($this->entityType, $this->bundle)
->getBundleMapping();
$this
->assertEquals($types, $bundle_mapping['types'], 'Bundle mapping updated.');
}
public function testFieldMapping() {
$field_name = 'created';
$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.');
$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.');
}
}