Project

General

Profile

Paste
Download (2.25 KB) Statistics
| Branch: | Revision:

root / drupal7 / modules / user / tests / user_form_test.module @ b0dc3a2e

1
<?php
2

    
3
/**
4
 * @file
5
 * Dummy module implementing a form to test user password validation
6
 */
7

    
8
/**
9
 * Implements hook_menu().
10
 *
11
 * Sets up a form that allows a user to validate password.
12
 */
13
function user_form_test_menu() {
14
  $items = array();
15
  $items['user_form_test_current_password/%user'] = array(
16
    'title' => 'User form test for current password validation',
17
    'page callback' => 'drupal_get_form',
18
    'page arguments' => array('user_form_test_current_password',1),
19
    'access arguments' => array('administer users'),
20
    'type' => MENU_SUGGESTED_ITEM,
21
  );
22
  return $items;
23
}
24

    
25
/**
26
 * A test form for user_validate_current_pass().
27
 */
28
function user_form_test_current_password($form, &$form_state, $account) {
29
  $account->user_form_test_field = '';
30
  $form['#user'] = $account;
31

    
32
  $form['user_form_test_field'] = array(
33
    '#type' => 'textfield',
34
    '#title' => t('Test field'),
35
    '#description' => t('A field that would require a correct password to change.'),
36
    '#required' => TRUE,
37
  );
38
  
39
  $form['current_pass'] = array(
40
    '#type' => 'password',
41
    '#title' => t('Current password'),
42
    '#size' => 25,
43
    '#description' => t('Enter your current password'),
44
  );
45

    
46
  $form['current_pass_required_values'] = array(
47
    '#type' => 'value',
48
    '#value' => array('user_form_test_field' => t('Test field')),
49
  );
50

    
51
  $form['#validate'][] = 'user_validate_current_pass';
52
  $form['submit'] = array(
53
    '#type' => 'submit',
54
    '#value' => t('Test'),
55
  );
56
  return $form;
57
}
58

    
59
/**
60
 * Submit function for the test form for user_validate_current_pass().
61
 */
62
function user_form_test_current_password_submit($form, &$form_state) {
63
  drupal_set_message(t('The password has been validated and the form submitted successfully.'));
64
}
65

    
66
/**
67
 * Implements hook_form_FORM_ID_alter().
68
 */
69
function user_form_test_form_user_profile_form_alter(&$form, &$form_state) {
70
  if (variable_get('user_form_test_user_profile_form_rebuild', FALSE)) {
71
    $form['#submit'][] = 'user_form_test_user_account_submit';
72
  }
73
}
74

    
75
/**
76
 * Submit function for user_profile_form().
77
 */
78
function user_form_test_user_account_submit($form, &$form_state) {
79
  // Rebuild the form instead of letting the process end. This allows us to
80
  // test for bugs that can be triggered in contributed modules.
81
  $form_state['rebuild'] = TRUE;
82
}