3 namespace Drupal\Tests\rdf\Functional;
5 use Drupal\node\Tests\NodeTestBase;
8 * Tests the RDFa markup of Nodes.
12 class NodeAttributesTest extends NodeTestBase {
19 public static $modules = ['rdf'];
21 protected function setUp() {
24 rdf_get_mapping('node', 'article')
26 'types' => ['sioc:Item', 'foaf:Document'],
28 ->setFieldMapping('title', [
29 'properties' => ['dc:title'],
31 ->setFieldMapping('created', [
32 'properties' => ['dc:date', 'dc:created'],
33 'datatype' => 'xsd:dateTime',
34 'datatype_callback' => ['callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'],
40 * Creates a node of type article and tests its RDFa markup.
42 public function testNodeAttributes() {
43 // Create node with single quotation mark title to ensure it does not get
44 // escaped more than once.
45 $node = $this->drupalCreateNode([
47 'title' => $this->randomMachineName(8) . "'",
50 $node_uri = $node->url('canonical', ['absolute' => TRUE]);
51 $base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
53 // Parses front page where the node is displayed in its teaser form.
54 $parser = new \EasyRdf_Parser_Rdfa();
55 $graph = new \EasyRdf_Graph();
56 $parser->parse($graph, $this->drupalGet('node/' . $node->id()), 'rdfa', $base_uri);
58 // Inspects RDF graph output.
62 'value' => 'http://rdfs.org/sioc/ns#Item',
64 $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).');
68 'value' => 'http://xmlns.com/foaf/0.1/Document',
70 $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).');
74 'value' => $node->getTitle(),
77 $this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/title', $expected_value), 'Node title found in RDF output (dc:title).');
78 // Node date (date format must be UTC).
81 'value' => \Drupal::service('date.formatter')->format($node->getCreatedTime(), 'custom', 'c', 'UTC'),
82 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime',
84 $this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/date', $expected_value), 'Node date found in RDF output (dc:date).');
85 // Node date (date format must be UTC).
88 'value' => \Drupal::service('date.formatter')->format($node->getCreatedTime(), 'custom', 'c', 'UTC'),
89 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime',
91 $this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/created', $expected_value), 'Node date found in RDF output (dc:created).');