You are here

protected function StandardProfileTest::assertRdfaNodeCommentProperties in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/rdf/tests/src/Functional/StandardProfileTest.php \Drupal\Tests\rdf\Functional\StandardProfileTest::assertRdfaNodeCommentProperties()
  2. 10 core/modules/rdf/tests/src/Functional/StandardProfileTest.php \Drupal\Tests\rdf\Functional\StandardProfileTest::assertRdfaNodeCommentProperties()

Tests output for comment properties on nodes in full page view mode.

1 call to StandardProfileTest::assertRdfaNodeCommentProperties()
StandardProfileTest::doArticleRdfaTests in core/modules/rdf/tests/src/Functional/StandardProfileTest.php
Tests that article data is exposed using RDFa.

File

core/modules/rdf/tests/src/Functional/StandardProfileTest.php, line 419

Class

StandardProfileTest
Tests the RDF mappings and RDFa markup of the standard profile.

Namespace

Drupal\Tests\rdf\Functional

Code

protected function assertRdfaNodeCommentProperties() {
  $this
    ->drupalGet($this->article
    ->toUrl());

  // Relationship between node and comment.
  $expected_value = [
    'type' => 'uri',
    'value' => $this->articleCommentUri,
  ];
  $this
    ->assertTrue($this
    ->hasRdfProperty($this
    ->getSession()
    ->getPage()
    ->getContent(), $this->baseUri, $this->articleUri, 'http://schema.org/comment', $expected_value), "Relationship between node and comment found (schema:comment).");

  // Comment type.
  $this
    ->assertEqual($this
    ->getElementRdfType($this->article
    ->toUrl(), $this->baseUri, $this->articleCommentUri), 'schema:Comment', 'Comment type was found (schema:Comment).');

  // Comment title.
  $expected_value = [
    'type' => 'literal',
    'value' => $this->articleComment
      ->get('subject')->value,
    'lang' => 'en',
  ];
  $this
    ->assertTrue($this
    ->hasRdfProperty($this
    ->getSession()
    ->getPage()
    ->getContent(), $this->baseUri, $this->articleCommentUri, 'http://schema.org/name', $expected_value), "Article comment title was found (schema:name).");

  // Comment created date.
  $expected_value = [
    'type' => 'literal',
    'value' => $this->container
      ->get('date.formatter')
      ->format($this->articleComment
      ->get('created')->value, 'custom', 'c', 'UTC'),
    'lang' => 'en',
  ];
  $this
    ->assertTrue($this
    ->hasRdfProperty($this
    ->getSession()
    ->getPage()
    ->getContent(), $this->baseUri, $this->articleCommentUri, 'http://schema.org/dateCreated', $expected_value), "Article comment created date was found (schema:dateCreated).");

  // Comment body.
  $text = $this->articleComment
    ->get('comment_body')->value;
  $expected_value = [
    'type' => 'literal',
    // There is an extra carriage return in the when parsing comments as
    // output by Bartik, so it must be added to the expected value.
    'value' => "{$text}\n",
    'lang' => 'en',
  ];
  $this
    ->assertTrue($this
    ->hasRdfProperty($this
    ->getSession()
    ->getPage()
    ->getContent(), $this->baseUri, $this->articleCommentUri, 'http://schema.org/text', $expected_value), "Article comment body was found (schema:text).");

  // Comment uid.
  $expected_value = [
    'type' => 'uri',
    'value' => $this->commenterUri,
  ];
  $this
    ->assertTrue($this
    ->hasRdfProperty($this
    ->getSession()
    ->getPage()
    ->getContent(), $this->baseUri, $this->articleCommentUri, 'http://schema.org/author', $expected_value), "Article comment author was found (schema:author).");

  // Comment author type.
  $this
    ->assertEqual($this
    ->getElementRdfType($this->article
    ->toUrl(), $this->baseUri, $this->commenterUri), 'schema:Person', 'Comment author type was found (schema:Person).');

  // Comment author name.
  $expected_value = [
    'type' => 'literal',
    'value' => $this->webUser
      ->getAccountName(),
  ];
  $this
    ->assertTrue($this
    ->hasRdfProperty($this
    ->getSession()
    ->getPage()
    ->getContent(), $this->baseUri, $this->commenterUri, 'http://schema.org/name', $expected_value), "Comment author name was found (schema:name).");
}