Chris@0: prefix = 'rdf.mapping'; Chris@0: $this->entityType = $this->bundle = 'entity_test'; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests creation of RDF mapping. Chris@0: */ Chris@0: public function testMappingCreation() { Chris@0: $mapping_config_name = "{$this->prefix}.{$this->entityType}.{$this->bundle}"; Chris@0: Chris@0: // Save bundle mapping config. Chris@0: rdf_get_mapping($this->entityType, $this->bundle)->save(); Chris@0: // Test that config file was saved. Chris@0: $mapping_config = \Drupal::configFactory()->listAll('rdf.mapping.'); Chris@0: $this->assertTrue(in_array($mapping_config_name, $mapping_config), 'Rdf mapping config saved.'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test the handling of bundle mappings. Chris@0: */ Chris@0: public function testBundleMapping() { Chris@0: // Test that the bundle mapping can be saved. Chris@0: $types = ['sioc:Post', 'foaf:Document']; Chris@0: rdf_get_mapping($this->entityType, $this->bundle) Chris@0: ->setBundleMapping(['types' => $types]) Chris@0: ->save(); Chris@0: $bundle_mapping = rdf_get_mapping($this->entityType, $this->bundle) Chris@0: ->getBundleMapping(); Chris@0: $this->assertEqual($types, $bundle_mapping['types'], 'Bundle mapping saved.'); Chris@0: Chris@0: // Test that the bundle mapping can be edited. Chris@0: $types = ['schema:BlogPosting']; Chris@0: rdf_get_mapping($this->entityType, $this->bundle) Chris@0: ->setBundleMapping(['types' => $types]) Chris@0: ->save(); Chris@0: $bundle_mapping = rdf_get_mapping($this->entityType, $this->bundle) Chris@0: ->getBundleMapping(); Chris@0: $this->assertEqual($types, $bundle_mapping['types'], 'Bundle mapping updated.'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test the handling of field mappings. Chris@0: */ Chris@0: public function testFieldMapping() { Chris@0: $field_name = 'created'; Chris@0: Chris@0: // Test that the field mapping can be saved. Chris@0: $mapping = [ Chris@0: 'properties' => ['dc:created'], Chris@0: 'datatype' => 'xsd:dateTime', Chris@0: 'datatype_callback' => ['callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'], Chris@0: ]; Chris@0: rdf_get_mapping($this->entityType, $this->bundle) Chris@0: ->setFieldMapping($field_name, $mapping) Chris@0: ->save(); Chris@0: $field_mapping = rdf_get_mapping($this->entityType, $this->bundle) Chris@0: ->getFieldMapping($field_name); Chris@0: $this->assertEqual($mapping, $field_mapping, 'Field mapping saved.'); Chris@0: Chris@0: // Test that the field mapping can be edited. Chris@0: $mapping = [ Chris@0: 'properties' => ['dc:date'], Chris@0: 'datatype' => 'foo:bar', Chris@0: 'datatype_callback' => ['callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'], Chris@0: ]; Chris@0: rdf_get_mapping($this->entityType, $this->bundle) Chris@0: ->setFieldMapping($field_name, $mapping) Chris@0: ->save(); Chris@0: $field_mapping = rdf_get_mapping($this->entityType, $this->bundle) Chris@0: ->getFieldMapping($field_name); Chris@0: $this->assertEqual($mapping, $field_mapping, 'Field mapping updated.'); Chris@0: } Chris@0: Chris@0: }