View source
<?php
namespace Drupal\Tests\rdf\Functional;
use Drupal\Core\Url;
use Drupal\Tests\file\Functional\FileFieldTestBase;
use Drupal\file\Entity\File;
use Drupal\Tests\rdf\Traits\RdfParsingTrait;
class FileFieldAttributesTest extends FileFieldTestBase {
use RdfParsingTrait;
protected static $modules = [
'rdf',
'file',
];
protected $defaultTheme = 'stark';
protected $baseUri;
protected $fieldName;
protected $file;
protected $node;
protected function setUp() : void {
parent::setUp();
$node_storage = $this->container
->get('entity_type.manager')
->getStorage('node');
$this->fieldName = strtolower($this
->randomMachineName());
$type_name = 'article';
$this
->createFileField($this->fieldName, 'node', $type_name);
\Drupal::service('entity_display.repository')
->getViewDisplay('node', 'article', 'teaser')
->setComponent($this->fieldName, [
'type' => 'file_default',
])
->save();
$mapping = rdf_get_mapping('node', 'article');
$mapping
->setFieldMapping($this->fieldName, [
'properties' => [
'rdfs:seeAlso',
],
'mapping_type' => 'rel',
])
->save();
$test_file = $this
->getTestFile('text');
$nid = $this
->uploadNodeFile($test_file, $this->fieldName, $type_name);
$node_storage
->resetCache([
$nid,
]);
$this->node = $node_storage
->load($nid);
$this->file = File::load($this->node->{$this->fieldName}->target_id);
$this->baseUri = Url::fromRoute('<front>', [], [
'absolute' => TRUE,
])
->toString();
}
public function testNodeTeaser() {
$node_render_array = \Drupal::entityTypeManager()
->getViewBuilder('node')
->view($this->node, 'teaser');
$html = \Drupal::service('renderer')
->renderRoot($node_render_array);
$node_uri = $this->node
->toUrl('canonical', [
'absolute' => TRUE,
])
->toString();
$file_uri = $this->file
->createFileUrl(FALSE);
$expected_value = [
'type' => 'uri',
'value' => $file_uri,
];
$this
->assertTrue($this
->hasRdfProperty($html, $this->baseUri, $node_uri, 'http://www.w3.org/2000/01/rdf-schema#seeAlso', $expected_value), 'Node to file relation found in RDF output (rdfs:seeAlso).');
$this
->drupalGet('node');
}
}