Commit feb983dd authored by catch's avatar catch

Issue #1261918 by dereine, tstoeckler, Damien Tournoud, Bojhan: Fixed Labels...

Issue #1261918 by dereine, tstoeckler, Damien Tournoud, Bojhan: Fixed Labels of the user entities are just not working.
parent 879b5357
......@@ -157,7 +157,7 @@ function user_entity_info() {
'controller class' => 'UserController',
'base table' => 'users',
'uri callback' => 'user_uri',
'label callback' => 'format_username',
'label callback' => 'user_label',
'fieldable' => TRUE,
'entity keys' => array(
'id' => 'uid',
......@@ -191,6 +191,23 @@ function user_uri($user) {
);
}
/**
* Entity label callback.
*
* @param $entity_type
* The entity type.
* @param $entity
* The entity object.
*
* @return
* The name of the user.
*
* @see format_username
*/
function user_label($entity_type, $entity) {
return format_username($entity);
}
/**
* Implements hook_field_info_alter().
*/
......
......@@ -2169,3 +2169,43 @@ class UserValidateCurrentPassCustomForm extends DrupalWebTestCase {
$this->assertText(t('The password has been validated and the form submitted successfully.'));
}
}
/**
* Test user entity callbacks.
*/
class UserEntityCallbacksTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'User entity callback tests',
'description' => 'Tests specific parts of the user entity like the URI callback and the label callback.',
'group' => 'User'
);
}
function setUp() {
parent::setUp('user');
$this->account = $this->drupalCreateUser();
$this->anonymous = drupal_anonymous_user();
}
/**
* Test label callback.
*/
function testLabelCallback() {
$this->assertEqual(entity_label('user', $this->account), $this->account->name, t('The username should be used as label'));
// Setup a random anonymous name to be sure the name is used.
$name = $this->randomName();
variable_set('anonymous', $name);
$this->assertEqual(entity_label('user', $this->anonymous), $name, t('The variable anonymous should be used for name of uid 0'));
}
/**
* Test URI callback.
*/
function testUriCallback() {
$uri = entity_uri('user', $this->account);
$this->assertEqual('user/' . $this->account->uid, $uri['path'], t('Correct user URI.'));
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment