Skip to content
Snippets Groups Projects
Commit 9e8c184e authored by Dries Buytaert's avatar Dries Buytaert
Browse files

Issue #1895064 by scor: Fixed Ensure user name is language neutral in RDFa and...

Issue #1895064 by scor: Fixed Ensure user name is language neutral in RDFa and update tests to parse RDFa.
parent 1af32393
No related branches found
No related tags found
No related merge requests found
<?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).');
}
}
......@@ -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');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment