diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 92f6cf2..b04e0f1 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,6 @@ autoassignole x.x-x.x, xxxx-xx-xx --------------------------------------- +Issue #2045659 by claudiu.cristea: Featurify autoassignole 7.x-1.0-beta5, xxxx-xx-xx diff --git a/autoassignrole.admin.inc b/autoassignrole.admin.inc index dcd4f29..2efdfc8 100644 --- a/autoassignrole.admin.inc +++ b/autoassignrole.admin.inc @@ -88,6 +88,7 @@ function autoassignrole_user_settings() { // user by Drupal. $roles = user_roles(TRUE); unset($roles[DRUPAL_AUTHENTICATED_RID]); + $roles = drupal_map_assoc($roles); if ($roles) { $form['autoassignrole_user_roles'] = array( @@ -177,80 +178,65 @@ function autoassignrole_user_settings() { * * Form to edit or add role-specific pages. */ -function autoassignrole_page_form($form, &$form_state, $op = 'add', $id = 0) { +function autoassignrole_page_form($form, &$form_state, $op = 'add', $name = NULL) { $roles = user_roles(TRUE); unset($roles[DRUPAL_AUTHENTICATED_RID]); + $roles = drupal_map_assoc($roles); - $form = array(); - - switch ($op) { - case 'add': - $title = t('Add a new role page'); - $submit_value = t('Add'); - break; - - case 'edit': - $title = t('Edit role page'); - $submit_value = t('Save'); - break; + if ($op == 'add') { + $page = (object) array('name' => '', 'title' => '', 'path' => '', 'roles' => array(), 'menu' => '', 'display' => ''); } - - $form['rid_page'] = array( - '#type' => 'fieldset', - '#title' => $title, - ); - - $form['rid_page']['op_term'] = array( - '#type' => 'hidden', - '#value' => $op, - ); - - if ($op == 'edit') { - $form['rid_page']['id'] = array( - '#type' => 'hidden', - '#value' => $id, - ); - if ($id > 0) { - $page = autoassignrole_get_page($id); - } + else { + $page = autoassignrole_get_page($name); + $page->roles = drupal_map_assoc(unserialize($page->roles)); } - $form['rid_page']['roles'] = array( - '#type' => 'checkboxes', - '#title' => t('Role'), - '#description' => t('Select the roles this page will assign'), - '#options' => $roles, - '#required' => TRUE, - '#default_value' => isset($page->rids) ? unserialize($page->rids) : array(), + $form['operation'] = array( + '#type' => 'value', + '#value' => $op, ); - - $form['rid_page']['title'] = array( + $form['title'] = array( '#type' => 'textfield', '#title' => t('Page Title'), '#description' => t('Enter the title of the page'), '#size' => 60, '#required' => TRUE, - '#default_value' => isset($page->title) ? $page->title : "", + '#default_value' => $page->title, ); - - $form['rid_page']['path'] = array( + $form['name'] = array( + '#type' => 'machine_name', + '#default_value' => $page->name, + '#disabled' => $op == 'edit', + '#machine_name' => array( + 'exists' => 'autoassignrole_get_page', + 'source' => array('title'), + ), + '#required' => TRUE, + ); + $form['roles'] = array( + '#type' => 'checkboxes', + '#title' => t('Role'), + '#description' => t('Select the roles this page will assign'), + '#options' => $roles, + '#required' => TRUE, + '#default_value' => $page->roles, + ); + $form['path'] = array( '#type' => 'textfield', '#title' => t('Page Path'), '#description' => t('Enter the Drupal path for the registration page for this role. This is a relative path based on your Drupal installation.'), '#size' => 60, '#required' => TRUE, - '#default_value' => isset($page->path) ? $page->path : "", + '#default_value' => $page->path, ); - - $form['rid_page']['menu'] = array( + $form['menu'] = array( '#type' => 'select', '#title' => t('Menu'), '#description' => t('Which parent menu item should these pages appear under? This will only apply if you choose the "Standard" display option below.'), '#options' => menu_get_menus(), - '#default_value' => isset($page->menu) ? $page->menu : "", + '#default_value' => $page->menu, ); - - $form['rid_page']['display'] = array( + $form['display'] = array( '#type' => 'select', '#title' => t('Display type'), '#description' => t('Choose the way you would like these pages to be displayed.
Standard is equivalent to the core Drupal log in/ registration form, with tabs along the top.
Individual is a separate page without tabs.'), @@ -258,12 +244,12 @@ function autoassignrole_page_form($form, &$form_state, $op = 'add', $id = 0) { AUTOASSIGNROLE_PAGE_DISPLAY_STANDARD => t('Standard'), AUTOASSIGNROLE_PAGE_DISPLAY_INDIVIDUAL => t('Individual'), ), - '#default_value' => isset($page->display) ? $page->display : "", + '#default_value' => $page->display, ); $form['submit'] = array( '#type' => 'submit', - '#value' => $submit_value, + '#value' => $op == 'add' ? t('Add') : t('Save'), ); return $form; @@ -303,85 +289,33 @@ function autoassignrole_page_form_validate($form_id, &$form_state) { * Implements hook_form_submit(). */ function autoassignrole_page_form_submit($form_id, &$form_state) { - $page = array( - 'rids' => serialize($form_state['values']['roles']), - 'path' => $form_state['values']['path'], - 'menu' => $form_state['values']['menu'], - 'title' => $form_state['values']['title'], - 'display' => $form_state['values']['display'], + $values =& $form_state['values']; + $is_new = $values['operation'] == 'add'; + + $page = (object) array( + 'name' => $values['name'], + 'roles' => serialize(array_keys(array_filter($values['roles']))), + 'path' => $values['path'], + 'menu' => $values['menu'], + 'title' => $values['title'], + 'display' => $values['display'], ); - $return = FALSE; - $op = $form_state['values']['op_term']; - switch ($op) { - case 'add': - $return = autoassignrole_add_page($page); - $operation = 'Created'; - break; - - case 'edit': - $id = $form_state['values']['id']; - $return = autoassignrole_update_page($page, $id); - $operation = 'Updated'; - break; - } + $return = drupal_write_record('autoassignrole_page', $page, $is_new ? array() : 'name'); - if ($return) { + $ops = array(FALSE => t('updated'), TRUE => t('created')); + $op = $ops[$is_new]; + if ($return !== FALSE) { menu_rebuild(); - drupal_set_message(t('Successfully @operation Page @page', array('@operation' => $operation, '@page' => $page['title']))); + drupal_set_message(t('Successfully @operation Page @page', array('@operation' => $op, '@page' => $page->title))); drupal_goto('admin/config/people/autoassignrole/pages'); } else { - drupal_set_message(t('Unfortunately there has been an error and this page could not be %op', array('%op' => drupal_strtolower($operation))), 'error'); + drupal_set_message(t('Unfortunately there has been an error and this page could not be %op', array('%op' => $op)), 'error'); } } /** - * Function to add role-specific page. - * - * @param array $page - * The details of the page to be added. - * - * @return bool - * Return true if successful | false. - */ -function autoassignrole_add_page($page) { - $return_value = FALSE; - try { - $return_value = db_insert('autoassignrole_page')->fields($page)->execute(); - } - catch (Exception $e) { - drupal_set_message(t('db_insert failed. Message = %message, query = %query', array('%message' => $e->getMessage(), '%query' => $e->query_string)), 'error'); - } - return $return_value; -} - -/** - * Function to update existing role-specific page. - * - * @param array $page - * The details of the page to be added. - * @param int $id - * The id of the page to be updated. - * - * @return bool - * Return true if successful | false. - */ -function autoassignrole_update_page($page, $id) { - $return_value = FALSE; - try { - $return_value = db_update('autoassignrole_page') - ->fields($page) - ->condition('rid_page_id', $id) - ->execute(); - } - catch (Exception $e) { - drupal_set_message(t('db_update failed. Message = %message, query = %query', array('%message' => $e->getMessage(), '%query' => $e->query_string)), 'error'); - } - return $return_value; -} - -/** * Function to delete role-specific page. */ function autoassignrole_page_delete_confirm($form, &$form_state, $page_id) { @@ -399,7 +333,7 @@ function autoassignrole_page_delete_confirm($form, &$form_state, $page_id) { */ function autoassignrole_page_delete_confirm_submit($form, &$form_state) { db_delete('autoassignrole_page') - ->condition('rid_page_id', (int) $form_state['values']['page_id']) + ->condition('name', $form_state['values']['page_id']) ->execute(); menu_rebuild(); drupal_set_message(t('Successfully deleted page')); @@ -414,8 +348,9 @@ function autoassignrole_page_delete_confirm_submit($form, &$form_state) { */ function autoassignrole_list_pages() { $header = array( + array('data' => t('Name'), 'field' => 'name'), array('data' => 'Title', 'field' => 'title', 'sort' => 'asc'), - array('data' => 'Roles', 'field' => 'rids'), + array('data' => 'Roles', 'field' => 'roles'), array('data' => 'Path', 'field' => 'path'), array('data' => 'Operations'), ); @@ -426,8 +361,8 @@ function autoassignrole_list_pages() { ->extend('TableSort') ->orderByHeader($header) ->fields('p', array( - 'rid_page_id', - 'rids', + 'name', + 'roles', 'title', 'path', ) @@ -435,26 +370,15 @@ function autoassignrole_list_pages() { $results = $query->execute(); - $user_roles = user_roles(TRUE); $rows = array(); foreach ($results as $page) { - $rids = unserialize($page->rids); - $roles = ''; - $count = 0; - foreach ($rids as $rid) { - if (!empty($rid) && array_key_exists($rid, $user_roles)) { - if ($count != 0) { - $roles .= ', '; - } - $roles .= $user_roles[$rid]; - $count++; - } - } - $edit = l(t('Edit'), 'admin/config/people/autoassignrole/pages/edit/' . $page->rid_page_id); - $delete = l(t('Delete'), 'admin/config/people/autoassignrole/pages/delete/' . $page->rid_page_id); + $roles = implode(', ', unserialize($page->roles)); + $edit = l(t('Edit'), 'admin/config/people/autoassignrole/pages/edit/' . $page->name); + $delete = l(t('Delete'), 'admin/config/people/autoassignrole/pages/delete/' . $page->name); $links = $edit . ' | ' . $delete; $rows[] = array( 'data' => array( + $page->name, $page->title, $roles, $page->path, diff --git a/autoassignrole.info b/autoassignrole.info index 717d6c1..d13300c 100644 --- a/autoassignrole.info +++ b/autoassignrole.info @@ -3,6 +3,7 @@ description = Automatically assign a role to new users. core = 7.x configure=admin/config/people/autoassignrole version = VERSION +dependencies[] = ctools files[] = autoassignrole.module files[] = autoassignrole.admin.inc files[] = autoassignrole.test diff --git a/autoassignrole.install b/autoassignrole.install index e9d9447..4a58f2c 100644 --- a/autoassignrole.install +++ b/autoassignrole.install @@ -43,16 +43,16 @@ function autoassignrole_schema() { $schema['autoassignrole_page'] = array( 'description' => 'Stores autoassignrole page information', 'fields' => array( - 'rid_page_id' => array( - 'type' => 'serial', - 'not null' => TRUE, - 'description' => 'The unique identifier for this role page', - ), - 'rids' => array( + 'name' => array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, - 'description' => 'The role IDs for this page', + 'description' => 'The unique machine name of this page.' + ), + 'roles' => array( + 'type' => 'text', + 'not null' => FALSE, + 'description' => 'The roles for this page', ), 'path' => array( 'type' => 'text', @@ -76,7 +76,20 @@ function autoassignrole_schema() { 'description' => 'The display type for this page', ), ), - 'primary key' => array('rid_page_id'), + 'primary key' => array('name'), + 'export' => array( + 'key' => 'name', + 'key name' => 'Machine name', + 'primary key' => 'name', + 'identifier' => 'autoassignrole', + 'default hook' => 'autoassignrole_page_default', + 'api' => array( + 'owner' => 'autoassignrole', + 'api' => 'autoassignrole', + 'minimum_version' => 1, + 'current_version' => 1, + ), + ), ); return $schema; @@ -259,13 +272,62 @@ function autoassignrole_update_7104() { } /** - * Converts the role storage from role ID to role name to allow Features export. + * Features integration. */ function autoassignrole_update_7105() { $roles = user_roles(TRUE); - $auto_roles = array(); - foreach (variable_get('autoassignrole_auto_roles', array()) as $rid => $checked) { - $auto_roles[$roles[$rid]] = $checked ? $roles[$rid] : 0; + foreach (array('autoassignrole_auto_roles', 'autoassignrole_user_roles') as $variable) { + $stored_roles = array(); + foreach (variable_get($variable, array()) as $rid => $checked) { + $stored_roles[$roles[$rid]] = $checked ? $roles[$rid] : 0; + } + variable_set($variable, $stored_roles); } - variable_set('autoassignrole_auto_roles', $auto_roles); + + // Add a machine name to {autoassignrole_page} table, to make it exportable. + db_add_field('autoassignrole_page', 'name', array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => FALSE, + 'description' => 'The unique machine name of this page.' + )); + // Add a larger column 'roles' to replace 'rids'. + db_add_field('autoassignrole_page', 'roles', array( + 'type' => 'text', + 'not null' => FALSE, + 'description' => 'The roles for this page', + )); + + // Convert the {autoassignrole_page} table data. + foreach (db_query("SELECT * FROM {autoassignrole_page}")->fetchAll() as $row) { + $name = preg_replace('@[^a-z0-9]+@', '_', drupal_strtolower($row->title)); + $suffixed = $name; + $count = 0; + // Handle possible duplicates in 'title'. + while (db_query("SELECT 1 FROM {autoassignrole_page} WHERE name = :name AND rid_page_id <> :id", array(':name' => $suffixed, ':id' => $row->rid_page_id))->fetchField()) { + $suffixed = $name . '_' . $count; + $count++; + } + $rids = serialize(array_values(array_filter(array_map(function ($rid) use ($roles) { + return empty($roles[$rid]) ? FALSE : $roles[$rid]; + }, unserialize($row->rids))))); + db_update('autoassignrole_page') + ->fields(array('name' => $suffixed, 'roles' => $rids)) + ->condition('rid_page_id', $row->rid_page_id) + ->execute(); + } + + // Drop legacy fields and indexes. + db_drop_field('autoassignrole_page', 'rid_page_id'); + db_drop_field('autoassignrole_page', 'rids'); + // Make 'name' primary key. + db_add_primary_key('autoassignrole_page', array('name')); + + // Fix the 'not null' problem. + db_change_field('autoassignrole_page', 'name', 'name', array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'description' => 'The unique machine name of this page.' + )); } diff --git a/autoassignrole.module b/autoassignrole.module index c7f265d..1d4cd15 100644 --- a/autoassignrole.module +++ b/autoassignrole.module @@ -92,12 +92,12 @@ function autoassignrole_menu() { $pages = autoassignrole_get_pages(); foreach ($pages as $page) { - $rids = unserialize($page->rids); + $roles = drupal_map_assoc(unserialize($page->roles)); switch ($page->display) { case AUTOASSIGNROLE_PAGE_DISPLAY_STANDARD: $items[$page->path] = array( 'title' => check_plain($page->title), - 'page arguments' => array($rids), + 'page arguments' => array($roles), 'page callback' => 'autoassignrole_register', 'access callback' => 'user_register_access', 'file' => 'autoassignrole.paths.inc', @@ -106,7 +106,7 @@ function autoassignrole_menu() { ); $items[$page->path . '/register'] = array( 'title' => 'Register', - 'page arguments' => array($rids), + 'page arguments' => array($roles), 'page callback' => 'autoassignrole_register', 'access callback' => 'user_register_access', 'file' => 'autoassignrole.paths.inc', @@ -131,7 +131,7 @@ function autoassignrole_menu() { case AUTOASSIGNROLE_PAGE_DISPLAY_INDIVIDUAL: $items[$page->path] = array( 'title' => check_plain($page->title), - 'page arguments' => array($rids), + 'page arguments' => array($roles), 'page callback' => 'autoassignrole_register', 'access callback' => 'user_register_access', 'file' => 'autoassignrole.paths.inc', @@ -139,7 +139,7 @@ function autoassignrole_menu() { ); $items[$page->path . '/register'] = array( 'title' => 'Register', - 'page arguments' => array($rids), + 'page arguments' => array($roles), 'page callback' => 'autoassignrole_register', 'access callback' => 'user_register_access', 'file' => 'autoassignrole.paths.inc', @@ -169,7 +169,7 @@ function autoassignrole_menu() { /** * Finds any role ids attached to current page, if any. */ -function autoassignrole_get_active_path_rid() { +function autoassignrole_get_active_path_roles() { $item = menu_get_item(); if ($item['page_callback'] == 'autoassignrole_register') { return $item['page_arguments'][0]; @@ -185,7 +185,7 @@ function autoassignrole_user_presave(&$edit, $account, $category) { // Make sure we only assign roles automatically when enabled to do so. if (variable_get('autoassignrole_auto_active', 0) || variable_get("autoassignrole_user_active", 0) || (variable_get('autoassignrole_admin_active', 0) && user_access('administer users')) - || autoassignrole_get_active_path_rid()) { + || autoassignrole_get_active_path_roles()) { // Use case http://drupal.org/node/944864 // Only assign roles if this is a new account. if (isset($account->is_new) && !empty($account->is_new)) { @@ -196,7 +196,7 @@ function autoassignrole_user_presave(&$edit, $account, $category) { // Add in automatic roles. if ((variable_get('autoassignrole_auto_active', 0) && !user_access('administer users')) || (variable_get('autoassignrole_admin_active', 0) && user_access('administer users'))) { - $roles_to_add += array_intersect_key($user_roles, _autoassignrole_get_auto_roles()); + $roles_to_add += array_intersect_key($user_roles, _autoassignrole_convert_roles(variable_get('autoassignrole_auto_roles', array()))); } // Add in user selected roles if any. @@ -205,13 +205,13 @@ function autoassignrole_user_presave(&$edit, $account, $category) { if (!is_array($edit['user_roles'])) { $edit['user_roles'] = array($edit['user_roles'] => $edit['user_roles']); } - $roles_to_add += array_intersect_key($user_roles, array_filter($edit['user_roles'])); + $roles_to_add += array_intersect_key($user_roles, _autoassignrole_convert_roles($edit['user_roles'])); } // Add page-specific roles. - $page_rids = autoassignrole_get_active_path_rid(); - if ($page_rids) { - $roles_to_add = array_intersect_key($user_roles, array_filter($page_rids)); + $page_roles = autoassignrole_get_active_path_roles(); + if ($page_roles) { + $roles_to_add = array_intersect_key($user_roles, _autoassignrole_convert_roles($page_roles)); } // Make sure the roles key exists. @@ -230,10 +230,10 @@ function autoassignrole_user_presave(&$edit, $account, $category) { */ function autoassignrole_form_user_register_form_alter(&$form, &$form_state) { if (variable_get("autoassignrole_user_active", 0) && !user_access('administer users') - && !autoassignrole_get_active_path_rid()) { + && !autoassignrole_get_active_path_roles()) { // Get a list of valid roles that can be selected. - $roles = array_intersect_key(user_roles(TRUE), array_filter(variable_get('autoassignrole_user_roles', array()))); + $roles = array_intersect_key(user_roles(TRUE), _autoassignrole_convert_roles(variable_get('autoassignrole_user_roles', array()))); if ($roles) { $form['autoassignrole_user'] = array( @@ -253,6 +253,7 @@ function autoassignrole_form_user_register_form_alter(&$form, &$form_state) { else { drupal_sort_weight($roles, $roles); } + $roles = drupal_map_assoc($roles); $multiple = variable_get('autoassignrole_user_multiple', 0); $user_selection = variable_get('autoassignrole_user_selection', AUTOASSIGNROLE_ELEMENT_RADIO_CHECKBOX); @@ -305,7 +306,7 @@ function autoassignrole_get_pages() { */ function autoassignrole_get_page($id) { $query = _autoasignrole_get_page_query(); - $query->condition('rid_page_id', $id, '='); + $query->condition('name', $id, '='); return $query->execute()->fetchObject(); } @@ -318,7 +319,8 @@ function autoassignrole_get_page($id) { function _autoasignrole_get_page_query() { return db_select('autoassignrole_page', 'p') ->fields('p', array( - 'rids', + 'name', + 'roles', 'path', 'title', 'menu', @@ -342,22 +344,25 @@ function _autoassignrole_get_user_description() { } /** - * Converts the 'autoassignrole_auto_roles' variable in user_roles(), format, - * taking role IDs as keys. The unchecked roles of 'autoassignrole_auto_roles' - * variables are filtered out. + * Converts the a list of roles that have both keys and values as role name to + * user_roles() format, taking role IDs as keys. * + * @param array $roles + * Roles to be converted. * @return array * A list of role names keyed by role id. */ -function _autoassignrole_get_auto_roles() { - $auto_roles = variable_get('autoassignrole_auto_roles', array()); - return array_filter(user_roles(TRUE), function ($role) use ($auto_roles) { - return !empty($auto_roles[$role]); +function _autoassignrole_convert_roles(array $roles) { + return array_filter(user_roles(TRUE), function ($role) use ($roles) { + return !empty($roles[$role]); }); } /** * Implements hook_user_role_presave(). + * + * We guess that in an update process the role might been changed, so we store + * the existing name before the new one is saved to be compared later. */ function autoassignrole_user_role_presave($role) { if (!empty($role->rid)) { @@ -376,13 +381,29 @@ function autoassignrole_user_role_update($role) { return; } - $auto_role = array(); - foreach (variable_get('autoassignrole_auto_roles', array()) as $name => $checked) { - if ($name == $role->existing_name) { - $name = $role->name; - $checked = $checked ? $name : 0; + foreach (array('autoassignrole_auto_roles', 'autoassignrole_user_roles') as $variable) { + $stored_roles = array(); + foreach (variable_get($variable, array()) as $name => $checked) { + if ($name == $role->existing_name) { + $name = $role->name; + $checked = $checked ? $name : 0; + } + $stored_roles[$name] = $checked; } - $auto_role[$name] = $checked; + variable_set($variable, $stored_roles); + } +} + +/** + * Implements hook_features_pipe_COMPONENT_alter(). + */ +function autoassignrole_features_pipe_autoassignrole_page_alter(&$pipe, $data, $export) { + $variables = db_select('variable', 'v') + ->fields('v', array('name')) + ->condition('name', db_like('autoassignrole_') . '%', 'LIKE') + ->execute() + ->fetchCol(); + foreach ($variables as $variable) { + $pipe['variable'][] = $variable; } - variable_set('autoassignrole_auto_roles', $auto_role); } diff --git a/autoassignrole.paths.inc b/autoassignrole.paths.inc index f9a76ee..9cccc17 100644 --- a/autoassignrole.paths.inc +++ b/autoassignrole.paths.inc @@ -21,7 +21,7 @@ require_once drupal_get_path('module', 'user') . '/user.pages.inc'; * * $rid is not actually used in the function but by passing it we can find out * which roles are meant to be added to the new user by using - * autoassignrole_get_active_path_rid(); + * autoassignrole_get_active_path_roles(); * * @see autoassignrole.module * @@ -31,7 +31,7 @@ require_once drupal_get_path('module', 'user') . '/user.pages.inc'; * @return string * User registration form renderer. * - * @see autoassignrole_get_active_path_rid() + * @see autoassignrole_get_active_path_roles() */ function autoassignrole_register($rid) { $output = drupal_get_form('user_register_form'); diff --git a/autoassignrole.test b/autoassignrole.test index 0a98155..051ea13 100644 --- a/autoassignrole.test +++ b/autoassignrole.test @@ -299,13 +299,13 @@ class AutoassignroleAdminUserTestCase extends DrupalWebTestCase { // Verify that there are roles exposed. $this->assertField( - 'autoassignrole_user_roles[3]', + 'autoassignrole_user_roles[' . $this->roles[3] . ']', 'Looking for the autoassignrole_user_roles checkboxes.' ); // Verify that a checkbox for each of our valid roles shows on the page. foreach ($this->roles as $rid => $role) { - $edit["autoassignrole_user_roles[$rid]"] = $rid; + $edit["autoassignrole_user_roles[$role]"] = $role; } // Check each of our roles and submit the form. @@ -318,7 +318,7 @@ class AutoassignroleAdminUserTestCase extends DrupalWebTestCase { // Verify the checked value was saved for each of our roles. $roles = variable_get("autoassignrole_user_roles", array()); foreach ($this->roles as $rid => $role) { - $this->assertEqual(TRUE, array_key_exists($rid, $roles), 'Verifying that role (rid:' . $rid . ') was activated.'); + $this->assertEqual(TRUE, array_key_exists($role, $roles), 'Verifying that role "' . $role . '" was activated.'); } } @@ -618,7 +618,7 @@ class AuthassignroleRolePerPathTestCase extends DrupalWebTestCase { $this->drupalGet('admin/config/people/autoassignrole/pages/add'); // Verify that there are roles exposed. - $role_keys = array_keys($this->roles); + $role_keys = array_values($this->roles); $this->assertField( 'roles[' . $role_keys[0] . ']', 'Looking for the autoassignrole_auto_roles checkboxes.' @@ -632,12 +632,13 @@ class AuthassignroleRolePerPathTestCase extends DrupalWebTestCase { continue; } } - $edit["roles[$rid]"] = $rid; + $edit["roles[$role]"] = $role; } // Set the title. $this->page_title = $this->randomName(); $edit['title'] = $this->page_title; + $edit['name'] = drupal_strtolower($this->randomName()); // Set the path. $edit['path'] = $this->page_path = 'test/register/' . $this->page_title; @@ -649,7 +650,7 @@ class AuthassignroleRolePerPathTestCase extends DrupalWebTestCase { ); // Verify the path has been saved. - $this->assertText('Successfully Created Page ' . $this->page_title, 'Verified that path has been created.'); + $this->assertText('Successfully created Page ' . $this->page_title, 'Verified that path has been created.'); } }