Commit add48605 authored by edwardahan's avatar edwardahan Committed by hass
Browse files

Issue #2620882 by edwardaa, hass: Reset realname cache for the updated

user
parent daab11a7
name = Real name
description = Provides token-based name displays for users.
core = 7.x
configure = admin/config/people/realname
dependencies[] = token
; Tests
test_dependencies[] = entity
files[] = tests/realname.test
configure = admin/config/people/realname
files[] = tests/realname_entity.test
......@@ -140,8 +140,9 @@ function realname_user_load($accounts) {
* Implements hook_user_update().
*/
function realname_user_update(&$edit, $account, $category) {
// Since user data may have changed, update the realname.
realname_update($account);
// Since user data may have changed, update the realname and its cache.
$realnames = &drupal_static('realname_load_multiple', array());
$realnames[$account->uid] = realname_update($account);
}
/**
......
......@@ -117,4 +117,28 @@ class RealnameBasicTest extends DrupalWebTestCase {
$this->assertText('Real name', '[testRealnameManageDisplay]: Real name field visible on user page.');
}
/**
* Test realname user update.
*/
public function testRealnameUserUpdate() {
$edit['realname_pattern'] = '[user:name-raw]';
$this->drupalPost('admin/config/people/realname', $edit, t('Save configuration'));
$user1 = user_load($this->admin_user->uid);
$realname1 = $user1->realname;
// Update user name.
$user1->name = $this->randomName();
user_save($user1);
// Reload the user.
$user2 = user_load($this->admin_user->uid);
$realname2 = $user2->realname;
// Check if realname changed.
$this->assertTrue($realname1);
$this->assertTrue($realname2);
$this->assertNotEqual($realname1, $realname2, '[testRealnameUserUpdate]: Real name changed.');
}
}
<?php
/**
* @file
* Test file for Realname module.
*/
/**
* Test entity related functionality.
*/
class RealnameEntityTest extends DrupalWebTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Realname entity tests',
'description' => 'Test entity related functionality.',
'group' => 'Realname',
'dependencies' => array('entity'),
);
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp('entity', 'realname');
$permissions = array(
'change own username',
);
$this->user = $this->drupalCreateUser($permissions);
}
/**
* Test realname user update hook.
*/
public function testRealnameUserUpdate() {
variable_set('realname_pattern', '[user:name-raw]');
$uid = $this->user->uid;
$wrapper1 = entity_metadata_wrapper('user', $uid);
$realname1 = $wrapper1->label();
// Update user name via entity_metadata_wrapper.
$wrapper1->name = $this->randomName();
$wrapper1->save();
// Reload the user via entity_metadata_wrapper.
$wrapper2 = entity_metadata_wrapper('user', $uid);
$realname2 = $wrapper2->label();
// Check if realname changed via entity_metadata_wrapper.
$this->assertTrue($realname1);
$this->assertTrue($realname2);
$this->assertNotEqual($realname1, $realname2, '[testRealnameUserUpdate]: Real name changed via entity_metadata_wrapper.');
}
}
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