Chris@0: setBundleMapping([ Chris@0: 'types' => ['sioc:Item', 'foaf:Document'], Chris@0: ]) Chris@0: ->setFieldMapping('title', [ Chris@0: 'properties' => ['dc:title'], Chris@0: ]) Chris@0: ->setFieldMapping('created', [ Chris@0: 'properties' => ['dc:date', 'dc:created'], Chris@0: 'datatype' => 'xsd:dateTime', Chris@0: 'datatype_callback' => ['callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'], Chris@0: ]) Chris@0: ->save(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Creates a node of type article and tests its RDFa markup. Chris@0: */ Chris@0: public function testNodeAttributes() { Chris@0: // Create node with single quotation mark title to ensure it does not get Chris@0: // escaped more than once. Chris@0: $node = $this->drupalCreateNode([ Chris@0: 'type' => 'article', Chris@0: 'title' => $this->randomMachineName(8) . "'", Chris@0: ]); Chris@0: Chris@18: $node_uri = $node->toUrl('canonical', ['absolute' => TRUE])->toString(); Chris@18: $base_uri = Url::fromRoute('', [], ['absolute' => TRUE])->toString(); Chris@0: Chris@0: // Parses front page where the node is displayed in its teaser form. Chris@0: $parser = new \EasyRdf_Parser_Rdfa(); Chris@0: $graph = new \EasyRdf_Graph(); Chris@0: $parser->parse($graph, $this->drupalGet('node/' . $node->id()), 'rdfa', $base_uri); Chris@0: Chris@0: // Inspects RDF graph output. Chris@0: // Node type. Chris@0: $expected_value = [ Chris@0: 'type' => 'uri', Chris@0: 'value' => 'http://rdfs.org/sioc/ns#Item', Chris@0: ]; Chris@0: $this->assertTrue($graph->hasProperty($node_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Node type found in RDF output (sioc:Item).'); Chris@0: // Node type. Chris@0: $expected_value = [ Chris@0: 'type' => 'uri', Chris@0: 'value' => 'http://xmlns.com/foaf/0.1/Document', Chris@0: ]; Chris@0: $this->assertTrue($graph->hasProperty($node_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Node type found in RDF output (foaf:Document).'); Chris@0: // Node title. Chris@0: $expected_value = [ Chris@0: 'type' => 'literal', Chris@0: 'value' => $node->getTitle(), Chris@0: 'lang' => 'en', Chris@0: ]; Chris@0: $this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/title', $expected_value), 'Node title found in RDF output (dc:title).'); Chris@0: // Node date (date format must be UTC). Chris@0: $expected_value = [ Chris@0: 'type' => 'literal', Chris@0: 'value' => \Drupal::service('date.formatter')->format($node->getCreatedTime(), 'custom', 'c', 'UTC'), Chris@0: 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime', Chris@0: ]; Chris@0: $this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/date', $expected_value), 'Node date found in RDF output (dc:date).'); Chris@0: // Node date (date format must be UTC). Chris@0: $expected_value = [ Chris@0: 'type' => 'literal', Chris@0: 'value' => \Drupal::service('date.formatter')->format($node->getCreatedTime(), 'custom', 'c', 'UTC'), Chris@0: 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime', Chris@0: ]; Chris@0: $this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/created', $expected_value), 'Node date found in RDF output (dc:created).'); Chris@0: } Chris@0: Chris@0: }