function CommentAttributesTest::_testBasicCommentRdfaMarkup

Helper function for testCommentRdfaMarkup().

Tests the current page for basic comment RDFa markup.

Parameters

$comment: Comment object.

$account: An array containing information about an anonymous user.

1 call to CommentAttributesTest::_testBasicCommentRdfaMarkup()
CommentAttributesTest::testCommentRdfaMarkup in drupal/core/modules/rdf/lib/Drupal/rdf/Tests/CommentAttributesTest.php
Tests if RDFa markup for meta information is present in comments.

File

drupal/core/modules/rdf/lib/Drupal/rdf/Tests/CommentAttributesTest.php, line 178
Contains Drupal\rdf\Tests\CommentAttributesTest.

Class

CommentAttributesTest
Tests the RDFa markup of comments.

Namespace

Drupal\rdf\Tests

Code

function _testBasicCommentRdfaMarkup($graph, $comment, $account = array()) {
  $uri = $comment
    ->uri();
  $comment_uri = url($uri['path'], $uri['options'] + array(
    'absolute' => TRUE,
  ));

  // Comment type.
  $expected_value = array(
    'type' => 'uri',
    'value' => 'http://rdfs.org/sioc/types#Comment',
  );
  $this
    ->assertTrue($graph
    ->hasProperty($comment_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Comment type found in RDF output (sioct:Comment).');

  // Comment type.
  $expected_value = array(
    'type' => 'uri',
    'value' => 'http://rdfs.org/sioc/ns#Post',
  );
  $this
    ->assertTrue($graph
    ->hasProperty($comment_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Comment type found in RDF output (sioc:Post).');

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

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

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

  // Comment body.
  $expected_value = array(
    'type' => 'literal',
    'value' => $comment->comment_body->value . "\n",
    'lang' => 'en',
  );
  $this
    ->assertTrue($graph
    ->hasProperty($comment_uri, 'http://purl.org/rss/1.0/modules/content/encoded', $expected_value), 'Comment body found in RDF output (content:encoded).');

  // The comment author can be a registered user or an anonymous user.
  if ($comment->uid->value > 0) {
    $author_uri = url('user/' . $comment->uid->value, array(
      'absolute' => TRUE,
    ));

    // Comment relation to author.
    $expected_value = array(
      'type' => 'uri',
      'value' => $author_uri,
    );
    $this
      ->assertTrue($graph
      ->hasProperty($comment_uri, 'http://rdfs.org/sioc/ns#has_creator', $expected_value), 'Comment relation to author found in RDF output (sioc:has_creator).');
  }
  else {

    // The author is expected to be a blank node.
    $author_uri = $graph
      ->get($comment_uri, '<http://rdfs.org/sioc/ns#has_creator>');
    if ($author_uri instanceof \EasyRdf_Resource) {
      $this
        ->assertTrue($author_uri
        ->isBnode(), 'Comment relation to author found in RDF output (sioc:has_creator) and author is blank node.');
    }
    else {
      $this
        ->fail('Comment relation to author found in RDF output (sioc:has_creator).');
    }
  }

  // Author name.
  $name = empty($account["name"]) ? $this->web_user->name : $account["name"] . " (not verified)";
  $expected_value = array(
    'type' => 'literal',
    'value' => $name,
  );
  $this
    ->assertTrue($graph
    ->hasProperty($author_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'Comment author name found in RDF output (foaf:name).');

  // Comment author homepage (only for anonymous authors).
  if ($comment->uid->value == 0) {
    $expected_value = array(
      'type' => 'uri',
      'value' => 'http://example.org/',
    );
    $this
      ->assertTrue($graph
      ->hasProperty($author_uri, 'http://xmlns.com/foaf/0.1/page', $expected_value), 'Comment author link found in RDF output (foaf:page).');
  }
}