Commit 1850079c authored by hass's avatar hass
Browse files

Coder review

parent 78abe8f3
<?php
/**
* @file
* Administrative page callbacks for the realname module.
*/
/**
* Form constructor for the Real name settings form.
*
......
......@@ -2,10 +2,5 @@ name = Real name
description = Provides token-based name displays for users.
core = 7.x
dependencies[] = token
files[] = realname.module
files[] = realname.admin.inc
files[] = realname.pages.inc
files[] = realname.tokens.inc
files[] = realname.test
files[] = realname.install
configure = admin/config/people/realname
<?php
/**
* @file
* Installation file for Realname module.
*/
/**
* Implements hook_schema().
*/
......@@ -31,7 +36,7 @@ function realname_schema() {
),
'primary key' => array('uid'),
'indexes' => array(
'realname' => array('realname')
'realname' => array('realname'),
),
'foreign keys' => array(
'users' => array(
......
......@@ -68,7 +68,9 @@ function realname_menu() {
}
/**
* Implements hook_menu_alter() to replace user autocomplete with realname autocomplete.
* Implements hook_menu_alter().
*
* Replace user autocomplete with realname autocomplete.
*/
function realname_menu_alter(&$items) {
// Implement realname autocomplete.
......@@ -200,7 +202,7 @@ function realname_user_operations() {
* @param array $uids
* An array of user IDs.
*/
function realname_user_operations_realname_update($uids) {
function realname_user_operations_realname_update(array $uids) {
$accounts = user_load_multiple($uids);
foreach ($accounts as $account) {
realname_update($account);
......@@ -278,10 +280,11 @@ function realname_load($account) {
*
* @param array $accounts
* An array of user account objects keyed by user ID.
*
* @return array
* An array of real names keyed by user ID.
*/
function realname_load_multiple($accounts) {
function realname_load_multiple(array $accounts) {
$realnames = &drupal_static(__FUNCTION__, array());
if ($new_accounts = array_diff_key($accounts, $realnames)) {
......@@ -326,7 +329,8 @@ function realname_update($account) {
// Remove double spaces (if a token had no value).
$realname = preg_replace('/ {2,}/', ' ', $realname);
// The name must be trimmed to 255 characters before inserting into the database.
// The name must be trimmed to 255 characters before inserting into the
// database.
$realname = truncate_utf8(trim($realname), 255);
// Allow other modules to alter the generated realname.
......@@ -364,7 +368,7 @@ function realname_delete($uid) {
* @param array $uids
* An array of user IDs.
*/
function realname_delete_multiple($uids) {
function realname_delete_multiple(array $uids) {
db_delete('realname')->condition('uid', $uids, 'IN')->execute();
drupal_static_reset('realname_load_multiple');
entity_get_controller('user')->resetCache($uids);
......@@ -447,7 +451,7 @@ function realname_autocomplete($field_name, $entity_type, $bundle_name, $string
* @param string $bundle_name
* The bundle name.
*
* @return boolean
* @return bool
* True if user can access this menu item.
*/
function realname_autocomplete_access_callback($field_name, $entity_type, $bundle_name) {
......
......@@ -4,8 +4,12 @@
* @file
* Test file for Realname module.
*/
class RealnameBasicTest extends DrupalWebTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Realname basic tests',
......@@ -14,7 +18,10 @@ class RealnameBasicTest extends DrupalWebTestCase {
);
}
function setUp() {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp('realname');
$permissions = array(
......@@ -32,7 +39,10 @@ class RealnameBasicTest extends DrupalWebTestCase {
$this->verbose('<pre>' . print_r($this->drupalLogin($this->admin_user, TRUE)) . '</pre>');
}
function testRealnameConfiguration() {
/**
* Test realname configuration.
*/
public function testRealnameConfiguration() {
// Check if Configure link is available on 'Modules' page.
// Requires 'administer modules' permission.
$this->drupalGet('admin/modules');
......@@ -72,7 +82,10 @@ class RealnameBasicTest extends DrupalWebTestCase {
$this->assertRaw(t('The <em>[user:name]</em> token cannot be used as it will cause recursion.'), '[testRealnameConfiguration]: Invalid token found.');
}
function testRealnameUsernameAlter() {
/**
* Test realname alter functions.
*/
public function testRealnameUsernameAlter() {
// Add a test string and see if core username has been replaced by realname.
$edit['realname_pattern'] = '[user:name-raw] (UID: [user:uid])';
$this->drupalPost('admin/config/people/realname', $edit, t('Save configuration'));
......@@ -84,7 +97,10 @@ class RealnameBasicTest extends DrupalWebTestCase {
$this->assertRaw($this->admin_user->name . ' (UID: ' . $this->admin_user->uid . ')', '[testRealnameUsernameAlter]: Real name shown on user edit page.');
}
function testRealnameManageDisplay() {
/**
* Test realname display configuration.
*/
public function testRealnameManageDisplay() {
$edit['realname_pattern'] = '[user:name-raw]';
$this->drupalPost('admin/config/people/realname', $edit, t('Save configuration'));
......
......@@ -33,7 +33,7 @@ function realname_views_data() {
'filter' => array(
'handler' => 'views_handler_filter_string',
'title' => t('Name'),
'help' => t("The user's real name. This filter does not check if the user exists and allows partial matching. Does not utilize autocomplete.")
'help' => t("The user's real name. This filter does not check if the user exists and allows partial matching. Does not utilize autocomplete."),
),
);
......
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