You are here

protected function StandardProfileTest::assertRdfaCommonNodeProperties in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/rdf/tests/src/Functional/StandardProfileTest.php \Drupal\Tests\rdf\Functional\StandardProfileTest::assertRdfaCommonNodeProperties()
  2. 9 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.

@internal

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

File

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

Class

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

Namespace

Drupal\Tests\rdf\Functional

Code

protected function assertRdfaCommonNodeProperties(NodeInterface $node, string $message_prefix) : void {
  $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
    ->assertEquals('schema:Person', $this
    ->getElementRdfType($node
    ->toUrl(), $this->baseUri, $this->authorUri), '$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).");
}