You are here

protected function StandardProfileTest::assertRdfaCommonNodeProperties 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::assertRdfaCommonNodeProperties()
  2. 10 core/modules/rdf/tests/src/Functional/StandardProfileTest.php \Drupal\Tests\rdf\Functional\StandardProfileTest::assertRdfaCommonNodeProperties()

Tests output for properties held in common between articles and pages.

Parameters

\Drupal\node\NodeInterface $node: The node being displayed.

string $message_prefix: The word to use in the test assertion message.

Throws

\Drupal\Core\Entity\EntityMalformedException

3 calls to StandardProfileTest::assertRdfaCommonNodeProperties()
StandardProfileTest::doArticleRdfaTests in core/modules/rdf/tests/src/Functional/StandardProfileTest.php
Tests that article data is exposed using RDFa.
StandardProfileTest::doFrontPageRdfaTests in core/modules/rdf/tests/src/Functional/StandardProfileTest.php
Tests that data is exposed in the front page teasers.
StandardProfileTest::doPageRdfaTests in core/modules/rdf/tests/src/Functional/StandardProfileTest.php
Tests that page data is exposed using RDFa.

File

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

Class

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

Namespace

Drupal\Tests\rdf\Functional

Code

protected function assertRdfaCommonNodeProperties(NodeInterface $node, $message_prefix) {
  $this
    ->drupalGet($node
    ->toUrl());
  $uri = $node
    ->toUrl('canonical', [
    'absolute' => TRUE,
  ])
    ->toString();

  // Title.
  $expected_value = [
    'type' => 'literal',
    'value' => $node
      ->get('title')->value,
    'lang' => 'en',
  ];
  $this
    ->assertTrue($this
    ->hasRdfProperty($this
    ->getSession()
    ->getPage()
    ->getContent(), $this->baseUri, $uri, 'http://schema.org/name', $expected_value), "{$message_prefix} title was found (schema:name).");

  // Created date.
  $expected_value = [
    'type' => 'literal',
    'value' => $this->container
      ->get('date.formatter')
      ->format($node
      ->get('created')->value, 'custom', 'c', 'UTC'),
    'lang' => 'en',
  ];
  $this
    ->assertTrue($this
    ->hasRdfProperty($this
    ->getSession()
    ->getPage()
    ->getContent(), $this->baseUri, $uri, 'http://schema.org/dateCreated', $expected_value), "{$message_prefix} created date was found (schema:dateCreated) in teaser.");

  // Body.
  $expected_value = [
    'type' => 'literal',
    'value' => $node
      ->get('body')->value,
    'lang' => 'en',
  ];
  $this
    ->assertTrue($this
    ->hasRdfProperty($this
    ->getSession()
    ->getPage()
    ->getContent(), $this->baseUri, $uri, 'http://schema.org/text', $expected_value), "{$message_prefix} body was found (schema:text) in teaser.");

  // Author.
  $expected_value = [
    'type' => 'uri',
    'value' => $this->authorUri,
  ];
  $this
    ->assertTrue($this
    ->hasRdfProperty($this
    ->getSession()
    ->getPage()
    ->getContent(), $this->baseUri, $uri, 'http://schema.org/author', $expected_value), "{$message_prefix} author was found (schema:author) in teaser.");

  // Author type.
  $this
    ->assertEqual($this
    ->getElementRdfType($node
    ->toUrl(), $this->baseUri, $this->authorUri), 'schema:Person', '$message_prefix author type was found (schema:Person).');

  // Author name.
  $expected_value = [
    'type' => 'literal',
    'value' => $this->adminUser
      ->label(),
  ];
  $this
    ->assertTrue($this
    ->hasRdfProperty($this
    ->getSession()
    ->getPage()
    ->getContent(), $this->baseUri, $this->authorUri, 'http://schema.org/name', $expected_value), "{$message_prefix} author name was found (schema:name).");
}