View source
<?php
namespace Drupal\rdf\Tests;
use Drupal\file\Tests\FileFieldTestBase;
use Drupal\file\Entity\File;
class FileFieldAttributesTest extends FileFieldTestBase {
public static $modules = array(
'rdf',
'file',
);
protected $fieldName;
protected $file;
protected $node;
protected function setUp() {
parent::setUp();
$node_storage = $this->container
->get('entity.manager')
->getStorage('node');
$this->fieldName = strtolower($this
->randomMachineName());
$type_name = 'article';
$this
->createFileField($this->fieldName, 'node', $type_name);
entity_get_display('node', 'article', 'teaser')
->setComponent($this->fieldName, array(
'type' => 'file_default',
))
->save();
$mapping = rdf_get_mapping('node', 'article');
$mapping
->setFieldMapping($this->fieldName, array(
'properties' => array(
'rdfs:seeAlso',
),
'mapping_type' => 'rel',
))
->save();
$test_file = $this
->getTestFile('text');
$nid = $this
->uploadNodeFile($test_file, $this->fieldName, $type_name);
$node_storage
->resetCache(array(
$nid,
));
$this->node = $node_storage
->load($nid);
$this->file = File::load($this->node->{$this->fieldName}->target_id);
}
function testNodeTeaser() {
$node_render_array = entity_view_multiple(array(
$this->node,
), 'teaser');
$html = \Drupal::service('renderer')
->renderRoot($node_render_array);
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$base_uri = \Drupal::url('<front>', [], [
'absolute' => TRUE,
]);
$parser
->parse($graph, $html, 'rdfa', $base_uri);
$node_uri = $this->node
->url('canonical', [
'absolute' => TRUE,
]);
$file_uri = file_create_url($this->file
->getFileUri());
$expected_value = array(
'type' => 'uri',
'value' => $file_uri,
);
$this
->assertTrue($graph
->hasProperty($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');
}
}