function TrackerAttributesTest::_testBasicTrackerRdfaMarkup

Helper function for testAttributesInTracker().

Tests the tracker page for RDFa markup.

Parameters

\Drupal\Core\Entity\EntityInterface $node: The node just created.

1 call to TrackerAttributesTest::_testBasicTrackerRdfaMarkup()
TrackerAttributesTest::testAttributesInTracker in drupal/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php
Tests for correct attributes on tracker page.

File

drupal/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php, line 78
Contains Drupal\rdf\Tests\TrackerAttributesTest.

Class

TrackerAttributesTest
Tests the RDF tracker page mapping.

Namespace

Drupal\rdf\Tests

Code

function _testBasicTrackerRdfaMarkup(EntityInterface $node) {
  $node_uri = url('node/' . $node->nid, array(
    'absolute' => TRUE,
  ));
  $user_uri = url('user/' . $node->uid, array(
    'absolute' => TRUE,
  ));
  $user = $node->uid == 0 ? 'Anonymous user' : 'Registered user';

  // Parses tracker page where the nodes are displayed in a table.
  $parser = new \EasyRdf_Parser_Rdfa();
  $graph = new \EasyRdf_Graph();
  $parser
    ->parse($graph, $this
    ->drupalGet('tracker'), 'rdfa', $this->base_uri);

  // Inspects RDF graph output.
  // Node title.
  $expected_value = array(
    'type' => 'literal',
    // The theme layer adds a space after the title a element, and the RDFa
    // attribute is on the wrapping td. Adds a space to match this.
    'value' => $node->title . ' ',
    'lang' => 'en',
  );
  $this
    ->assertTrue($graph
    ->hasProperty($node_uri, 'http://purl.org/dc/terms/title', $expected_value), 'Title found in RDF output (dc:title).');

  // Number of comments.
  $expected_value = array(
    'type' => 'literal',
    'value' => '0',
    'datatype' => 'http://www.w3.org/2001/XMLSchema#integer',
  );
  $this
    ->assertTrue($graph
    ->hasProperty($node_uri, 'http://rdfs.org/sioc/ns#num_replies', $expected_value), 'Number of comments found in RDF output (sioc:num_replies).');

  // Node relation to author.
  $expected_value = array(
    'type' => 'uri',
    'value' => $user_uri,
  );
  if ($node->uid == 0) {
    $this
      ->assertFalse($graph
      ->hasProperty($node_uri, 'http://rdfs.org/sioc/ns#has_creator', $expected_value), 'No relation to author found in RDF output (sioc:has_creator).');
  }
  elseif ($node->uid > 0) {
    $this
      ->assertTrue($graph
      ->hasProperty($node_uri, 'http://rdfs.org/sioc/ns#has_creator', $expected_value), 'Relation to author found in RDF output (sioc:has_creator).');
  }

  // Last updated.
  $expected_value = array(
    'type' => 'literal',
    'value' => date('c', $node->changed),
    'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime',
  );
  $this
    ->assertTrue($graph
    ->hasProperty($node_uri, 'http://rdfs.org/sioc/ns#last_activity_date', $expected_value), 'Last activity date found in RDF output (sioc:last_activity_date).');

  // Adds new comment to ensure the tracker is updated accordingly.
  $comment = array(
    'subject' => $this
      ->randomName(),
    'comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]' => $this
      ->randomName(),
  );
  $this
    ->drupalPost('comment/reply/' . $node->nid, $comment, t('Save'));

  // Parses tracker page where the nodes are displayed in a table.
  $parser = new \EasyRdf_Parser_Rdfa();
  $graph = new \EasyRdf_Graph();
  $parser
    ->parse($graph, $this
    ->drupalGet('tracker'), 'rdfa', $this->base_uri);

  // Number of comments.
  $expected_value = array(
    'type' => 'literal',
    'value' => '1',
    'datatype' => 'http://www.w3.org/2001/XMLSchema#integer',
  );
  $this
    ->assertTrue($graph
    ->hasProperty($node_uri, 'http://rdfs.org/sioc/ns#num_replies', $expected_value), 'Number of comments found in RDF output (sioc:num_replies).');

  // Last updated due to new comment.
  // last_activity_date needs to be queried from the database directly because
  // it cannot be accessed via node_load().
  $expected_last_activity_date = db_query('SELECT t.changed FROM {tracker_node} t WHERE t.nid = (:nid)', array(
    ':nid' => $node->nid,
  ))
    ->fetchField();
  $expected_value = array(
    'type' => 'literal',
    'value' => date('c', $expected_last_activity_date),
    'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime',
  );
  $this
    ->assertTrue($graph
    ->hasProperty($node_uri, 'http://rdfs.org/sioc/ns#last_activity_date', $expected_value), 'Last activity date after new comment has been posted found in RDF output (sioc:last_activity_date).');
}