From 9e8c184eacf7f7c2195b042aae139abf78ce6c01 Mon Sep 17 00:00:00 2001 From: Dries <dries@buytaert.net> Date: Tue, 12 Feb 2013 16:40:21 -0500 Subject: [PATCH] Issue #1895064 by scor: Fixed Ensure user name is language neutral in RDFa and update tests to parse RDFa. --- .../Drupal/rdf/Tests/UserAttributesTest.php | 109 ++++++++++++++++++ core/modules/rdf/rdf.module | 4 +- 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 core/modules/rdf/lib/Drupal/rdf/Tests/UserAttributesTest.php diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/UserAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/UserAttributesTest.php new file mode 100644 index 000000000000..29c69cb785cd --- /dev/null +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/UserAttributesTest.php @@ -0,0 +1,109 @@ +<?php + +/** + * @file + * Contains Drupal\rdf\Tests\UserAttributesTest. + */ + +namespace Drupal\rdf\Tests; + +use Drupal\simpletest\WebTestBase; + +/** + * Tests the RDFa markup of Users. + */ +class UserAttributesTest extends WebTestBase { + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('rdf', 'rdf_test'); + + public static function getInfo() { + return array( + 'name' => 'RDFa markup for users', + 'description' => 'Tests the RDFa markup of users.', + 'group' => 'RDF', + ); + } + + /** + * 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 two users, one with access to user profiles. + $user1 = $this->drupalCreateUser(array('access user profiles')); + $user2 = $this->drupalCreateUser(); + $username = $user2->name; + $this->drupalLogin($user1); + + $account_uri = url('user/' . $user2->uid, array('absolute' => TRUE)); + $person_uri = url('user/' . $user2->uid, array('fragment' => 'me', '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 = url('<front>', array('absolute' => TRUE)); + $parser->parse($graph, $this->drupalGet('user/' . $user2->uid), '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' => $user2->name, + ); + $this->assertTrue($graph->hasProperty($account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).'); + // Person type. + $expected_value = array( + 'type' => 'uri', + 'value' => 'http://xmlns.com/foaf/0.1/Person', + ); + $this->assertTrue($graph->hasProperty($person_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Person type found in RDF output (foaf:Person).'); + // Person relation to account. + $expected_value = array( + 'type' => 'uri', + 'value' => $account_uri, + ); + $this->assertTrue($graph->hasProperty($person_uri, 'http://xmlns.com/foaf/0.1/account', $expected_value), 'Person relation to account found in RDF output (foaf:account).'); + + + // User 2 creates a node. + $this->drupalLogin($user2); + $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1)); + $this->drupalLogin($user1); + + // 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 = url('<front>', array('absolute' => TRUE)); + $parser->parse($graph, $this->drupalGet('node/' . $node->nid), 'rdfa', $base_uri); + + // Ensures the default bundle mapping for user is used on the Authored By + // information on the node. + // 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' => $user2->name, + ); + $this->assertTrue($graph->hasProperty($account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).'); + } +} diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index 255fc9769b20..89494eb3d33d 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -627,13 +627,15 @@ function rdf_preprocess_user(&$variables) { 'resource' => url($uri['path'], $uri['options']), ), ); - // Adds the markup for username. + // Adds the markup for username as language neutral literal, see + // rdf_preprocess_username(). $username_meta = array( '#tag' => 'meta', '#attributes' => array( 'about' => url($uri['path'], $uri['options']), 'property' => $account->rdf_mapping['name']['predicates'], 'content' => $account->name, + 'lang' => '', ) ); drupal_add_html_head($account_holder_meta, 'rdf_user_account_holder'); -- GitLab