public function CommentAttributesTest::testNumberOfCommentsRdfaMarkup

Tests the presence of the RDFa markup for the number of comments.

File

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

Class

CommentAttributesTest
Tests the RDFa markup of comments.

Namespace

Drupal\rdf\Tests

Code

public function testNumberOfCommentsRdfaMarkup() {

  // Posts 2 comments on behalf of registered user.
  $this
    ->saveComment($this->node->nid, $this->web_user->uid);
  $this
    ->saveComment($this->node->nid, $this->web_user->uid);

  // Tests number of comments in teaser view.
  $this
    ->drupalLogin($this->web_user);
  $parser = new \EasyRdf_Parser_Rdfa();
  $graph = new \EasyRdf_Graph();
  $parser
    ->parse($graph, $this
    ->drupalGet('node'), 'rdfa', $this->base_uri);

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

  // Makes sure we don't generate the wrong statement for number of comments.
  $node_comments_uri = url('node/' . $this->node->nid, array(
    'fragment' => 'comments',
    'absolute' => TRUE,
  ));
  $this
    ->assertFalse($graph
    ->hasProperty($node_comments_uri, 'http://rdfs.org/sioc/ns#num_replies', $expected_value), 'Number of comments found in RDF output of teaser view mode (sioc:num_replies).');

  // Tests number of comments in full node view, expected value is the same.
  $parser = new \EasyRdf_Parser_Rdfa();
  $graph = new \EasyRdf_Graph();
  $parser
    ->parse($graph, $this
    ->drupalGet('node/' . $this->node->nid), 'rdfa', $this->base_uri);
  $this
    ->assertTrue($graph
    ->hasProperty($this->node_uri, 'http://rdfs.org/sioc/ns#num_replies', $expected_value), 'Number of comments found in RDF output of full node view mode (sioc:num_replies).');
}