Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -12,6 +12,12 @@ use Drupal\rdf\RdfMappingInterface;
* @ConfigEntityType(
* id = "rdf_mapping",
* label = @Translation("RDF mapping"),
* label_singular = @Translation("RDF mapping item"),
* label_plural = @Translation("RDF mappings items"),
* label_count = @PluralTranslation(
* singular = "@count RDF mapping item",
* plural = "@count RDF mapping items",
* ),
* config_prefix = "mapping",
* entity_keys = {
* "id" = "id"
@ -53,20 +59,20 @@ class RdfMapping extends ConfigEntityBase implements RdfMappingInterface {
*
* @var array
*/
protected $types = array();
protected $types = [];
/**
* The mappings for fields on this bundle.
*
* @var array
*/
protected $fieldMappings = array();
protected $fieldMappings = [];
/**
* {@inheritdoc}
*/
public function getPreparedBundleMapping() {
return array('types' => $this->types);
return ['types' => $this->types];
}
/**
@ -74,9 +80,9 @@ class RdfMapping extends ConfigEntityBase implements RdfMappingInterface {
*/
public function getBundleMapping() {
if (!empty($this->types)) {
return array('types' => $this->types);
return ['types' => $this->types];
}
return array();
return [];
}
/**
@ -94,16 +100,16 @@ class RdfMapping extends ConfigEntityBase implements RdfMappingInterface {
* {@inheritdoc}
*/
public function getPreparedFieldMapping($field_name) {
$field_mapping = array(
$field_mapping = [
'properties' => NULL,
'datatype' => NULL,
'datatype_callback' => NULL,
'mapping_type' => NULL,
);
];
if (isset($this->fieldMappings[$field_name])) {
$field_mapping = array_merge($field_mapping, $this->fieldMappings[$field_name]);
}
return empty($field_mapping['properties']) ? array() : $field_mapping;
return empty($field_mapping['properties']) ? [] : $field_mapping;
}
/**
@ -113,13 +119,13 @@ class RdfMapping extends ConfigEntityBase implements RdfMappingInterface {
if (isset($this->fieldMappings[$field_name])) {
return $this->fieldMappings[$field_name];
}
return array();
return [];
}
/**
* {@inheritdoc}
*/
public function setFieldMapping($field_name, array $mapping = array()) {
public function setFieldMapping($field_name, array $mapping = []) {
$this->fieldMappings[$field_name] = $mapping;
return $this;
}

View file

@ -102,6 +102,6 @@ interface RdfMappingInterface extends ConfigEntityInterface {
* @return \Drupal\rdf\Entity\RdfMapping
* The RdfMapping object.
*/
public function setFieldMapping($field_name, array $mapping = array());
public function setFieldMapping($field_name, array $mapping = []);
}

View file

@ -22,7 +22,7 @@ class SchemaOrgDataConverter {
*
* @see http://schema.org/UserInteraction
*/
static function interactionCount($count, $arguments) {
public static function interactionCount($count, $arguments) {
$interaction_type = $arguments['interaction_type'];
return "$interaction_type:$count";
}

View file

@ -20,7 +20,7 @@ class CommentAttributesTest extends CommentTestBase {
*
* @var array
*/
public static $modules = array('views', 'node', 'comment', 'rdf');
public static $modules = ['views', 'node', 'comment', 'rdf'];
/**
* URI of the front page of the Drupal site.
@ -40,11 +40,11 @@ class CommentAttributesTest extends CommentTestBase {
parent::setUp();
// Enables anonymous user comments.
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array(
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [
'access comments' => TRUE,
'post comments' => TRUE,
'skip comment approval' => TRUE,
));
]);
// Allows anonymous to leave their contact information.
$this->setCommentAnonymous(COMMENT_ANONYMOUS_MAY_CONTACT);
$this->setCommentPreview(DRUPAL_OPTIONAL);
@ -58,53 +58,53 @@ class CommentAttributesTest extends CommentTestBase {
// Set relation between node and comment.
$article_mapping = rdf_get_mapping('node', 'article');
$comment_count_mapping = array(
'properties' => array('sioc:num_replies'),
$comment_count_mapping = [
'properties' => ['sioc:num_replies'],
'datatype' => 'xsd:integer',
'datatype_callback' => array('callable' => 'Drupal\rdf\CommonDataConverter::rawValue'),
);
'datatype_callback' => ['callable' => 'Drupal\rdf\CommonDataConverter::rawValue'],
];
$article_mapping->setFieldMapping('comment_count', $comment_count_mapping)->save();
// Save user mapping.
$user_mapping = rdf_get_mapping('user', 'user');
$username_mapping = array(
'properties' => array('foaf:name'),
);
$username_mapping = [
'properties' => ['foaf:name'],
];
$user_mapping->setFieldMapping('name', $username_mapping)->save();
$user_mapping->setFieldMapping('homepage', array('properties' => array('foaf:page'), 'mapping_type' => 'rel'))->save();
$user_mapping->setFieldMapping('homepage', ['properties' => ['foaf:page'], 'mapping_type' => 'rel'])->save();
// Save comment mapping.
$mapping = rdf_get_mapping('comment', 'comment');
$mapping->setBundleMapping(array('types' => array('sioc:Post', 'sioct:Comment')))->save();
$field_mappings = array(
'subject' => array(
'properties' => array('dc:title'),
),
'created' => array(
'properties' => array('dc:date', 'dc:created'),
$mapping->setBundleMapping(['types' => ['sioc:Post', 'sioct:Comment']])->save();
$field_mappings = [
'subject' => [
'properties' => ['dc:title'],
],
'created' => [
'properties' => ['dc:date', 'dc:created'],
'datatype' => 'xsd:dateTime',
'datatype_callback' => array('callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'),
),
'changed' => array(
'properties' => array('dc:modified'),
'datatype_callback' => ['callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'],
],
'changed' => [
'properties' => ['dc:modified'],
'datatype' => 'xsd:dateTime',
'datatype_callback' => array('callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'),
),
'comment_body' => array(
'properties' => array('content:encoded'),
),
'pid' => array(
'properties' => array('sioc:reply_of'),
'datatype_callback' => ['callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'],
],
'comment_body' => [
'properties' => ['content:encoded'],
],
'pid' => [
'properties' => ['sioc:reply_of'],
'mapping_type' => 'rel',
),
'uid' => array(
'properties' => array('sioc:has_creator'),
],
'uid' => [
'properties' => ['sioc:has_creator'],
'mapping_type' => 'rel',
),
'name' => array(
'properties' => array('foaf:name'),
),
);
],
'name' => [
'properties' => ['foaf:name'],
],
];
// Iterate over shared field mappings and save.
foreach ($field_mappings as $field_name => $field_mapping) {
$mapping->setFieldMapping($field_name, $field_mapping)->save();
@ -126,11 +126,11 @@ class CommentAttributesTest extends CommentTestBase {
$parser->parse($graph, $this->drupalGet('node'), 'rdfa', $this->baseUri);
// Number of comments.
$expected_value = array(
$expected_value = [
'type' => 'literal',
'value' => 2,
'datatype' => 'http://www.w3.org/2001/XMLSchema#integer',
);
];
$this->assertTrue($graph->hasProperty($this->nodeUri, 'http://rdfs.org/sioc/ns#num_replies', $expected_value), 'Number of comments found in RDF output of teaser view (sioc:num_replies).');
// Tests number of comments in full node view, expected value is the same.
@ -183,7 +183,7 @@ class CommentAttributesTest extends CommentTestBase {
$this->_testBasicCommentRdfaMarkup($graph, $comment1);
// Posts comment #2 as anonymous user.
$anonymous_user = array();
$anonymous_user = [];
$anonymous_user['name'] = $this->randomMachineName();
$anonymous_user['mail'] = 'tester@simpletest.org';
$anonymous_user['homepage'] = 'http://example.org/';
@ -222,22 +222,22 @@ class CommentAttributesTest extends CommentTestBase {
$parser->parse($graph, $this->drupalGet('node/' . $this->node->id()), 'rdfa', $this->baseUri);
// Tests the reply_of relationship of a first level comment.
$expected_value = array(
$expected_value = [
'type' => 'uri',
'value' => $this->nodeUri,
);
];
$this->assertTrue($graph->hasProperty($comment_1_uri, 'http://rdfs.org/sioc/ns#reply_of', $expected_value), 'Comment relation to its node found in RDF output (sioc:reply_of).');
// Tests the reply_of relationship of a second level comment.
$expected_value = array(
$expected_value = [
'type' => 'uri',
'value' => $this->nodeUri,
);
];
$this->assertTrue($graph->hasProperty($comment_2_uri, 'http://rdfs.org/sioc/ns#reply_of', $expected_value), 'Comment relation to its node found in RDF output (sioc:reply_of).');
$expected_value = array(
$expected_value = [
'type' => 'uri',
'value' => $comment_1_uri,
);
];
$this->assertTrue($graph->hasProperty($comment_2_uri, 'http://rdfs.org/sioc/ns#reply_of', $expected_value), 'Comment relation to its parent comment found in RDF output (sioc:reply_of).');
}
@ -251,61 +251,61 @@ class CommentAttributesTest extends CommentTestBase {
* @param $account
* An array containing information about an anonymous user.
*/
function _testBasicCommentRdfaMarkup($graph, CommentInterface $comment, $account = array()) {
$comment_uri = $comment->url('canonical', array('absolute' => TRUE));
public function _testBasicCommentRdfaMarkup($graph, CommentInterface $comment, $account = []) {
$comment_uri = $comment->url('canonical', ['absolute' => TRUE]);
// Comment type.
$expected_value = array(
$expected_value = [
'type' => 'uri',
'value' => 'http://rdfs.org/sioc/types#Comment',
);
];
$this->assertTrue($graph->hasProperty($comment_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Comment type found in RDF output (sioct:Comment).');
// Comment type.
$expected_value = array(
$expected_value = [
'type' => 'uri',
'value' => 'http://rdfs.org/sioc/ns#Post',
);
];
$this->assertTrue($graph->hasProperty($comment_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Comment type found in RDF output (sioc:Post).');
// Comment title.
$expected_value = array(
$expected_value = [
'type' => 'literal',
'value' => $comment->getSubject(),
'lang' => 'en',
);
];
$this->assertTrue($graph->hasProperty($comment_uri, 'http://purl.org/dc/terms/title', $expected_value), 'Comment subject found in RDF output (dc:title).');
// Comment date.
$expected_value = array(
$expected_value = [
'type' => 'literal',
'value' => format_date($comment->getCreatedTime(), 'custom', 'c', 'UTC'),
'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime',
);
];
$this->assertTrue($graph->hasProperty($comment_uri, 'http://purl.org/dc/terms/date', $expected_value), 'Comment date found in RDF output (dc:date).');
// Comment date.
$expected_value = array(
$expected_value = [
'type' => 'literal',
'value' => format_date($comment->getCreatedTime(), 'custom', 'c', 'UTC'),
'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime',
);
];
$this->assertTrue($graph->hasProperty($comment_uri, 'http://purl.org/dc/terms/created', $expected_value), 'Comment date found in RDF output (dc:created).');
// Comment body.
$expected_value = array(
$expected_value = [
'type' => 'literal',
'value' => $comment->comment_body->value . "\n",
'lang' => 'en',
);
];
$this->assertTrue($graph->hasProperty($comment_uri, 'http://purl.org/rss/1.0/modules/content/encoded', $expected_value), 'Comment body found in RDF output (content:encoded).');
// The comment author can be a registered user or an anonymous user.
if ($comment->getOwnerId() > 0) {
$author_uri = \Drupal::url('entity.user.canonical', ['user' => $comment->getOwnerId()], array('absolute' => TRUE));
$author_uri = \Drupal::url('entity.user.canonical', ['user' => $comment->getOwnerId()], ['absolute' => TRUE]);
// Comment relation to author.
$expected_value = array(
$expected_value = [
'type' => 'uri',
'value' => $author_uri,
);
];
$this->assertTrue($graph->hasProperty($comment_uri, 'http://rdfs.org/sioc/ns#has_creator', $expected_value), 'Comment relation to author found in RDF output (sioc:has_creator).');
}
else {
@ -321,18 +321,18 @@ class CommentAttributesTest extends CommentTestBase {
// Author name.
$name = empty($account["name"]) ? $this->webUser->getUsername() : $account["name"] . " (not verified)";
$expected_value = array(
$expected_value = [
'type' => 'literal',
'value' => $name,
);
];
$this->assertTrue($graph->hasProperty($author_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'Comment author name found in RDF output (foaf:name).');
// Comment author homepage (only for anonymous authors).
if ($comment->getOwnerId() == 0) {
$expected_value = array(
$expected_value = [
'type' => 'uri',
'value' => 'http://example.org/',
);
];
$this->assertTrue($graph->hasProperty($author_uri, 'http://xmlns.com/foaf/0.1/page', $expected_value), 'Comment author link found in RDF output (foaf:page).');
}
}
@ -353,8 +353,8 @@ class CommentAttributesTest extends CommentTestBase {
* @return \Drupal\comment\Entity\Comment
* The saved comment.
*/
function saveComment($nid, $uid, $contact = NULL, $pid = 0) {
$values = array(
public function saveComment($nid, $uid, $contact = NULL, $pid = 0) {
$values = [
'entity_id' => $nid,
'entity_type' => 'node',
'field_name' => 'comment',
@ -363,7 +363,7 @@ class CommentAttributesTest extends CommentTestBase {
'subject' => $this->randomMachineName(),
'comment_body' => $this->randomMachineName(),
'status' => 1,
);
];
if ($contact) {
$values += $contact;
}

View file

@ -1,147 +0,0 @@
<?php
namespace Drupal\rdf\Tests;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\taxonomy\Tests\TaxonomyTestBase;
/**
* Tests RDFa markup generation for taxonomy term fields.
*
* @group rdf
*/
class EntityReferenceFieldAttributesTest extends TaxonomyTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('rdf', 'field_test', 'file', 'image');
/**
* The name of the taxonomy term reference field used in the test.
*
* @var string
*/
protected $fieldName;
/**
* The vocabulary object used in the test.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $vocabulary;
protected function setUp() {
parent::setUp();
$web_user = $this->drupalCreateUser(array('bypass node access', 'administer taxonomy'));
$this->drupalLogin($web_user);
$this->vocabulary = $this->createVocabulary();
// Create the field.
$this->fieldName = 'field_taxonomy_test';
$handler_settings = array(
'target_bundles' => array(
$this->vocabulary->id() => $this->vocabulary->id(),
),
'auto_create' => TRUE,
);
$this->createEntityReferenceField('node', 'article', $this->fieldName, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')
->setComponent($this->fieldName, array('type' => 'options_select'))
->save();
entity_get_display('node', 'article', 'full')
->setComponent($this->fieldName, array('type' => 'entity_reference_label'))
->save();
// Set the RDF mapping for the new field.
rdf_get_mapping('node', 'article')
->setFieldMapping($this->fieldName, array(
'properties' => array('dc:subject'),
'mapping_type' => 'rel',
))
->save();
rdf_get_mapping('taxonomy_term', $this->vocabulary->id())
->setBundleMapping(array('types' => array('skos:Concept')))
->setFieldMapping('name', array('properties' => array('rdfs:label')))
->save();
}
/**
* Tests if file fields in teasers have correct resources.
*
* Ensure that file fields have the correct resource as the object in RDFa
* when displayed as a teaser.
*/
function testNodeTeaser() {
// Set the teaser display to show this field.
entity_get_display('node', 'article', 'teaser')
->setComponent($this->fieldName, array('type' => 'entity_reference_label'))
->save();
// Create a term in each vocabulary.
$term1 = $this->createTerm($this->vocabulary);
$term2 = $this->createTerm($this->vocabulary);
$taxonomy_term_1_uri = $term1->url('canonical', ['absolute' => TRUE]);
$taxonomy_term_2_uri = $term2->url('canonical', ['absolute' => TRUE]);
// Create the node.
$node = $this->drupalCreateNode(array('type' => 'article'));
$node->set($this->fieldName, array(
array('target_id' => $term1->id()),
array('target_id' => $term2->id()),
));
// Render the node.
$node_render_array = entity_view_multiple(array($node), 'teaser');
$html = \Drupal::service('renderer')->renderRoot($node_render_array);
// Parse the teaser.
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
$parser->parse($graph, $html, 'rdfa', $base_uri);
// Node relations to taxonomy terms.
$node_uri = $node->url('canonical', ['absolute' => TRUE]);
$expected_value = array(
'type' => 'uri',
'value' => $taxonomy_term_1_uri,
);
$this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/subject', $expected_value), 'Node to term relation found in RDF output (dc:subject).');
$expected_value = array(
'type' => 'uri',
'value' => $taxonomy_term_2_uri,
);
$this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/subject', $expected_value), 'Node to term relation found in RDF output (dc:subject).');
// Taxonomy terms triples.
// Term 1.
$expected_value = array(
'type' => 'uri',
'value' => 'http://www.w3.org/2004/02/skos/core#Concept',
);
// @todo Enable with https://www.drupal.org/node/2072791.
//$this->assertTrue($graph->hasProperty($taxonomy_term_1_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Taxonomy term type found in RDF output (skos:Concept).');
$expected_value = array(
'type' => 'literal',
'value' => $term1->getName(),
);
//$this->assertTrue($graph->hasProperty($taxonomy_term_1_uri, 'http://www.w3.org/2000/01/rdf-schema#label', $expected_value), 'Taxonomy term name found in RDF output (rdfs:label).');
// Term 2.
$expected_value = array(
'type' => 'uri',
'value' => 'http://www.w3.org/2004/02/skos/core#Concept',
);
//$this->assertTrue($graph->hasProperty($taxonomy_term_2_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Taxonomy term type found in RDF output (skos:Concept).');
$expected_value = array(
'type' => 'literal',
'value' => $term2->getName(),
);
//$this->assertTrue($graph->hasProperty($taxonomy_term_2_uri, 'http://www.w3.org/2000/01/rdf-schema#label', $expected_value), 'Taxonomy term name found in RDF output (rdfs:label).');
}
}

View file

@ -16,7 +16,7 @@ class TestDataConverter {
* @return string
* Returns the data.
*/
static function convertFoo($data) {
public static function convertFoo($data) {
return 'foo' . $data['value'];
}

View file

@ -1,99 +0,0 @@
<?php
namespace Drupal\rdf\Tests;
use Drupal\file\Tests\FileFieldTestBase;
use Drupal\file\Entity\File;
/**
* Tests the RDFa markup of filefields.
*
* @group rdf
*/
class FileFieldAttributesTest extends FileFieldTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('rdf', 'file');
/**
* The name of the file field used in the test.
*
* @var string
*/
protected $fieldName;
/**
* The file object used in the test.
*
* @var \Drupal\file\FileInterface
*/
protected $file;
/**
* The node object used in the test.
*
* @var \Drupal\node\NodeInterface
*/
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);
// Set the teaser display to show this field.
entity_get_display('node', 'article', 'teaser')
->setComponent($this->fieldName, array('type' => 'file_default'))
->save();
// Set the RDF mapping for the new field.
$mapping = rdf_get_mapping('node', 'article');
$mapping->setFieldMapping($this->fieldName, array('properties' => array('rdfs:seeAlso'), 'mapping_type' => 'rel'))->save();
$test_file = $this->getTestFile('text');
// Create a new node with the uploaded file.
$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);
}
/**
* Tests if file fields in teasers have correct resources.
*
* Ensure that file fields have the correct resource as the object in RDFa
* when displayed as a teaser.
*/
function testNodeTeaser() {
// Render the teaser.
$node_render_array = entity_view_multiple(array($this->node), 'teaser');
$html = \Drupal::service('renderer')->renderRoot($node_render_array);
// Parses front page where the node is displayed in its teaser form.
$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());
// Node relation to attached file.
$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');
}
}

View file

@ -17,33 +17,33 @@ class GetNamespacesTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('rdf', 'rdf_test_namespaces');
public static $modules = ['rdf', 'rdf_test_namespaces'];
/**
* Tests RDF namespaces.
*/
function testGetRdfNamespaces() {
public function testGetRdfNamespaces() {
// Fetches the front page and extracts RDFa 1.1 prefixes.
$this->drupalGet('');
$element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', array(
$element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', [
':prefix_binding' => 'rdfs: http://www.w3.org/2000/01/rdf-schema#',
));
]);
$this->assertTrue(!empty($element), 'A prefix declared once is displayed.');
$element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', array(
$element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', [
':prefix_binding' => 'foaf: http://xmlns.com/foaf/0.1/',
));
]);
$this->assertTrue(!empty($element), 'The same prefix declared in several implementations of hook_rdf_namespaces() is valid as long as all the namespaces are the same.');
$element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', array(
$element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', [
':prefix_binding' => 'foaf1: http://xmlns.com/foaf/0.1/',
));
]);
$this->assertTrue(!empty($element), 'Two prefixes can be assigned the same namespace.');
$element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', array(
$element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', [
':prefix_binding' => 'dc: http://purl.org/dc/terms/',
));
]);
$this->assertTrue(!empty($element), 'When a prefix has conflicting namespaces, the first declared one is used.');
}

View file

@ -1,44 +0,0 @@
<?php
namespace Drupal\rdf\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests hook_rdf_namespaces().
*
* @group rdf
*/
class GetRdfNamespacesTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('rdf', 'rdf_test_namespaces');
/**
* Tests getting RDF namespaces.
*/
function testGetRdfNamespaces() {
// Get all RDF namespaces.
$ns = rdf_get_namespaces();
$this->assertEqual($ns['rdfs'], 'http://www.w3.org/2000/01/rdf-schema#', 'A prefix declared once is included.');
$this->assertEqual($ns['foaf'], 'http://xmlns.com/foaf/0.1/', 'The same prefix declared in several implementations of hook_rdf_namespaces() is valid as long as all the namespaces are the same.');
$this->assertEqual($ns['foaf1'], 'http://xmlns.com/foaf/0.1/', 'Two prefixes can be assigned the same namespace.');
// Enable rdf_conflicting_namespaces to ensure that an exception is thrown
// when RDF namespaces are conflicting.
\Drupal::service('module_installer')->install(array('rdf_conflicting_namespaces'), TRUE);
try {
$ns = rdf_get_namespaces();
$this->fail('Expected exception not thrown for conflicting namespace declaration.');
}
catch (\Exception $e) {
$this->pass('Expected exception thrown: ' . $e->getMessage());
}
}
}

View file

@ -19,7 +19,7 @@ class ImageFieldAttributesTest extends ImageFieldTestBase {
*
* @var array
*/
public static $modules = array('rdf', 'image');
public static $modules = ['rdf', 'image'];
/**
* The name of the image field used in the test.
@ -52,11 +52,11 @@ class ImageFieldAttributesTest extends ImageFieldTestBase {
// Set the RDF mapping for the new field.
rdf_get_mapping('node', 'article')
->setFieldMapping($this->fieldName, array(
'properties' => array('og:image'),
->setFieldMapping($this->fieldName, [
'properties' => ['og:image'],
'mapping_type' => 'rel',
))
->setBundleMapping(array('types' => array()))
])
->setBundleMapping(['types' => []])
->save();
// Get the test image that simpletest provides.
@ -71,12 +71,12 @@ class ImageFieldAttributesTest extends ImageFieldTestBase {
/**
* Tests that image fields in teasers have correct resources.
*/
function testNodeTeaser() {
public function testNodeTeaser() {
// Set the display options for the teaser.
$display_options = array(
$display_options = [
'type' => 'image',
'settings' => array('image_style' => 'medium', 'image_link' => 'content'),
);
'settings' => ['image_style' => 'medium', 'image_link' => 'content'],
];
$display = entity_get_display('node', 'article', 'teaser');
$display->setComponent($this->fieldName, $display_options)
->save();
@ -96,17 +96,17 @@ class ImageFieldAttributesTest extends ImageFieldTestBase {
$image_uri = ImageStyle::load('medium')->buildUrl($this->file->getFileUri());
// Test relations from node to image.
$expected_value = array(
$expected_value = [
'type' => 'uri',
'value' => $image_uri,
);
];
$this->assertTrue($graph->hasProperty($node_uri, 'http://ogp.me/ns#image', $expected_value), 'Node to file relation found in RDF output (og:image).');
// Test image type.
$expected_value = array(
$expected_value = [
'type' => 'uri',
'value' => 'http://xmlns.com/foaf/0.1/Image',
);
];
$this->assertTrue($graph->hasProperty($image_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Image type found in RDF output (foaf:Image).');
}

View file

@ -1,94 +0,0 @@
<?php
namespace Drupal\rdf\Tests;
use Drupal\node\Tests\NodeTestBase;
/**
* Tests the RDFa markup of Nodes.
*
* @group rdf
*/
class NodeAttributesTest extends NodeTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('rdf');
protected function setUp() {
parent::setUp();
rdf_get_mapping('node', 'article')
->setBundleMapping(array(
'types' => array('sioc:Item', 'foaf:Document'),
))
->setFieldMapping('title', array(
'properties' => array('dc:title'),
))
->setFieldMapping('created', array(
'properties' => array('dc:date', 'dc:created'),
'datatype' => 'xsd:dateTime',
'datatype_callback' => array('callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'),
))
->save();
}
/**
* Creates a node of type article and tests its RDFa markup.
*/
function testNodeAttributes() {
// Create node with single quotation mark title to ensure it does not get
// escaped more than once.
$node = $this->drupalCreateNode(array(
'type' => 'article',
'title' => $this->randomMachineName(8) . "'",
));
$node_uri = $node->url('canonical', ['absolute' => TRUE]);
$base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
// Parses front page where the node is displayed in its teaser form.
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$parser->parse($graph, $this->drupalGet('node/' . $node->id()), 'rdfa', $base_uri);
// Inspects RDF graph output.
// Node type.
$expected_value = array(
'type' => 'uri',
'value' => 'http://rdfs.org/sioc/ns#Item',
);
$this->assertTrue($graph->hasProperty($node_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Node type found in RDF output (sioc:Item).');
// Node type.
$expected_value = array(
'type' => 'uri',
'value' => 'http://xmlns.com/foaf/0.1/Document',
);
$this->assertTrue($graph->hasProperty($node_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Node type found in RDF output (foaf:Document).');
// Node title.
$expected_value = array(
'type' => 'literal',
'value' => $node->getTitle(),
'lang' => 'en',
);
$this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/title', $expected_value), 'Node title found in RDF output (dc:title).');
// Node date (date format must be UTC).
$expected_value = array(
'type' => 'literal',
'value' => \Drupal::service('date.formatter')->format($node->getCreatedTime(), 'custom', 'c', 'UTC'),
'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime',
);
$this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/date', $expected_value), 'Node date found in RDF output (dc:date).');
// Node date (date format must be UTC).
$expected_value = array(
'type' => 'literal',
'value' => \Drupal::service('date.formatter')->format($node->getCreatedTime(), 'custom', 'c', 'UTC'),
'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime',
);
$this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/created', $expected_value), 'Node date found in RDF output (dc:created).');
}
}

View file

@ -1,537 +0,0 @@
<?php
namespace Drupal\rdf\Tests;
use Drupal\Core\Url;
use Drupal\file\Entity\File;
use Drupal\image\Entity\ImageStyle;
use Drupal\node\Entity\NodeType;
use Drupal\node\NodeInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\comment\Entity\Comment;
use Drupal\taxonomy\Entity\Term;
/**
* Tests the RDF mappings and RDFa markup of the standard profile.
*
* @group rdf
*/
class StandardProfileTest extends WebTestBase {
/**
* The profile used during tests.
*
* This purposefully uses the standard profile.
*
* @var string
*/
public $profile = 'standard';
/**
* @var string
*/
protected $baseUri;
/**
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* @var \Drupal\user\UserInterface
*/
protected $webUser;
/**
* @var \Drupal\taxonomy\TermInterface
*/
protected $term;
/**
* @var \Drupal\file\FileInterface
*/
protected $image;
/**
* @var \Drupal\node\NodeInterface
*/
protected $article;
/**
* @var \Drupal\comment\CommentInterface
*/
protected $articleComment;
/**
* @var \Drupal\node\NodeInterface
*/
protected $page;
/**
* @var string
*/
protected $imageUri;
/**
* @var string
*/
protected $termUri;
/**
* @var string
*/
protected $articleUri;
/**
* @var string
*/
protected $pageUri;
/**
* @var string
*/
protected $authorUri;
/**
* @var string
*/
protected $articleCommentUri;
/**
* @var string
*/
protected $commenterUri;
protected function setUp() {
parent::setUp();
// Use Classy theme for testing markup output.
\Drupal::service('theme_handler')->install(['classy']);
\Drupal::service('theme_handler')->setDefault('classy');
$this->baseUri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
// Create two test users.
$this->adminUser = $this->drupalCreateUser(array(
'administer content types',
'administer comments',
'access comments',
'access content',
));
$this->webUser = $this->drupalCreateUser(array(
'access comments',
'post comments',
'skip comment approval',
'access content',
));
$this->drupalLogin($this->adminUser);
// Create term.
$this->term = Term::create([
'name' => $this->randomMachineName(),
'description' => $this->randomMachineName(),
'vid' => 'tags',
]);
$this->term->save();
// Create image.
file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg');
$this->image = File::create(['uri' => 'public://example.jpg']);
$this->image->save();
// Create article.
$article_settings = array(
'type' => 'article',
'promote' => NODE_PROMOTED,
'field_image' => array(
array(
'target_id' => $this->image->id(),
),
),
'field_tags' => array(
array(
'target_id' => $this->term->id(),
),
),
);
$this->article = $this->drupalCreateNode($article_settings);
// Create second article to test teaser list.
$this->drupalCreateNode(array('type' => 'article', 'promote' => NODE_PROMOTED,));
// Create article comment.
$this->articleComment = $this->saveComment($this->article->id(), $this->webUser->id(), NULL, 0);
// Create page.
$this->page = $this->drupalCreateNode(array('type' => 'page'));
// Set URIs.
// Image.
$image_file = $this->article->get('field_image')->entity;
$this->imageUri = ImageStyle::load('large')->buildUrl($image_file->getFileUri());
// Term.
$this->termUri = $this->term->url('canonical', array('absolute' => TRUE));
// Article.
$this->articleUri = $this->article->url('canonical', array('absolute' => TRUE));
// Page.
$this->pageUri = $this->page->url('canonical', array('absolute' => TRUE));
// Author.
$this->authorUri = $this->adminUser->url('canonical', array('absolute' => TRUE));
// Comment.
$this->articleCommentUri = $this->articleComment->url('canonical', array('absolute' => TRUE));
// Commenter.
$this->commenterUri = $this->webUser->url('canonical', array('absolute' => TRUE));
$this->drupalLogout();
}
/**
* Tests that data is exposed correctly when using standard profile.
*
* Because tests using standard profile take a very long time to run, and
* because there is no manipulation of config or data within the test, simply
* run all the tests from within this function.
*/
public function testRdfaOutput() {
$this->doFrontPageRdfaTests();
$this->doArticleRdfaTests();
$this->doPageRdfaTests();
$this->doUserRdfaTests();
$this->doTermRdfaTests();
}
/**
* Tests that data is exposed in the front page teasers.
*/
protected function doFrontPageRdfaTests() {
// Feed the HTML into the parser.
$graph = $this->getRdfGraph(Url::fromRoute('<front>'));
// Ensure that both articles are listed.
$this->assertEqual(2, count($graph->allOfType('http://schema.org/Article')), 'Two articles found on front page.');
// Test interaction count.
$expected_value = array(
'type' => 'literal',
'value' => 'UserComments:1',
'lang' => 'en',
);
$this->assertTrue($graph->hasProperty($this->articleUri, 'http://schema.org/interactionCount', $expected_value), "Teaser comment count was found (schema:interactionCount).");
// Test the properties that are common between pages and articles and are
// displayed in full and teaser mode.
$this->assertRdfaCommonNodeProperties($graph, $this->article, "Teaser");
// Test properties that are displayed in both teaser and full mode.
$this->assertRdfaArticleProperties($graph, "Teaser");
// @todo Once the image points to the original instead of the processed
// image, move this to testArticleProperties().
$image_file = $this->article->get('field_image')->entity;
$image_uri = ImageStyle::load('medium')->buildUrl($image_file->getFileUri());
$expected_value = array(
'type' => 'uri',
'value' => $image_uri,
);
$this->assertTrue($graph->hasProperty($this->articleUri, 'http://schema.org/image', $expected_value), "Teaser image was found (schema:image).");
}
/**
* Tests that article data is exposed using RDFa.
*
* Two fields are not tested for output here. Changed date is not displayed
* on the page, so there is no test for output in node view. Comment count is
* displayed in teaser view, so it is tested in the front article tests.
*/
protected function doArticleRdfaTests() {
// Feed the HTML into the parser.
$graph = $this->getRdfGraph($this->article->urlInfo());
// Type.
$this->assertEqual($graph->type($this->articleUri), 'schema:Article', 'Article type was found (schema:Article).');
// Test the properties that are common between pages and articles.
$this->assertRdfaCommonNodeProperties($graph, $this->article, "Article");
// Test properties that are displayed in both teaser and full mode.
$this->assertRdfaArticleProperties($graph, "Article");
// Test the comment properties displayed on articles.
$this->assertRdfaNodeCommentProperties($graph);
// @todo Once the image points to the original instead of the processed
// image, move this to testArticleProperties().
$expected_value = array(
'type' => 'uri',
'value' => $this->imageUri,
);
$this->assertTrue($graph->hasProperty($this->articleUri, 'http://schema.org/image', $expected_value), "Article image was found (schema:image).");
}
/**
* Tests that page data is exposed using RDFa.
*
* Two fields are not tested for output here. Changed date is not displayed
* on the page, so there is no test for output in node view. Comment count is
* displayed in teaser view, so it is tested in the front page tests.
*/
protected function doPageRdfaTests() {
// The standard profile hides the created date on pages. Revert display to
// true for testing.
// @todo Clean-up standard profile defaults.
$node_type = NodeType::load('page');
$node_type->setDisplaySubmitted(TRUE);
$node_type->save();
// Feed the HTML into the parser.
$graph = $this->getRdfGraph($this->page->urlInfo());
// Type.
$this->assertEqual($graph->type($this->pageUri), 'schema:WebPage', 'Page type was found (schema:WebPage).');
// Test the properties that are common between pages and articles.
$this->assertRdfaCommonNodeProperties($graph, $this->page, "Page");
}
/**
* Tests that user data is exposed on user page.
*/
protected function doUserRdfaTests() {
$this->drupalLogin($this->rootUser);
// Feed the HTML into the parser.
$graph = $this->getRdfGraph($this->adminUser->urlInfo());
// User type.
$this->assertEqual($graph->type($this->authorUri), 'schema:Person', "User type was found (schema:Person) on user page.");
// User name.
$expected_value = array(
'type' => 'literal',
'value' => $this->adminUser->label(),
);
$this->assertTrue($graph->hasProperty($this->authorUri, 'http://schema.org/name', $expected_value), "User name was found (schema:name) on user page.");
$this->drupalLogout();
}
/**
* Tests that term data is exposed on term page.
*/
protected function doTermRdfaTests() {
// Feed the HTML into the parser.
$graph = $this->getRdfGraph($this->term->urlInfo());
// Term type.
$this->assertEqual($graph->type($this->termUri), 'schema:Thing', "Term type was found (schema:Thing) on term page.");
// Term name.
$expected_value = array(
'type' => 'literal',
'value' => $this->term->getName(),
'lang' => 'en',
);
$this->assertTrue($graph->hasProperty($this->termUri, 'http://schema.org/name', $expected_value), "Term name was found (schema:name) on term page.");
// @todo Add test for term description once it is a field:
// https://www.drupal.org/node/569434.
}
/**
* Tests output for properties held in common between articles and pages.
*
* @param \EasyRdf_Graph $graph
* The EasyRDF graph object.
* @param \Drupal\node\NodeInterface $node
* The node being displayed.
* @param string $message_prefix
* The word to use in the test assertion message.
*/
protected function assertRdfaCommonNodeProperties($graph, NodeInterface $node, $message_prefix) {
$uri = $node->url('canonical', array('absolute' => TRUE));
// Title.
$expected_value = array(
'type' => 'literal',
'value' => $node->get('title')->value,
'lang' => 'en',
);
$this->assertTrue($graph->hasProperty($uri, 'http://schema.org/name', $expected_value), "$message_prefix title was found (schema:name).");
// Created date.
$expected_value = array(
'type' => 'literal',
'value' => format_date($node->get('created')->value, 'custom', 'c', 'UTC'),
'lang' => 'en',
);
$this->assertTrue($graph->hasProperty($uri, 'http://schema.org/dateCreated', $expected_value), "$message_prefix created date was found (schema:dateCreated) in teaser.");
// Body.
$expected_value = array(
'type' => 'literal',
'value' => $node->get('body')->value,
'lang' => 'en',
);
$this->assertTrue($graph->hasProperty($uri, 'http://schema.org/text', $expected_value), "$message_prefix body was found (schema:text) in teaser.");
// Author.
$expected_value = array(
'type' => 'uri',
'value' => $this->authorUri,
);
$this->assertTrue($graph->hasProperty($uri, 'http://schema.org/author', $expected_value), "$message_prefix author was found (schema:author) in teaser.");
// Author type.
$this->assertEqual($graph->type($this->authorUri), 'schema:Person', "$message_prefix author type was found (schema:Person).");
// Author name.
$expected_value = array(
'type' => 'literal',
'value' => $this->adminUser->label(),
);
$this->assertTrue($graph->hasProperty($this->authorUri, 'http://schema.org/name', $expected_value), "$message_prefix author name was found (schema:name).");
}
/**
* Tests output for article properties displayed in both view modes.
*
* @param \EasyRdf_Graph $graph
* The EasyRDF graph object.
* @param string $message_prefix
* The word to use in the test assertion message.
*/
protected function assertRdfaArticleProperties($graph, $message_prefix) {
// Tags.
$expected_value = array(
'type' => 'uri',
'value' => $this->termUri,
);
$this->assertTrue($graph->hasProperty($this->articleUri, 'http://schema.org/about', $expected_value), "$message_prefix tag was found (schema:about).");
// Tag type.
// @todo Enable with https://www.drupal.org/node/2072791.
//$this->assertEqual($graph->type($this->termUri), 'schema:Thing', 'Tag type was found (schema:Thing).');
// Tag name.
$expected_value = array(
'type' => 'literal',
'value' => $this->term->getName(),
'lang' => 'en',
);
// @todo Enable with https://www.drupal.org/node/2072791.
//$this->assertTrue($graph->hasProperty($this->termUri, 'http://schema.org/name', $expected_value), "$message_prefix name was found (schema:name).");
}
/**
* Tests output for comment properties on nodes in full page view mode.
*
* @param \EasyRdf_Graph $graph
* The EasyRDF graph object.
*/
protected function assertRdfaNodeCommentProperties($graph) {
// Relationship between node and comment.
$expected_value = array(
'type' => 'uri',
'value' => $this->articleCommentUri,
);
$this->assertTrue($graph->hasProperty($this->articleUri, 'http://schema.org/comment', $expected_value), 'Relationship between node and comment found (schema:comment).');
// Comment type.
$this->assertEqual($graph->type($this->articleCommentUri), 'schema:Comment', 'Comment type was found (schema:Comment).');
// Comment title.
$expected_value = array(
'type' => 'literal',
'value' => $this->articleComment->get('subject')->value,
'lang' => 'en',
);
$this->assertTrue($graph->hasProperty($this->articleCommentUri, 'http://schema.org/name', $expected_value), 'Article comment title was found (schema:name).');
// Comment created date.
$expected_value = array(
'type' => 'literal',
'value' => format_date($this->articleComment->get('created')->value, 'custom', 'c', 'UTC'),
'lang' => 'en',
);
$this->assertTrue($graph->hasProperty($this->articleCommentUri, 'http://schema.org/dateCreated', $expected_value), 'Article comment created date was found (schema:dateCreated).');
// Comment body.
$text = $this->articleComment->get('comment_body')->value;
$expected_value = array(
'type' => 'literal',
// There is an extra carriage return in the when parsing comments as
// output by Bartik, so it must be added to the expected value.
'value' => "$text
",
'lang' => 'en',
);
$this->assertTrue($graph->hasProperty($this->articleCommentUri, 'http://schema.org/text', $expected_value), 'Article comment body was found (schema:text).');
// Comment uid.
$expected_value = array(
'type' => 'uri',
'value' => $this->commenterUri,
);
$this->assertTrue($graph->hasProperty($this->articleCommentUri, 'http://schema.org/author', $expected_value), 'Article comment author was found (schema:author).');
// Comment author type.
$this->assertEqual($graph->type($this->commenterUri), 'schema:Person', 'Comment author type was found (schema:Person).');
// Comment author name.
$expected_value = array(
'type' => 'literal',
'value' => $this->webUser->getUsername(),
);
$this->assertTrue($graph->hasProperty($this->commenterUri, 'http://schema.org/name', $expected_value), 'Comment author name was found (schema:name).');
}
/**
* Creates a comment entity.
*
* @param int $nid
* Node id which will hold the comment.
* @param int $uid
* User id of the author of the comment. Can be NULL if $contact provided.
* @param mixed $contact
* Set to NULL for no contact info, TRUE to ignore success checking, and
* array of values to set contact info.
* @param int $pid
* Comment id of the parent comment in a thread.
*
* @return \Drupal\comment\Entity\Comment
* The saved comment.
*/
protected function saveComment($nid, $uid, $contact = NULL, $pid = 0) {
$values = array(
'entity_id' => $nid,
'entity_type' => 'node',
'field_name' => 'comment',
'uid' => $uid,
'pid' => $pid,
'subject' => $this->randomMachineName(),
'comment_body' => $this->randomMachineName(),
'status' => 1,
);
if ($contact) {
$values += $contact;
}
$comment = Comment::create($values);
$comment->save();
return $comment;
}
/**
* Get the EasyRdf_Graph object for a page.
*
* @param \Drupal\Core\Url $url
* The URL object for the page.
*
* @return \EasyRdf_Graph
* The RDF graph object.
*/
protected function getRdfGraph(Url $url) {
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$parser->parse($graph, $this->drupalGet($url), 'rdfa', $this->baseUri);
return $graph;
}
}

View file

@ -1,81 +0,0 @@
<?php
namespace Drupal\rdf\Tests;
use Drupal\taxonomy\Tests\TaxonomyTestBase;
/**
* Tests the RDFa markup of Taxonomy terms.
*
* @group rdf
*/
class TaxonomyAttributesTest extends TaxonomyTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('rdf', 'views');
/**
* Vocabulary created for testing purposes.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $vocabulary;
protected function setUp() {
parent::setUp();
$this->vocabulary = $this->createVocabulary();
// RDF mapping - term bundle.
rdf_get_mapping('taxonomy_term', $this->vocabulary->id())
->setBundleMapping(array('types' => array('skos:Concept')))
->setFieldMapping('name', array(
'properties' => array('rdfs:label', 'skos:prefLabel'),
))
->save();
}
/**
* Creates a random term and ensures the RDF output is correct.
*/
function testTaxonomyTermRdfaAttributes() {
$term = $this->createTerm($this->vocabulary);
$term_uri = $term->url('canonical', ['absolute' => TRUE]);
// Parses the term's page and checks that the RDF output is correct.
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
$parser->parse($graph, $this->drupalGet('taxonomy/term/' . $term->id()), 'rdfa', $base_uri);
// Inspects RDF graph output.
// Term type.
$expected_value = array(
'type' => 'uri',
'value' => 'http://www.w3.org/2004/02/skos/core#Concept',
);
$this->assertTrue($graph->hasProperty($term_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Term type found in RDF output (skos:Concept).');
// Term label.
$expected_value = array(
'type' => 'literal',
'value' => $term->getName(),
'lang' => 'en',
);
$this->assertTrue($graph->hasProperty($term_uri, 'http://www.w3.org/2000/01/rdf-schema#label', $expected_value), 'Term label found in RDF output (rdfs:label).');
// Term label.
$expected_value = array(
'type' => 'literal',
'value' => $term->getName(),
'lang' => 'en',
);
$this->assertTrue($graph->hasProperty($term_uri, 'http://www.w3.org/2004/02/skos/core#prefLabel', $expected_value), 'Term label found in RDF output (skos:prefLabel).');
// @todo Add test for term description once it is a field:
// https://www.drupal.org/node/569434.
}
}

View file

@ -1,108 +0,0 @@
<?php
namespace Drupal\rdf\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests the RDFa markup of Users.
*
* @group rdf
*/
class UserAttributesTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('rdf', 'node');
protected function setUp() {
parent::setUp();
rdf_get_mapping('user', 'user')
->setBundleMapping(array(
'types' => array('sioc:UserAccount'),
))
->setFieldMapping('name', array(
'properties' => array('foaf:name'),
))
->save();
}
/**
* Tests if default mapping for user is being used.
*
* Creates a random user and ensures the default mapping for the user is
* being used.
*/
function testUserAttributesInMarkup() {
// Creates users that should and should not be truncated
// by template_preprocess_username (20 characters)
// one of these users tests right on the cusp (20).
$user1 = $this->drupalCreateUser(array('access user profiles'));
$authors = array(
$this->drupalCreateUser(array(), $this->randomMachineName(30)),
$this->drupalCreateUser(array(), $this->randomMachineName(20)),
$this->drupalCreateUser(array(), $this->randomMachineName(5))
);
$this->drupalLogin($user1);
$this->drupalCreateContentType(array('type' => 'article'));
/** @var \Drupal\user\UserInterface[] $authors */
foreach ($authors as $author) {
$account_uri = $author->url('canonical', ['absolute' => TRUE]);
// Parses the user profile page where the default bundle mapping for user
// should be used.
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
$parser->parse($graph, $this->drupalGet('user/' . $author->id()), 'rdfa', $base_uri);
// Inspects RDF graph output.
// User type.
$expected_value = array(
'type' => 'uri',
'value' => 'http://rdfs.org/sioc/ns#UserAccount',
);
$this->assertTrue($graph->hasProperty($account_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'User type found in RDF output (sioc:UserAccount).');
// User name.
$expected_value = array(
'type' => 'literal',
'value' => $author->getUsername(),
);
$this->assertTrue($graph->hasProperty($account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');
// User creates a node.
$this->drupalLogin($author);
$node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
$this->drupalLogin($user1);
// Parses the node created by the user.
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
$parser->parse($graph, $this->drupalGet('node/' . $node->id()), 'rdfa', $base_uri);
// Ensures the default bundle mapping for user is used on the Authored By
// information on the node.
$expected_value = array(
'type' => 'uri',
'value' => 'http://rdfs.org/sioc/ns#UserAccount',
);
$this->assertTrue($graph->hasProperty($account_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'User type found in RDF output (sioc:UserAccount).');
// User name.
$expected_value = array(
'type' => 'literal',
'value' => $author->getUsername(),
);
$this->assertTrue($graph->hasProperty($account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');
}
}
}