Chris@0: $properties]; Chris@0: $expected_attributes = ['property' => $properties]; Chris@0: Chris@0: $this->_testAttributes($expected_attributes, $mapping); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test attribute creation for mappings which use 'datatype'. Chris@0: */ Chris@0: public function testDatatype() { Chris@0: $properties = ['foo:bar1']; Chris@0: $datatype = 'foo:bar1type'; Chris@0: Chris@0: $mapping = [ Chris@0: 'datatype' => $datatype, Chris@0: 'properties' => $properties, Chris@0: ]; Chris@0: $expected_attributes = [ Chris@0: 'datatype' => $datatype, Chris@0: 'property' => $properties, Chris@0: ]; Chris@0: Chris@0: $this->_testAttributes($expected_attributes, $mapping); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test attribute creation for mappings which override human-readable content. Chris@0: */ Chris@0: public function testDatatypeCallback() { Chris@0: $properties = ['dc:created']; Chris@0: $datatype = 'xsd:dateTime'; Chris@0: Chris@0: $date = 1252750327; Chris@18: $iso_date = $this->container->get('date.formatter')->format($date, 'custom', 'c', 'UTC'); Chris@0: Chris@0: $mapping = [ Chris@0: 'datatype' => $datatype, Chris@0: 'properties' => $properties, Chris@18: 'datatype_callback' => ['callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'], Chris@0: ]; Chris@0: $expected_attributes = [ Chris@0: 'datatype' => $datatype, Chris@0: 'property' => $properties, Chris@0: 'content' => $iso_date, Chris@0: ]; Chris@0: Chris@18: $this->_testAttributes($expected_attributes, $mapping, ['value' => $date]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test attribute creation for mappings which use data converters. Chris@0: */ Chris@0: public function testDatatypeCallbackWithConverter() { Chris@0: $properties = ['schema:interactionCount']; Chris@0: Chris@0: $data = "23"; Chris@0: $content = "UserComments:23"; Chris@0: Chris@0: $mapping = [ Chris@0: 'properties' => $properties, Chris@0: 'datatype_callback' => [ Chris@0: 'callable' => 'Drupal\rdf\SchemaOrgDataConverter::interactionCount', Chris@0: 'arguments' => ['interaction_type' => 'UserComments'], Chris@0: ], Chris@0: ]; Chris@0: $expected_attributes = [ Chris@0: 'property' => $properties, Chris@0: 'content' => $content, Chris@0: ]; Chris@0: Chris@0: $this->_testAttributes($expected_attributes, $mapping, $data); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test attribute creation for mappings which use 'rel'. Chris@0: */ Chris@0: public function testRel() { Chris@0: $properties = ['sioc:has_creator', 'dc:creator']; Chris@0: Chris@0: $mapping = [ Chris@0: 'properties' => $properties, Chris@0: 'mapping_type' => 'rel', Chris@0: ]; Chris@0: $expected_attributes = ['rel' => $properties]; Chris@0: Chris@0: $this->_testAttributes($expected_attributes, $mapping); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Helper function to test attribute generation. Chris@0: * Chris@0: * @param array $expected_attributes Chris@0: * The expected return of rdf_rdfa_attributes. Chris@0: * @param array $field_mapping Chris@0: * The field mapping to merge into the RDF mapping config. Chris@0: * @param mixed $data Chris@0: * The data to pass into the datatype callback, if specified. Chris@0: */ Chris@0: protected function _testAttributes($expected_attributes, $field_mapping, $data = NULL) { Chris@0: $mapping = rdf_get_mapping('node', 'article') Chris@0: ->setFieldMapping('field_test', $field_mapping) Chris@0: ->getPreparedFieldMapping('field_test'); Chris@0: $attributes = rdf_rdfa_attributes($mapping, $data); Chris@0: ksort($expected_attributes); Chris@0: ksort($attributes); Chris@0: $this->assertEqual($expected_attributes, $attributes); Chris@0: } Chris@0: Chris@0: }