Révision 6ff32cea
Ajouté par Florent Torregrosa il y a environ 9 ans
drupal7/modules/simpletest/tests/form.test | ||
---|---|---|
470 | 470 |
$this->drupalPost(NULL, array('checkboxes[one]' => TRUE, 'checkboxes[two]' => TRUE), t('Submit')); |
471 | 471 |
$this->assertText('An illegal choice has been detected.', 'Input forgery was detected.'); |
472 | 472 |
} |
473 |
|
|
474 |
/** |
|
475 |
* Tests that submitted values are converted to scalar strings for textfields. |
|
476 |
*/ |
|
477 |
public function testTextfieldStringValue() { |
|
478 |
// Check multivalued submissions. |
|
479 |
$multivalue = array('evil' => 'multivalue', 'not so' => 'good'); |
|
480 |
$this->checkFormValue('textfield', $multivalue, ''); |
|
481 |
$this->checkFormValue('password', $multivalue, ''); |
|
482 |
$this->checkFormValue('textarea', $multivalue, ''); |
|
483 |
$this->checkFormValue('machine_name', $multivalue, ''); |
|
484 |
$this->checkFormValue('password_confirm', $multivalue, array('pass1' => '', 'pass2' => '')); |
|
485 |
// Check integer submissions. |
|
486 |
$integer = 5; |
|
487 |
$string = '5'; |
|
488 |
$this->checkFormValue('textfield', $integer, $string); |
|
489 |
$this->checkFormValue('password', $integer, $string); |
|
490 |
$this->checkFormValue('textarea', $integer, $string); |
|
491 |
$this->checkFormValue('machine_name', $integer, $string); |
|
492 |
$this->checkFormValue('password_confirm', array('pass1' => $integer, 'pass2' => $integer), array('pass1' => $string, 'pass2' => $string)); |
|
493 |
// Check that invalid array keys are ignored for password confirm elements. |
|
494 |
$this->checkFormValue('password_confirm', array('pass1' => 'test', 'pass2' => 'test', 'extra' => 'invalid'), array('pass1' => 'test', 'pass2' => 'test')); |
|
495 |
} |
|
496 |
|
|
497 |
/** |
|
498 |
* Checks that a given form input value is sanitized to the expected result. |
|
499 |
* |
|
500 |
* @param string $element_type |
|
501 |
* The form element type. Example: textfield. |
|
502 |
* @param mixed $input_value |
|
503 |
* The submitted user input value for the form element. |
|
504 |
* @param mixed $expected_value |
|
505 |
* The sanitized result value in the form state after calling |
|
506 |
* form_builder(). |
|
507 |
*/ |
|
508 |
protected function checkFormValue($element_type, $input_value, $expected_value) { |
|
509 |
$form_id = $this->randomName(); |
|
510 |
$form = array(); |
|
511 |
$form_state = form_state_defaults(); |
|
512 |
$form['op'] = array('#type' => 'submit', '#value' => t('Submit')); |
|
513 |
$form[$element_type] = array( |
|
514 |
'#type' => $element_type, |
|
515 |
'#title' => 'test', |
|
516 |
); |
|
517 |
|
|
518 |
$form_state['input'][$element_type] = $input_value; |
|
519 |
$form_state['input']['form_id'] = $form_id; |
|
520 |
$form_state['method'] = 'post'; |
|
521 |
$form_state['values'] = array(); |
|
522 |
drupal_prepare_form($form_id, $form, $form_state); |
|
523 |
|
|
524 |
// This is the main function we want to test: it is responsible for |
|
525 |
// populating user supplied $form_state['input'] to sanitized |
|
526 |
// $form_state['values']. |
|
527 |
form_builder($form_id, $form, $form_state); |
|
528 |
|
|
529 |
$this->assertIdentical($form_state['values'][$element_type], $expected_value, format_string('Form submission for the "@element_type" element type has been correctly sanitized.', array('@element_type' => $element_type))); |
|
530 |
} |
|
473 | 531 |
} |
474 | 532 |
|
475 | 533 |
/** |
Formats disponibles : Unified diff
Update core to 7.36