summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.26/modules/user/tests/user_form_test.module
blob: 4e907f361b3ceb9028ff625edbe8c1b2469ce99b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php

/**
 * @file
 * Dummy module implementing a form to test user password validation
 */

/**
 * Implements hook_menu().
 *
 * Sets up a form that allows a user to validate password.
 */
function user_form_test_menu() {
  $items = array();
  $items['user_form_test_current_password/%user'] = array(
    'title' => 'User form test for current password validation',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('user_form_test_current_password',1),
    'access arguments' => array('administer users'),
    'type' => MENU_SUGGESTED_ITEM,
  );
  return $items;
}

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

  $form['user_form_test_field'] = array(
    '#type' => 'textfield',
    '#title' => t('Test field'),
    '#description' => t('A field that would require a correct password to change.'),
    '#required' => TRUE,
  );
  
  $form['current_pass'] = array(
    '#type' => 'password',
    '#title' => t('Current password'),
    '#size' => 25,
    '#description' => t('Enter your current password'),
  );

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

  $form['#validate'][] = 'user_validate_current_pass';
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Test'),
  );
  return $form;
}

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