public function ImageFieldAttributesTest::testNodeTeaser in Drupal 8
Same name and namespace in other branches
- 9 core/modules/rdf/tests/src/Functional/ImageFieldAttributesTest.php \Drupal\Tests\rdf\Functional\ImageFieldAttributesTest::testNodeTeaser()
- 10 core/modules/rdf/tests/src/Functional/ImageFieldAttributesTest.php \Drupal\Tests\rdf\Functional\ImageFieldAttributesTest::testNodeTeaser()
Tests that image fields in teasers have correct resources.
File
- core/
modules/ rdf/ tests/ src/ Functional/ ImageFieldAttributesTest.php, line 98
Class
- ImageFieldAttributesTest
- Tests the RDFa markup of imagefields.
Namespace
Drupal\Tests\rdf\FunctionalCode
public function testNodeTeaser() {
// Set the display options for the teaser.
$display_options = [
'type' => 'image',
'settings' => [
'image_style' => 'medium',
'image_link' => 'content',
],
];
$display = \Drupal::service('entity_display.repository')
->getViewDisplay('node', 'article', 'teaser');
$display
->setComponent($this->fieldName, $display_options)
->save();
// Render the teaser.
$node_render_array = \Drupal::entityTypeManager()
->getViewBuilder('node')
->view($this->node, 'teaser');
$html = \Drupal::service('renderer')
->renderRoot($node_render_array);
// Construct the node and image URIs for testing.
$node_uri = $this->node
->toUrl('canonical', [
'absolute' => TRUE,
])
->toString();
$image_uri = ImageStyle::load('medium')
->buildUrl($this->file
->getFileUri());
// Test relations from node to image.
$expected_value = [
'type' => 'uri',
'value' => $image_uri,
];
$this
->assertTrue($this
->hasRdfProperty($html, $this->baseUri, $node_uri, 'http://ogp.me/ns#image', $expected_value), 'Node to file relation found in RDF output (og:image).');
// Test image type.
$expected_value = [
'type' => 'uri',
'value' => 'http://xmlns.com/foaf/0.1/Image',
];
$this
->assertTrue($this
->hasRdfProperty($html, $this->baseUri, $image_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Term type found in RDF output (skos:Concept).');
}