- Patch #701672 by linclark: associate a standardized foaf:Person URI to each user profile.

merge-requests/26/head
Dries Buytaert 2010-03-03 17:06:42 +00:00
parent 02d6b122b5
commit e824801b2b
2 changed files with 31 additions and 4 deletions

View File

@ -495,12 +495,33 @@ function rdf_preprocess_field(&$variables) {
function rdf_preprocess_user_profile(&$variables) {
// Adds RDFa markup to the user profile page. Fields displayed in this page
// will automatically describe the user.
// @todo move to user.module
$account = $variables['elements']['#account'];
if (!empty($account->rdf_mapping['rdftype'])) {
$variables['attributes_array']['typeof'] = $account->rdf_mapping['rdftype'];
$variables['attributes_array']['about'] = url('user/' . $account->uid);
}
// Adds the relationship between the sioc:User and the foaf:Person who holds
// the account.
$account_holder_meta = array(
'#tag' => 'meta',
'#attributes' => array(
'about' => url('user/' . $account->uid, array('fragment' => 'me')),
'typeof' => array('foaf:Person'),
'rel' => array('foaf:account'),
'resource' => url('user/' . $account->uid),
),
);
// Adds the markup for username.
$username_meta = array(
'#tag' => 'meta',
'#attributes' => array(
'about' => url('user/' . $account->uid),
'property' => $account->rdf_mapping['name']['predicates'],
'content' => $account->name,
)
);
drupal_add_html_head($account_holder_meta, 'rdf_user_account_holder');
drupal_add_html_head($username_meta, 'rdf_user_username');
}
/**

View File

@ -307,14 +307,20 @@ class RdfMappingDefinitionTestCase extends DrupalWebTestCase {
// Create two users, one with access to user profiles.
$user1 = $this->drupalCreateUser(array('access user profiles'));
$user2 = $this->drupalCreateUser();
$username = $user2->name;
$this->drupalLogin($user1);
// Browse to the user profile page.
$this->drupalGet('user/' . $user2->uid);
// Ensure the default bundle mapping for user is used on the user profile
// page. These attributes come from the user default bundle definition.
$profile_url = url('user/' . $user2->uid);
$user2_profile_about = $this->xpath("//div[@class='profile' and @typeof='sioc:User' and @about='$profile_url']");
$account_uri = url('user/' . $user2->uid);
$person_uri = url('user/' . $user2->uid, array('fragment' => 'me'));
$user2_profile_about = $this->xpath("//div[@class='profile' and @typeof='sioc:User' and @about='$account_uri']");
$this->assertTrue(!empty($user2_profile_about), t('RDFa markup found on user profile page'));
$user_account_holder = $this->xpath("//meta[contains(@typeof, 'foaf:Person') and @about='$person_uri' and @resource='$account_uri' and contains(@rel, 'foaf:account')]");
$this->assertTrue(!empty($user_account_holder), t('URI created for account holder and username set on sioc:User.'));
$user_username = $this->xpath("//meta[@about='$account_uri' and contains(@property, 'foaf:name') and @content='$username']");
$this->assertTrue(!empty($user_username), t('foaf:name set on username.'));
// User 2 creates node.
$this->drupalLogin($user2);
@ -323,7 +329,7 @@ class RdfMappingDefinitionTestCase extends DrupalWebTestCase {
$this->drupalGet('node/' . $node->nid);
// Ensures the default bundle mapping for user is used on the Authored By
// information on the node.
$author_about = $this->xpath("//a[@typeof='sioc:User' and @about='$profile_url' and @property='foaf:name' and contains(@xml:lang, '')]");
$author_about = $this->xpath("//a[@typeof='sioc:User' and @about='$account_uri' and @property='foaf:name' and contains(@xml:lang, '')]");
$this->assertTrue(!empty($author_about), t('RDFa markup found on author information on post. xml:lang on username is set to empty string.'));
}
}