function NodeAttributesTest::testNodeAttributes

Creates a node of type article and tests its RDFa markup.

File

drupal/core/modules/rdf/lib/Drupal/rdf/Tests/NodeAttributesTest.php, line 35
Contains Drupal\rdf\Tests\NodeAttributesTest.

Class

NodeAttributesTest
Tests the RDFa markup of Nodes.

Namespace

Drupal\rdf\Tests

Code

function testNodeAttributes() {
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'article',
  ));
  $node_uri = url('node/' . $node->nid, array(
    'absolute' => TRUE,
  ));
  $base_uri = url('<front>', array(
    'absolute' => TRUE,
  ));

  // Parses front page where the node is displayed in its teaser form.
  $parser = new \EasyRdf_Parser_Rdfa();
  $graph = new \EasyRdf_Graph();
  $parser
    ->parse($graph, $this
    ->drupalGet('node/' . $node->nid), 'rdfa', $base_uri);

  // Inspects RDF graph output.
  // Node type.
  $expected_value = array(
    'type' => 'uri',
    'value' => 'http://rdfs.org/sioc/ns#Item',
  );
  $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).');

  // Node type.
  $expected_value = array(
    'type' => 'uri',
    'value' => 'http://xmlns.com/foaf/0.1/Document',
  );
  $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).');

  // Node title.
  $expected_value = array(
    'type' => 'literal',
    'value' => $node->title,
    'lang' => 'en',
  );
  $this
    ->assertTrue($graph
    ->hasProperty($node_uri, 'http://purl.org/dc/terms/title', $expected_value), 'Node title found in RDF output (dc:title).');

  // Node date.
  $expected_value = array(
    'type' => 'literal',
    'value' => date('c', $node->created),
    'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime',
  );
  $this
    ->assertTrue($graph
    ->hasProperty($node_uri, 'http://purl.org/dc/terms/date', $expected_value), 'Node date found in RDF output (dc:date).');

  // Node date.
  $expected_value = array(
    'type' => 'literal',
    'value' => date('c', $node->created),
    'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime',
  );
  $this
    ->assertTrue($graph
    ->hasProperty($node_uri, 'http://purl.org/dc/terms/created', $expected_value), 'Node date found in RDF output (dc:created).');
}