Révision 01a79e9a
Ajouté par Assos Assos il y a plus de 10 ans
htmltest/modules/simpletest/tests/form.test | ||
---|---|---|
1486 | 1486 |
$this->submitForm(array('textfield' => 'dummy value', 'checkboxes' => array(1 => NULL, 2 => 2)), TRUE); |
1487 | 1487 |
$this->submitForm(array('textfield' => 'dummy value', 'checkboxes' => array(1 => NULL, 2 => NULL)), TRUE); |
1488 | 1488 |
|
1489 |
// Test that a programmatic form submission can successfully submit values |
|
1490 |
// even for fields where the #access property is FALSE. |
|
1491 |
$this->submitForm(array('textfield' => 'dummy value', 'textfield_no_access' => 'test value'), TRUE); |
|
1492 |
// Test that #access is respected for programmatic form submissions when |
|
1493 |
// requested to do so. |
|
1494 |
$submitted_values = array('textfield' => 'dummy value', 'textfield_no_access' => 'test value'); |
|
1495 |
$expected_values = array('textfield' => 'dummy value', 'textfield_no_access' => 'default value'); |
|
1496 |
$form_state = array('programmed_bypass_access_check' => FALSE); |
|
1497 |
$this->submitForm($submitted_values, TRUE, $expected_values, $form_state); |
|
1498 |
|
|
1489 | 1499 |
// Test that a programmatic form submission can correctly click a button |
1490 | 1500 |
// that limits validation errors based on user input. Since we do not |
1491 | 1501 |
// submit any values for "textfield" here and the textfield is required, we |
... | ... | |
1508 | 1518 |
* @param $valid_input |
1509 | 1519 |
* A boolean indicating whether or not the form submission is expected to |
1510 | 1520 |
* be valid. |
1521 |
* @param $expected_values |
|
1522 |
* (Optional) An array of field values that are expected to be stored by |
|
1523 |
* the form submit handler. If not set, the submitted $values are assumed |
|
1524 |
* to also be the expected stored values. |
|
1525 |
* @param $form_state |
|
1526 |
* (Optional) A keyed array containing the state of the form, to be sent in |
|
1527 |
* the call to drupal_form_submit(). The $values parameter is added to |
|
1528 |
* $form_state['values'] by default, if it is not already set. |
|
1511 | 1529 |
*/ |
1512 |
private function submitForm($values, $valid_input) { |
|
1530 |
private function submitForm($values, $valid_input, $expected_values = NULL, $form_state = array()) {
|
|
1513 | 1531 |
// Programmatically submit the given values. |
1514 |
$form_state = array('values' => $values); |
|
1532 |
$form_state += array('values' => $values);
|
|
1515 | 1533 |
drupal_form_submit('form_test_programmatic_form', $form_state); |
1516 | 1534 |
|
1517 | 1535 |
// Check that the form returns an error when expected, and vice versa. |
... | ... | |
1528 | 1546 |
// By fetching the values from $form_state['storage'] we ensure that the |
1529 | 1547 |
// submission handler was properly executed. |
1530 | 1548 |
$stored_values = $form_state['storage']['programmatic_form_submit']; |
1531 |
foreach ($values as $key => $value) { |
|
1549 |
if (!isset($expected_values)) { |
|
1550 |
$expected_values = $values; |
|
1551 |
} |
|
1552 |
foreach ($expected_values as $key => $value) { |
|
1532 | 1553 |
$this->assertTrue(isset($stored_values[$key]) && $stored_values[$key] == $value, format_string('Submission handler correctly executed: %stored_key is %stored_value', array('%stored_key' => $key, '%stored_value' => print_r($value, TRUE)))); |
1533 | 1554 |
} |
1534 | 1555 |
} |
Formats disponibles : Unified diff
Update to drupal 7.26