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

@ -9,7 +9,7 @@
* Implements hook_rdf_namespaces().
*/
function rdf_conflicting_namespaces_rdf_namespaces() {
return array(
return [
'dc' => 'http://purl.org/conflicting/namespace',
);
];
}

View file

@ -9,8 +9,8 @@
* Implements hook_rdf_namespaces().
*/
function rdf_test_namespaces_rdf_namespaces() {
return array(
return [
'foaf' => 'http://xmlns.com/foaf/0.1/',
'foaf1' => 'http://xmlns.com/foaf/0.1/',
);
];
}

View file

@ -0,0 +1,147 @@
<?php
namespace Drupal\Tests\rdf\Functional;
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 = ['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(['bypass node access', 'administer taxonomy']);
$this->drupalLogin($web_user);
$this->vocabulary = $this->createVocabulary();
// Create the field.
$this->fieldName = 'field_taxonomy_test';
$handler_settings = [
'target_bundles' => [
$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, ['type' => 'options_select'])
->save();
entity_get_display('node', 'article', 'full')
->setComponent($this->fieldName, ['type' => 'entity_reference_label'])
->save();
// Set the RDF mapping for the new field.
rdf_get_mapping('node', 'article')
->setFieldMapping($this->fieldName, [
'properties' => ['dc:subject'],
'mapping_type' => 'rel',
])
->save();
rdf_get_mapping('taxonomy_term', $this->vocabulary->id())
->setBundleMapping(['types' => ['skos:Concept']])
->setFieldMapping('name', ['properties' => ['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.
*/
public function testNodeTeaser() {
// Set the teaser display to show this field.
entity_get_display('node', 'article', 'teaser')
->setComponent($this->fieldName, ['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(['type' => 'article']);
$node->set($this->fieldName, [
['target_id' => $term1->id()],
['target_id' => $term2->id()],
]);
// Render the node.
$node_render_array = entity_view_multiple([$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 = [
'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 = [
'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 = [
'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 = [
'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 = [
'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 = [
'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

@ -0,0 +1,99 @@
<?php
namespace Drupal\Tests\rdf\Functional;
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 = ['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, ['type' => 'file_default'])
->save();
// Set the RDF mapping for the new field.
$mapping = rdf_get_mapping('node', 'article');
$mapping->setFieldMapping($this->fieldName, ['properties' => ['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([$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.
*/
public function testNodeTeaser() {
// Render the teaser.
$node_render_array = entity_view_multiple([$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 = [
'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

@ -0,0 +1,44 @@
<?php
namespace Drupal\Tests\rdf\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests hook_rdf_namespaces().
*
* @group rdf
*/
class GetRdfNamespacesTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['rdf', 'rdf_test_namespaces'];
/**
* Tests getting RDF namespaces.
*/
public 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(['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

@ -0,0 +1,94 @@
<?php
namespace Drupal\Tests\rdf\Functional;
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 = ['rdf'];
protected function setUp() {
parent::setUp();
rdf_get_mapping('node', 'article')
->setBundleMapping([
'types' => ['sioc:Item', 'foaf:Document'],
])
->setFieldMapping('title', [
'properties' => ['dc:title'],
])
->setFieldMapping('created', [
'properties' => ['dc:date', 'dc:created'],
'datatype' => 'xsd:dateTime',
'datatype_callback' => ['callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'],
])
->save();
}
/**
* Creates a node of type article and tests its RDFa markup.
*/
public function testNodeAttributes() {
// Create node with single quotation mark title to ensure it does not get
// escaped more than once.
$node = $this->drupalCreateNode([
'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 = [
'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 = [
'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 = [
'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 = [
'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 = [
'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

@ -0,0 +1,537 @@
<?php
namespace Drupal\Tests\rdf\Functional;
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\Tests\BrowserTestBase;
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 BrowserTestBase {
/**
* 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']);
$this->config('system.theme')->set('default', 'classy')->save();
$this->baseUri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
// Create two test users.
$this->adminUser = $this->drupalCreateUser([
'administer content types',
'administer comments',
'access comments',
'access content',
]);
$this->webUser = $this->drupalCreateUser([
'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 = [
'type' => 'article',
'promote' => NodeInterface::PROMOTED,
'field_image' => [
[
'target_id' => $this->image->id(),
],
],
'field_tags' => [
[
'target_id' => $this->term->id(),
],
],
];
$this->article = $this->drupalCreateNode($article_settings);
// Create second article to test teaser list.
$this->drupalCreateNode(['type' => 'article', 'promote' => NodeInterface::PROMOTED]);
// Create article comment.
$this->articleComment = $this->saveComment($this->article->id(), $this->webUser->id(), NULL, 0);
// Create page.
$this->page = $this->drupalCreateNode(['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', ['absolute' => TRUE]);
// Article.
$this->articleUri = $this->article->url('canonical', ['absolute' => TRUE]);
// Page.
$this->pageUri = $this->page->url('canonical', ['absolute' => TRUE]);
// Author.
$this->authorUri = $this->adminUser->url('canonical', ['absolute' => TRUE]);
// Comment.
$this->articleCommentUri = $this->articleComment->url('canonical', ['absolute' => TRUE]);
// Commenter.
$this->commenterUri = $this->webUser->url('canonical', ['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 = [
'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 = [
'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 = [
'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 = [
'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 = [
'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', ['absolute' => TRUE]);
// Title.
$expected_value = [
'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 = [
'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 = [
'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 = [
'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 = [
'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 = [
'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 = [
'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 = [
'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 = [
'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 = [
'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 = [
'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 = [
'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 = [
'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 = [
'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

@ -0,0 +1,81 @@
<?php
namespace Drupal\Tests\rdf\Functional;
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 = ['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(['types' => ['skos:Concept']])
->setFieldMapping('name', [
'properties' => ['rdfs:label', 'skos:prefLabel'],
])
->save();
}
/**
* Creates a random term and ensures the RDF output is correct.
*/
public 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 = [
'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 = [
'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 = [
'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

@ -0,0 +1,108 @@
<?php
namespace Drupal\Tests\rdf\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the RDFa markup of Users.
*
* @group rdf
*/
class UserAttributesTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['rdf', 'node'];
protected function setUp() {
parent::setUp();
rdf_get_mapping('user', 'user')
->setBundleMapping([
'types' => ['sioc:UserAccount'],
])
->setFieldMapping('name', [
'properties' => ['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.
*/
public 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(['access user profiles']);
$authors = [
$this->drupalCreateUser([], $this->randomMachineName(30)),
$this->drupalCreateUser([], $this->randomMachineName(20)),
$this->drupalCreateUser([], $this->randomMachineName(5))
];
$this->drupalLogin($user1);
$this->drupalCreateContentType(['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 = [
'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 = [
'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(['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 = [
'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 = [
'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).');
}
}
}

View file

@ -16,7 +16,7 @@ class CrudTest extends KernelTestBase {
*
* @var array
*/
public static $modules = array('entity_test', 'rdf', 'system');
public static $modules = ['entity_test', 'rdf', 'system'];
/**
* @var string
@ -42,7 +42,7 @@ class CrudTest extends KernelTestBase {
/**
* Tests creation of RDF mapping.
*/
function testMappingCreation() {
public function testMappingCreation() {
$mapping_config_name = "{$this->prefix}.{$this->entityType}.{$this->bundle}";
// Save bundle mapping config.
@ -55,20 +55,20 @@ class CrudTest extends KernelTestBase {
/**
* Test the handling of bundle mappings.
*/
function testBundleMapping() {
public function testBundleMapping() {
// Test that the bundle mapping can be saved.
$types = array('sioc:Post', 'foaf:Document');
$types = ['sioc:Post', 'foaf:Document'];
rdf_get_mapping($this->entityType, $this->bundle)
->setBundleMapping(array('types' => $types))
->setBundleMapping(['types' => $types])
->save();
$bundle_mapping = rdf_get_mapping($this->entityType, $this->bundle)
->getBundleMapping();
$this->assertEqual($types, $bundle_mapping['types'], 'Bundle mapping saved.');
// Test that the bundle mapping can be edited.
$types = array('schema:BlogPosting');
$types = ['schema:BlogPosting'];
rdf_get_mapping($this->entityType, $this->bundle)
->setBundleMapping(array('types' => $types))
->setBundleMapping(['types' => $types])
->save();
$bundle_mapping = rdf_get_mapping($this->entityType, $this->bundle)
->getBundleMapping();
@ -78,15 +78,15 @@ class CrudTest extends KernelTestBase {
/**
* Test the handling of field mappings.
*/
function testFieldMapping() {
public function testFieldMapping() {
$field_name = 'created';
// Test that the field mapping can be saved.
$mapping = array(
'properties' => array('dc:created'),
$mapping = [
'properties' => ['dc:created'],
'datatype' => 'xsd:dateTime',
'datatype_callback' => array('callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'),
);
'datatype_callback' => ['callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'],
];
rdf_get_mapping($this->entityType, $this->bundle)
->setFieldMapping($field_name, $mapping)
->save();
@ -95,11 +95,11 @@ class CrudTest extends KernelTestBase {
$this->assertEqual($mapping, $field_mapping, 'Field mapping saved.');
// Test that the field mapping can be edited.
$mapping = array(
'properties' => array('dc:date'),
$mapping = [
'properties' => ['dc:date'],
'datatype' => 'foo:bar',
'datatype_callback' => array('callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'),
);
'datatype_callback' => ['callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'],
];
rdf_get_mapping($this->entityType, $this->bundle)
->setFieldMapping($field_name, $mapping)
->save();

View file

@ -26,7 +26,7 @@ class DateTimeFieldRdfaTest extends FieldRdfaTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('datetime');
public static $modules = ['datetime'];
protected function setUp() {
parent::setUp();
@ -35,12 +35,12 @@ class DateTimeFieldRdfaTest extends FieldRdfaTestBase {
// Add the mapping.
$mapping = rdf_get_mapping('entity_test', 'entity_test');
$mapping->setFieldMapping($this->fieldName, array(
'properties' => array('schema:dateCreated'),
))->save();
$mapping->setFieldMapping($this->fieldName, [
'properties' => ['schema:dateCreated'],
])->save();
// Set up test entity.
$this->entity = EntityTest::create(array());
$this->entity = EntityTest::create([]);
$this->entity->{$this->fieldName}->value = $this->testValue;
}
@ -48,7 +48,7 @@ class DateTimeFieldRdfaTest extends FieldRdfaTestBase {
* Tests the default formatter.
*/
public function testDefaultFormatter() {
$this->assertFormatterRdfa(array('type' => 'datetime_default'), 'http://schema.org/dateCreated', array('value' => $this->testValue . 'Z', 'type' => 'literal', 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime'));
$this->assertFormatterRdfa(['type' => 'datetime_default'], 'http://schema.org/dateCreated', ['value' => $this->testValue . 'Z', 'type' => 'literal', 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime']);
}
}

View file

@ -19,7 +19,7 @@ class EmailFieldRdfaTest extends FieldRdfaTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('text');
public static $modules = ['text'];
protected function setUp() {
parent::setUp();
@ -28,13 +28,13 @@ class EmailFieldRdfaTest extends FieldRdfaTestBase {
// Add the mapping.
$mapping = rdf_get_mapping('entity_test', 'entity_test');
$mapping->setFieldMapping($this->fieldName, array(
'properties' => array('schema:email'),
))->save();
$mapping->setFieldMapping($this->fieldName, [
'properties' => ['schema:email'],
])->save();
// Set up test values.
$this->testValue = 'test@example.com';
$this->entity = EntityTest::create(array());
$this->entity = EntityTest::create([]);
$this->entity->{$this->fieldName}->value = $this->testValue;
}
@ -43,9 +43,9 @@ class EmailFieldRdfaTest extends FieldRdfaTestBase {
*/
public function testAllFormatters() {
// Test the plain formatter.
$this->assertFormatterRdfa(array('type' => 'string'), 'http://schema.org/email', array('value' => $this->testValue));
$this->assertFormatterRdfa(['type' => 'string'], 'http://schema.org/email', ['value' => $this->testValue]);
// Test the mailto formatter.
$this->assertFormatterRdfa(array('type' => 'email_mailto'), 'http://schema.org/email', array('value' => $this->testValue));
$this->assertFormatterRdfa(['type' => 'email_mailto'], 'http://schema.org/email', ['value' => $this->testValue]);
}
}

View file

@ -52,7 +52,7 @@ class EntityReferenceRdfaTest extends FieldRdfaTestBase {
$this->installEntitySchema('entity_test_rev');
// Give anonymous users permission to view test entities.
$this->installConfig(array('user'));
$this->installConfig(['user']);
Role::load(RoleInterface::ANONYMOUS_ID)
->grantPermission('view test entity')
->save();
@ -61,20 +61,20 @@ class EntityReferenceRdfaTest extends FieldRdfaTestBase {
// Add the mapping.
$mapping = rdf_get_mapping('entity_test', 'entity_test');
$mapping->setFieldMapping($this->fieldName, array(
'properties' => array('schema:knows'),
))->save();
$mapping->setFieldMapping($this->fieldName, [
'properties' => ['schema:knows'],
])->save();
// Create the entity to be referenced.
$this->targetEntity = $this->container->get('entity_type.manager')
->getStorage($this->entityType)
->create(array('name' => $this->randomMachineName()));
->create(['name' => $this->randomMachineName()]);
$this->targetEntity->save();
// Create the entity that will have the entity reference field.
$this->entity = $this->container->get('entity_type.manager')
->getStorage($this->entityType)
->create(array('name' => $this->randomMachineName()));
->create(['name' => $this->randomMachineName()]);
$this->entity->save();
$this->entity->{$this->fieldName}->entity = $this->targetEntity;
$this->uri = $this->getAbsoluteUri($this->entity);
@ -87,9 +87,9 @@ class EntityReferenceRdfaTest extends FieldRdfaTestBase {
$entity_uri = $this->getAbsoluteUri($this->targetEntity);
// Tests the label formatter.
$this->assertFormatterRdfa(array('type' => 'entity_reference_label'), 'http://schema.org/knows', array('value' => $entity_uri, 'type' => 'uri'));
$this->assertFormatterRdfa(['type' => 'entity_reference_label'], 'http://schema.org/knows', ['value' => $entity_uri, 'type' => 'uri']);
// Tests the entity formatter.
$this->assertFormatterRdfa(array('type' => 'entity_reference_entity_view'), 'http://schema.org/knows', array('value' => $entity_uri, 'type' => 'uri'));
$this->assertFormatterRdfa(['type' => 'entity_reference_entity_view'], 'http://schema.org/knows', ['value' => $entity_uri, 'type' => 'uri']);
}
}

View file

@ -19,23 +19,23 @@ class FieldRdfaDatatypeCallbackTest extends FieldRdfaTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('text', 'filter');
public static $modules = ['text', 'filter'];
protected function setUp() {
parent::setUp();
$this->createTestField();
$this->installConfig(array('filter'));
$this->installConfig(['filter']);
// Add the mapping.
$mapping = rdf_get_mapping('entity_test', 'entity_test');
$mapping->setFieldMapping($this->fieldName, array(
'properties' => array('schema:interactionCount'),
'datatype_callback' => array(
$mapping->setFieldMapping($this->fieldName, [
'properties' => ['schema:interactionCount'],
'datatype_callback' => [
'callable' => 'Drupal\rdf\Tests\Field\TestDataConverter::convertFoo',
),
))->save();
],
])->save();
// Set up test values.
$this->testValue = $this->randomMachineName();
@ -51,7 +51,7 @@ class FieldRdfaDatatypeCallbackTest extends FieldRdfaTestBase {
*/
public function testDefaultFormatter() {
// Expected value is the output of the datatype callback, not the raw value.
$this->assertFormatterRdfa(array('type' => 'text_default'), 'http://schema.org/interactionCount', array('value' => 'foo' . $this->testValue));
$this->assertFormatterRdfa(['type' => 'text_default'], 'http://schema.org/interactionCount', ['value' => 'foo' . $this->testValue]);
}
}

View file

@ -48,7 +48,7 @@ abstract class FieldRdfaTestBase extends FieldKernelTestBase {
*
* @var array
*/
public static $modules = array('rdf');
public static $modules = ['rdf'];
/**
* @var string
@ -83,7 +83,7 @@ abstract class FieldRdfaTestBase extends FieldKernelTestBase {
* - datatype: (optional) The datatype of the value (e.g. xsd:dateTime).
*/
protected function assertFormatterRdfa($formatter, $property, $expected_rdf_value) {
$expected_rdf_value += array('type' => 'literal');
$expected_rdf_value += ['type' => 'literal'];
// The field formatter will be rendered inside the entity. Set the field
// formatter in the entity display options before rendering the entity.
@ -111,12 +111,12 @@ abstract class FieldRdfaTestBase extends FieldKernelTestBase {
* @param array $field_settings
* (optional) An array of field settings.
*/
protected function createTestField($field_settings = array()) {
FieldStorageConfig::create(array(
protected function createTestField($field_settings = []) {
FieldStorageConfig::create([
'field_name' => $this->fieldName,
'entity_type' => 'entity_test',
'type' => $this->fieldType,
))->save();
])->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => $this->fieldName,
@ -135,7 +135,7 @@ abstract class FieldRdfaTestBase extends FieldKernelTestBase {
* The absolute URI.
*/
protected function getAbsoluteUri($entity) {
return $entity->url('canonical', array('absolute' => TRUE));
return $entity->url('canonical', ['absolute' => TRUE]);
}
/**
@ -172,14 +172,14 @@ abstract class FieldRdfaTestBase extends FieldKernelTestBase {
* format and return values see the SimpleXML documentation,
* http://php.net/manual/function.simplexml-element-xpath.php.
*/
protected function xpathContent($content, $xpath, array $arguments = array()) {
protected function xpathContent($content, $xpath, array $arguments = []) {
if ($elements = $this->parseContent($content)) {
$xpath = $this->buildXPathQuery($xpath, $arguments);
$result = $elements->xpath($xpath);
// Some combinations of PHP / libxml versions return an empty array
// instead of the documented FALSE. Forcefully convert any falsish values
// to an empty array to allow foreach(...) constructions.
return $result ? $result : array();
return $result ? $result : [];
}
else {
return FALSE;

View file

@ -19,7 +19,7 @@ class LinkFieldRdfaTest extends FieldRdfaTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('link', 'text');
public static $modules = ['link', 'text'];
/**
* {@inheritdoc}
@ -31,9 +31,9 @@ class LinkFieldRdfaTest extends FieldRdfaTestBase {
// Add the mapping.
$mapping = rdf_get_mapping('entity_test', 'entity_test');
$mapping->setFieldMapping($this->fieldName, array(
'properties' => array('schema:link'),
))->save();
$mapping->setFieldMapping($this->fieldName, [
'properties' => ['schema:link'],
])->save();
}
@ -43,14 +43,14 @@ class LinkFieldRdfaTest extends FieldRdfaTestBase {
public function testAllFormattersExternal() {
// Set up test values.
$this->testValue = 'http://test.me/foo/bar/neque/porro/quisquam/est/qui-dolorem?foo/bar/neque/porro/quisquam/est/qui-dolorem';
$this->entity = EntityTest::create(array());
$this->entity = EntityTest::create([]);
$this->entity->{$this->fieldName}->uri = $this->testValue;
// Set up the expected result.
$expected_rdf = array(
$expected_rdf = [
'value' => $this->testValue,
'type' => 'uri',
);
];
$this->runTestAllFormatters($expected_rdf, 'external');
}
@ -61,15 +61,15 @@ class LinkFieldRdfaTest extends FieldRdfaTestBase {
public function testAllFormattersInternal() {
// Set up test values.
$this->testValue = 'admin';
$this->entity = EntityTest::create(array());
$this->entity = EntityTest::create([]);
$this->entity->{$this->fieldName}->uri = 'internal:/admin';
// Set up the expected result.
// AssertFormatterRdfa looks for a full path.
$expected_rdf = array(
$expected_rdf = [
'value' => $this->uri . '/' . $this->testValue,
'type' => 'uri',
);
];
$this->runTestAllFormatters($expected_rdf, 'internal');
}
@ -80,14 +80,14 @@ class LinkFieldRdfaTest extends FieldRdfaTestBase {
public function testAllFormattersFront() {
// Set up test values.
$this->testValue = '/';
$this->entity = EntityTest::create(array());
$this->entity = EntityTest::create([]);
$this->entity->{$this->fieldName}->uri = 'internal:/';
// Set up the expected result.
$expected_rdf = array(
$expected_rdf = [
'value' => $this->uri . '/',
'type' => 'uri',
);
];
$this->runTestAllFormatters($expected_rdf, 'front');
}
@ -98,86 +98,86 @@ class LinkFieldRdfaTest extends FieldRdfaTestBase {
public function runTestAllFormatters($expected_rdf, $type = NULL) {
// Test the link formatter: trim at 80, no other settings.
$formatter = array(
$formatter = [
'type' => 'link',
'settings' => array(
'settings' => [
'trim_length' => 80,
'url_only' => FALSE,
'url_plain' => FALSE,
'rel' => '',
'target' => '',
),
);
],
];
$this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
// Test the link formatter: trim at 40, nofollow, new window.
$formatter = array(
$formatter = [
'type' => 'link',
'settings' => array(
'settings' => [
'trim_length' => 40,
'url_only' => FALSE,
'url_plain' => FALSE,
'rel' => 'nofollow',
'target' => '_blank',
),
);
],
];
$this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
// Test the link formatter: trim at 40, URL only (not plaintext) nofollow,
// new window.
$formatter = array(
$formatter = [
'type' => 'link',
'settings' => array(
'settings' => [
'trim_length' => 40,
'url_only' => TRUE,
'url_plain' => FALSE,
'rel' => 'nofollow',
'target' => '_blank',
),
);
],
];
$this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
// Test the link_separate formatter: trim at 40, nofollow, new window.
$formatter = array(
$formatter = [
'type' => 'link_separate',
'settings' => array(
'settings' => [
'trim_length' => 40,
'rel' => 'nofollow',
'target' => '_blank',
),
);
],
];
$this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
// Change the expected value here to literal. When formatted as plaintext
// then the RDF is expecting a 'literal' not a 'uri'.
$expected_rdf = array(
$expected_rdf = [
'value' => $this->testValue,
'type' => 'literal',
);
];
// Test the link formatter: trim at 20, url only (as plaintext.)
$formatter = array(
$formatter = [
'type' => 'link',
'settings' => array(
'settings' => [
'trim_length' => 20,
'url_only' => TRUE,
'url_plain' => TRUE,
'rel' => '0',
'target' => '0',
),
);
],
];
$this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
// Test the link formatter: do not trim, url only (as plaintext.)
$formatter = array(
$formatter = [
'type' => 'link',
'settings' => array(
'settings' => [
'trim_length' => 0,
'url_only' => TRUE,
'url_plain' => TRUE,
'rel' => '0',
'target' => '0',
),
);
],
];
$this->assertFormatterRdfa($formatter, 'http://schema.org/link', $expected_rdf);
}

View file

@ -19,7 +19,7 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
$testValue = 3;
$this->createTestField();
$this->createTestEntity($testValue);
$this->assertFormatterRdfa(array('type' => 'number_integer'), 'http://schema.org/baseSalary', array('value' => $testValue));
$this->assertFormatterRdfa(['type' => 'number_integer'], 'http://schema.org/baseSalary', ['value' => $testValue]);
// Test that the content attribute is not created.
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__items") and @content]');
@ -31,26 +31,26 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
*/
public function testIntegerFormatterWithSettings() {
\Drupal::service('theme_handler')->install(['classy']);
\Drupal::service('theme_handler')->setDefault('classy');
$this->config('system.theme')->set('default', 'classy')->save();
$this->fieldType = 'integer';
$formatter = array(
$formatter = [
'type' => 'number_integer',
'settings' => array(
'settings' => [
'thousand_separator' => '.',
'prefix_suffix' => TRUE,
),
);
],
];
$testValue = 3333333.33;
$field_settings = array(
$field_settings = [
'prefix' => '#',
'suffix' => ' llamas.',
);
];
$this->createTestField($field_settings);
$this->createTestEntity($testValue);
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array('value' => $testValue));
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', ['value' => $testValue]);
// Test that the content attribute is created.
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', array(':testValue' => $testValue));
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', [':testValue' => $testValue]);
$this->assertTrue($result);
}
@ -62,7 +62,7 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
$testValue = 3.33;
$this->createTestField();
$this->createTestEntity($testValue);
$this->assertFormatterRdfa(array('type' => 'number_unformatted'), 'http://schema.org/baseSalary', array('value' => $testValue));
$this->assertFormatterRdfa(['type' => 'number_unformatted'], 'http://schema.org/baseSalary', ['value' => $testValue]);
// Test that the content attribute is not created.
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__items") and @content]');
@ -74,27 +74,27 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
*/
public function testFloatFormatterWithSettings() {
\Drupal::service('theme_handler')->install(['classy']);
\Drupal::service('theme_handler')->setDefault('classy');
$this->config('system.theme')->set('default', 'classy')->save();
$this->fieldType = 'float';
$formatter = array(
$formatter = [
'type' => 'number_decimal',
'settings' => array(
'settings' => [
'thousand_separator' => '.',
'decimal_separator' => ',',
'prefix_suffix' => TRUE,
),
);
],
];
$testValue = 3333333.33;
$field_settings = array(
$field_settings = [
'prefix' => '$',
'suffix' => ' more.',
);
];
$this->createTestField($field_settings);
$this->createTestEntity($testValue);
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array('value' => $testValue));
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', ['value' => $testValue]);
// Test that the content attribute is created.
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', array(':testValue' => $testValue));
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', [':testValue' => $testValue]);
$this->assertTrue($result);
}
@ -103,16 +103,16 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
*/
public function testFloatFormatterWithScale() {
$this->fieldType = 'float';
$formatter = array(
$formatter = [
'type' => 'number_decimal',
'settings' => array(
'settings' => [
'scale' => 5,
),
);
],
];
$testValue = 3.33;
$this->createTestField();
$this->createTestEntity($testValue);
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array('value' => $testValue));
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', ['value' => $testValue]);
// Test that the content attribute is not created.
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__items") and @content]');
@ -124,21 +124,21 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
*/
public function testFloatFormatterWithScaleExercised() {
\Drupal::service('theme_handler')->install(['classy']);
\Drupal::service('theme_handler')->setDefault('classy');
$this->config('system.theme')->set('default', 'classy')->save();
$this->fieldType = 'float';
$formatter = array(
$formatter = [
'type' => 'number_decimal',
'settings' => array(
'settings' => [
'scale' => 5,
),
);
],
];
$testValue = 3.1234567;
$this->createTestField();
$this->createTestEntity($testValue);
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array('value' => $testValue));
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', ['value' => $testValue]);
// Test that the content attribute is created.
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', array(':testValue' => $testValue));
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', [':testValue' => $testValue]);
$this->assertTrue($result);
}
@ -150,7 +150,7 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
$testValue = 3.33;
$this->createTestField();
$this->createTestEntity($testValue);
$this->assertFormatterRdfa(array('type' => 'number_decimal'), 'http://schema.org/baseSalary', array('value' => $testValue));
$this->assertFormatterRdfa(['type' => 'number_decimal'], 'http://schema.org/baseSalary', ['value' => $testValue]);
// Test that the content attribute is not created.
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__items") and @content]');
@ -162,27 +162,27 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
*/
public function testDecimalFormatterWithSettings() {
\Drupal::service('theme_handler')->install(['classy']);
\Drupal::service('theme_handler')->setDefault('classy');
$this->config('system.theme')->set('default', 'classy')->save();
$this->fieldType = 'decimal';
$formatter = array(
$formatter = [
'type' => 'number_decimal',
'settings' => array(
'settings' => [
'thousand_separator' => 't',
'decimal_separator' => '#',
'prefix_suffix' => TRUE,
),
);
],
];
$testValue = 3333333.33;
$field_settings = array(
$field_settings = [
'prefix' => '$',
'suffix' => ' more.',
);
];
$this->createTestField($field_settings);
$this->createTestEntity($testValue);
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array('value' => $testValue));
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', ['value' => $testValue]);
// Test that the content attribute is created.
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', array(':testValue' => $testValue));
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', [':testValue' => $testValue]);
$this->assertTrue($result);
}
@ -192,12 +192,12 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
protected function createTestEntity($testValue) {
// Add the mapping.
$mapping = rdf_get_mapping('entity_test', 'entity_test');
$mapping->setFieldMapping($this->fieldName, array(
'properties' => array('schema:baseSalary'),
))->save();
$mapping->setFieldMapping($this->fieldName, [
'properties' => ['schema:baseSalary'],
])->save();
// Set up test entity.
$this->entity = EntityTest::create(array());
$this->entity = EntityTest::create([]);
$this->entity->{$this->fieldName}->value = $testValue;
}

View file

@ -37,9 +37,9 @@ class StringFieldRdfaTest extends FieldRdfaTestBase {
// Add the mapping.
$mapping = rdf_get_mapping('entity_test', 'entity_test');
$mapping->setFieldMapping($this->fieldName, array(
'properties' => array('schema:text'),
))->save();
$mapping->setFieldMapping($this->fieldName, [
'properties' => ['schema:text'],
])->save();
// Set up test entity.
$this->entity = EntityTest::create();
@ -52,7 +52,7 @@ class StringFieldRdfaTest extends FieldRdfaTestBase {
*/
public function testStringFormatters() {
// Tests the string formatter.
$this->assertFormatterRdfa(array('type' => 'string'), 'http://schema.org/text', array('value' => $this->testValue));
$this->assertFormatterRdfa(['type' => 'string'], 'http://schema.org/text', ['value' => $this->testValue]);
}
}

View file

@ -26,7 +26,7 @@ class TelephoneFieldRdfaTest extends FieldRdfaTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('telephone', 'text');
public static $modules = ['telephone', 'text'];
protected function setUp() {
parent::setUp();
@ -35,13 +35,13 @@ class TelephoneFieldRdfaTest extends FieldRdfaTestBase {
// Add the mapping.
$mapping = rdf_get_mapping('entity_test', 'entity_test');
$mapping->setFieldMapping($this->fieldName, array(
'properties' => array('schema:telephone'),
))->save();
$mapping->setFieldMapping($this->fieldName, [
'properties' => ['schema:telephone'],
])->save();
// Set up test values.
$this->testValue = '555-555-5555';
$this->entity = EntityTest::create(array());
$this->entity = EntityTest::create([]);
$this->entity->{$this->fieldName}->value = $this->testValue;
}
@ -50,18 +50,18 @@ class TelephoneFieldRdfaTest extends FieldRdfaTestBase {
*/
public function testAllFormatters() {
// Tests the plain formatter.
$this->assertFormatterRdfa(array('type' => 'string'), 'http://schema.org/telephone', array('value' => $this->testValue));
$this->assertFormatterRdfa(['type' => 'string'], 'http://schema.org/telephone', ['value' => $this->testValue]);
// Tests the telephone link formatter.
$this->assertFormatterRdfa(array('type' => 'telephone_link'), 'http://schema.org/telephone', array('value' => 'tel:' . $this->testValue, 'type' => 'uri'));
$this->assertFormatterRdfa(['type' => 'telephone_link'], 'http://schema.org/telephone', ['value' => 'tel:' . $this->testValue, 'type' => 'uri']);
$formatter = array(
$formatter = [
'type' => 'telephone_link',
'settings' => array('title' => 'Contact us'),
);
$expected_rdf_value = array(
'settings' => ['title' => 'Contact us'],
];
$expected_rdf_value = [
'value' => 'tel:' . $this->testValue,
'type' => 'uri',
);
];
// Tests the telephone link formatter with custom title.
$this->assertFormatterRdfa($formatter, 'http://schema.org/telephone', $expected_rdf_value);
}

View file

@ -33,20 +33,20 @@ class TextFieldRdfaTest extends FieldRdfaTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('text', 'filter');
public static $modules = ['text', 'filter'];
protected function setUp() {
parent::setUp();
$this->installConfig(array('filter'));
$this->installConfig(['filter']);
$this->createTestField();
// Add the mapping.
$mapping = rdf_get_mapping('entity_test', 'entity_test');
$mapping->setFieldMapping($this->fieldName, array(
'properties' => array('schema:text'),
))->save();
$mapping->setFieldMapping($this->fieldName, [
'properties' => ['schema:text'],
])->save();
// Set up test entity.
$this->entity = EntityTest::create();
@ -63,11 +63,11 @@ class TextFieldRdfaTest extends FieldRdfaTestBase {
$formatted_value = strip_tags($this->entity->{$this->fieldName}->processed);
// Tests the default formatter.
$this->assertFormatterRdfa(array('type' => 'text_default'), 'http://schema.org/text', array('value' => $formatted_value));
$this->assertFormatterRdfa(['type' => 'text_default'], 'http://schema.org/text', ['value' => $formatted_value]);
// Tests the summary formatter.
$this->assertFormatterRdfa(array('type' => 'text_summary_or_trimmed'), 'http://schema.org/text', array('value' => $formatted_value));
$this->assertFormatterRdfa(['type' => 'text_summary_or_trimmed'], 'http://schema.org/text', ['value' => $formatted_value]);
// Tests the trimmed formatter.
$this->assertFormatterRdfa(array('type' => 'text_trimmed'), 'http://schema.org/text', array('value' => $formatted_value));
$this->assertFormatterRdfa(['type' => 'text_trimmed'], 'http://schema.org/text', ['value' => $formatted_value]);
}
}

View file

@ -16,16 +16,16 @@ class RdfaAttributesTest extends KernelTestBase {
*
* @var array
*/
public static $modules = array('rdf');
public static $modules = ['rdf'];
/**
* Test attribute creation for mappings which use 'property'.
*/
function testProperty() {
$properties = array('dc:title');
public function testProperty() {
$properties = ['dc:title'];
$mapping = array('properties' => $properties);
$expected_attributes = array('property' => $properties);
$mapping = ['properties' => $properties];
$expected_attributes = ['property' => $properties];
$this->_testAttributes($expected_attributes, $mapping);
}
@ -33,18 +33,18 @@ class RdfaAttributesTest extends KernelTestBase {
/**
* Test attribute creation for mappings which use 'datatype'.
*/
function testDatatype() {
$properties = array('foo:bar1');
public function testDatatype() {
$properties = ['foo:bar1'];
$datatype = 'foo:bar1type';
$mapping = array(
$mapping = [
'datatype' => $datatype,
'properties' => $properties,
);
$expected_attributes = array(
];
$expected_attributes = [
'datatype' => $datatype,
'property' => $properties,
);
];
$this->_testAttributes($expected_attributes, $mapping);
}
@ -52,23 +52,23 @@ class RdfaAttributesTest extends KernelTestBase {
/**
* Test attribute creation for mappings which override human-readable content.
*/
function testDatatypeCallback() {
$properties = array('dc:created');
public function testDatatypeCallback() {
$properties = ['dc:created'];
$datatype = 'xsd:dateTime';
$date = 1252750327;
$iso_date = date('c', $date);
$mapping = array(
$mapping = [
'datatype' => $datatype,
'properties' => $properties,
'datatype_callback' => array('callable' => 'date_iso8601'),
);
$expected_attributes = array(
'datatype_callback' => ['callable' => 'date_iso8601'],
];
$expected_attributes = [
'datatype' => $datatype,
'property' => $properties,
'content' => $iso_date,
);
];
$this->_testAttributes($expected_attributes, $mapping, $date);
}
@ -77,23 +77,23 @@ class RdfaAttributesTest extends KernelTestBase {
/**
* Test attribute creation for mappings which use data converters.
*/
function testDatatypeCallbackWithConverter() {
$properties = array('schema:interactionCount');
public function testDatatypeCallbackWithConverter() {
$properties = ['schema:interactionCount'];
$data = "23";
$content = "UserComments:23";
$mapping = array(
$mapping = [
'properties' => $properties,
'datatype_callback' => array(
'datatype_callback' => [
'callable' => 'Drupal\rdf\SchemaOrgDataConverter::interactionCount',
'arguments' => array('interaction_type' => 'UserComments'),
),
);
$expected_attributes = array(
'arguments' => ['interaction_type' => 'UserComments'],
],
];
$expected_attributes = [
'property' => $properties,
'content' => $content,
);
];
$this->_testAttributes($expected_attributes, $mapping, $data);
}
@ -101,14 +101,14 @@ class RdfaAttributesTest extends KernelTestBase {
/**
* Test attribute creation for mappings which use 'rel'.
*/
function testRel() {
$properties = array('sioc:has_creator', 'dc:creator');
public function testRel() {
$properties = ['sioc:has_creator', 'dc:creator'];
$mapping = array(
$mapping = [
'properties' => $properties,
'mapping_type' => 'rel',
);
$expected_attributes = array('rel' => $properties);
];
$expected_attributes = ['rel' => $properties];
$this->_testAttributes($expected_attributes, $mapping);
}

View file

@ -72,7 +72,7 @@ class RdfMappingConfigEntityUnitTest extends UnitTestCase {
$target_entity_type->expects($this->any())
->method('getProvider')
->will($this->returnValue('test_module'));
$values = array('targetEntityType' => $target_entity_type_id);
$values = ['targetEntityType' => $target_entity_type_id];
$target_entity_type->expects($this->any())
->method('getBundleEntityType')
->will($this->returnValue(NULL));
@ -99,23 +99,23 @@ class RdfMappingConfigEntityUnitTest extends UnitTestCase {
$target_entity_type_id = $this->randomMachineName(16);
$target_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
$target_entity_type->expects($this->any())
->method('getProvider')
->will($this->returnValue('test_module'));
->method('getProvider')
->will($this->returnValue('test_module'));
$bundle_id = $this->randomMachineName(10);
$values = array('targetEntityType' => $target_entity_type_id , 'bundle' => $bundle_id);
$values = ['targetEntityType' => $target_entity_type_id , 'bundle' => $bundle_id];
$target_entity_type->expects($this->any())
->method('getBundleConfigDependency')
->will($this->returnValue(array('type' => 'config', 'name' => 'test_module.type.' . $bundle_id)));
->will($this->returnValue(['type' => 'config', 'name' => 'test_module.type.' . $bundle_id]));
$this->entityManager->expects($this->at(0))
->method('getDefinition')
->with($target_entity_type_id)
->will($this->returnValue($target_entity_type));
->method('getDefinition')
->with($target_entity_type_id)
->will($this->returnValue($target_entity_type));
$this->entityManager->expects($this->at(1))
->method('getDefinition')
->with($this->entityTypeId)
->will($this->returnValue($this->entityType));
->method('getDefinition')
->with($this->entityTypeId)
->will($this->returnValue($this->entityType));
$entity = new RdfMapping($values, $this->entityTypeId);
$dependencies = $entity->calculateDependencies()->getDependencies();