function StandardProfileTest::assertRdfaCommonNodeProperties

Same name in other branches
  1. 8.9.x 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

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 385

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).");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.