class FormsTestCase in Drupal 7
@file Unit tests for the Drupal Form API.
Hierarchy
- class \DrupalTestCase
- class \DrupalWebTestCase
- class \FormsTestCase
- class \DrupalWebTestCase
Expanded class hierarchy of FormsTestCase
File
- modules/
simpletest/ tests/ form.test, line 8 - Unit tests for the Drupal Form API.
View source
class FormsTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Form element validation',
'description' => 'Tests various form element validation mechanisms.',
'group' => 'Form API',
);
}
function setUp() {
parent::setUp('form_test');
}
/**
* Check several empty values for required forms elements.
*
* Carriage returns, tabs, spaces, and unchecked checkbox elements are not
* valid content for a required field.
*
* If the form field is found in form_get_errors() then the test pass.
*/
function testRequiredFields() {
// Originates from http://drupal.org/node/117748
// Sets of empty strings and arrays.
$empty_strings = array(
'""' => "",
'"\\n"' => "\n",
'" "' => " ",
'"\\t"' => "\t",
'" \\n\\t "' => " \n\t ",
'"\\n\\n\\n\\n\\n"' => "\n\n\n\n\n",
);
$empty_arrays = array(
'array()' => array(),
);
$empty_checkbox = array(
NULL,
);
$elements['textfield']['element'] = array(
'#title' => $this
->randomName(),
'#type' => 'textfield',
);
$elements['textfield']['empty_values'] = $empty_strings;
$elements['password']['element'] = array(
'#title' => $this
->randomName(),
'#type' => 'password',
);
$elements['password']['empty_values'] = $empty_strings;
$elements['password_confirm']['element'] = array(
'#title' => $this
->randomName(),
'#type' => 'password_confirm',
);
// Provide empty values for both password fields.
foreach ($empty_strings as $key => $value) {
$elements['password_confirm']['empty_values'][$key] = array(
'pass1' => $value,
'pass2' => $value,
);
}
$elements['textarea']['element'] = array(
'#title' => $this
->randomName(),
'#type' => 'textarea',
);
$elements['textarea']['empty_values'] = $empty_strings;
$elements['radios']['element'] = array(
'#title' => $this
->randomName(),
'#type' => 'radios',
'#options' => array(
'' => t('None'),
$this
->randomName(),
$this
->randomName(),
$this
->randomName(),
),
);
$elements['radios']['empty_values'] = $empty_arrays;
$elements['checkbox']['element'] = array(
'#title' => $this
->randomName(),
'#type' => 'checkbox',
'#required' => TRUE,
);
$elements['checkbox']['empty_values'] = $empty_checkbox;
$elements['checkboxes']['element'] = array(
'#title' => $this
->randomName(),
'#type' => 'checkboxes',
'#options' => array(
$this
->randomName(),
$this
->randomName(),
$this
->randomName(),
),
);
$elements['checkboxes']['empty_values'] = $empty_arrays;
$elements['select']['element'] = array(
'#title' => $this
->randomName(),
'#type' => 'select',
'#options' => array(
'' => t('None'),
$this
->randomName(),
$this
->randomName(),
$this
->randomName(),
),
);
$elements['select']['empty_values'] = $empty_strings;
$elements['file']['element'] = array(
'#title' => $this
->randomName(),
'#type' => 'file',
);
$elements['file']['empty_values'] = $empty_strings;
// Regular expression to find the expected marker on required elements.
$required_marker_preg = '@<label.*<span class="form-required" title="This field is required\\.">\\*</span></label>@';
// Go through all the elements and all the empty values for them.
foreach ($elements as $type => $data) {
foreach ($data['empty_values'] as $key => $empty) {
foreach (array(
TRUE,
FALSE,
) as $required) {
$form_id = $this
->randomName();
$form = array();
$form_state = form_state_defaults();
form_clear_error();
$form['op'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
$element = $data['element']['#title'];
$form[$element] = $data['element'];
$form[$element]['#required'] = $required;
$form_state['input'][$element] = $empty;
$form_state['input']['form_id'] = $form_id;
$form_state['method'] = 'post';
// The form token CSRF protection should not interfere with this test,
// so we bypass it by marking this test form as programmed.
$form_state['programmed'] = TRUE;
drupal_prepare_form($form_id, $form, $form_state);
drupal_process_form($form_id, $form, $form_state);
$errors = form_get_errors();
// Form elements of type 'radios' throw all sorts of PHP notices
// when you try to render them like this, so we ignore those for
// testing the required marker.
// @todo Fix this work-around (http://drupal.org/node/588438).
$form_output = $type == 'radios' ? '' : drupal_render($form);
if ($required) {
// Make sure we have a form error for this element.
$this
->assertTrue(isset($errors[$element]), "Check empty({$key}) '{$type}' field '{$element}'");
if (!empty($form_output)) {
// Make sure the form element is marked as required.
$this
->assertTrue(preg_match($required_marker_preg, $form_output), "Required '{$type}' field is marked as required");
}
}
else {
if (!empty($form_output)) {
// Make sure the form element is *not* marked as required.
$this
->assertFalse(preg_match($required_marker_preg, $form_output), "Optional '{$type}' field is not marked as required");
}
if ($type == 'select') {
// Select elements are going to have validation errors with empty
// input, since those are illegal choices. Just make sure the
// error is not "field is required".
$this
->assertTrue(empty($errors[$element]) || strpos('field is required', $errors[$element]) === FALSE, "Optional '{$type}' field '{$element}' is not treated as a required element");
}
else {
// Make sure there is *no* form error for this element.
$this
->assertTrue(empty($errors[$element]), "Optional '{$type}' field '{$element}' has no errors with empty input");
}
}
}
}
}
// Clear the expected form error messages so they don't appear as exceptions.
drupal_get_messages();
}
/**
* Tests validation for required checkbox, select, and radio elements.
*
* Submits a test form containing several types of form elements. The form
* is submitted twice, first without values for required fields and then
* with values. Each submission is checked for relevant error messages.
*
* @see form_test_validate_required_form()
*/
function testRequiredCheckboxesRadio() {
$form = $form_state = array();
$form = form_test_validate_required_form($form, $form_state);
// Attempt to submit the form with no required fields set.
$edit = array();
$this
->drupalPost('form-test/validate-required', $edit, 'Submit');
// The only error messages that should appear are the relevant 'required'
// messages for each field.
$expected = array();
foreach (array(
'textfield',
'checkboxes',
'select',
'radios',
) as $key) {
$expected[] = t('!name field is required.', array(
'!name' => $form[$key]['#title'],
));
}
// Check the page for error messages.
$errors = $this
->xpath('//div[contains(@class, "error")]//li');
foreach ($errors as $error) {
$expected_key = array_search($error[0], $expected);
// If the error message is not one of the expected messages, fail.
if ($expected_key === FALSE) {
$this
->fail(format_string("Unexpected error message: @error", array(
'@error' => $error[0],
)));
}
else {
unset($expected[$expected_key]);
}
}
// Fail if any expected messages were not found.
foreach ($expected as $not_found) {
$this
->fail(format_string("Found error message: @error", array(
'@error' => $not_found,
)));
}
// Verify that input elements are still empty.
$this
->assertFieldByName('textfield', '');
$this
->assertNoFieldChecked('edit-checkboxes-foo');
$this
->assertNoFieldChecked('edit-checkboxes-bar');
$this
->assertOptionSelected('edit-select', '');
$this
->assertNoFieldChecked('edit-radios-foo');
$this
->assertNoFieldChecked('edit-radios-bar');
$this
->assertNoFieldChecked('edit-radios-optional-foo');
$this
->assertNoFieldChecked('edit-radios-optional-bar');
$this
->assertNoFieldChecked('edit-radios-optional-default-value-false-foo');
$this
->assertNoFieldChecked('edit-radios-optional-default-value-false-bar');
// Submit again with required fields set and verify that there are no
// error messages.
$edit = array(
'textfield' => $this
->randomString(),
'checkboxes[foo]' => TRUE,
'select' => 'foo',
'radios' => 'bar',
);
$this
->drupalPost(NULL, $edit, 'Submit');
$this
->assertNoFieldByXpath('//div[contains(@class, "error")]', FALSE, 'No error message is displayed when all required fields are filled.');
$this
->assertRaw("The form_test_validate_required_form form was submitted successfully.", 'Validation form submitted successfully.');
}
/**
* Tests validation for required textfield element without title.
*
* Submits a test form containing a textfield form elements without title.
* The form is submitted twice, first without value for the required field
* and then with value. Each submission is checked for relevant error
* messages.
*
* @see form_test_validate_required_form_no_title()
*/
function testRequiredTextfieldNoTitle() {
$form = $form_state = array();
$form = form_test_validate_required_form_no_title($form, $form_state);
// Attempt to submit the form with no required field set.
$edit = array();
$this
->drupalPost('form-test/validate-required-no-title', $edit, 'Submit');
$this
->assertNoRaw("The form_test_validate_required_form_no_title form was submitted successfully.", 'Validation form submitted successfully.');
// Check the page for the error class on the textfield.
$this
->assertFieldByXPath('//input[contains(@class, "error")]', FALSE, 'Error input form element class found.');
// Submit again with required fields set and verify that there are no
// error messages.
$edit = array(
'textfield' => $this
->randomString(),
);
$this
->drupalPost(NULL, $edit, 'Submit');
$this
->assertNoFieldByXpath('//input[contains(@class, "error")]', FALSE, 'No error input form element class found.');
$this
->assertRaw("The form_test_validate_required_form_no_title form was submitted successfully.", 'Validation form submitted successfully.');
}
/**
* Test default value handling for checkboxes.
*
* @see _form_test_checkbox()
*/
function testCheckboxProcessing() {
// First, try to submit without the required checkbox.
$edit = array();
$this
->drupalPost('form-test/checkbox', $edit, t('Submit'));
$this
->assertRaw(t('!name field is required.', array(
'!name' => 'required_checkbox',
)), 'A required checkbox is actually mandatory');
// Now try to submit the form correctly.
$values = drupal_json_decode($this
->drupalPost(NULL, array(
'required_checkbox' => 1,
), t('Submit')));
$expected_values = array(
'disabled_checkbox_on' => 'disabled_checkbox_on',
'disabled_checkbox_off' => 0,
'checkbox_on' => 'checkbox_on',
'checkbox_off' => 0,
'zero_checkbox_on' => '0',
'zero_checkbox_off' => 0,
);
foreach ($expected_values as $widget => $expected_value) {
$this
->assertIdentical($values[$widget], $expected_value, format_string('Checkbox %widget returns expected value (expected: %expected, got: %value)', array(
'%widget' => var_export($widget, TRUE),
'%expected' => var_export($expected_value, TRUE),
'%value' => var_export($values[$widget], TRUE),
)));
}
}
/**
* Tests validation of #type 'select' elements.
*/
function testSelect() {
$form = $form_state = array();
$form = form_test_select($form, $form_state);
$error = '!name field is required.';
$this
->drupalGet('form-test/select');
// Posting without any values should throw validation errors.
$this
->drupalPost(NULL, array(), 'Submit');
$this
->assertNoText(t($error, array(
'!name' => $form['select']['#title'],
)));
$this
->assertNoText(t($error, array(
'!name' => $form['select_required']['#title'],
)));
$this
->assertNoText(t($error, array(
'!name' => $form['select_optional']['#title'],
)));
$this
->assertNoText(t($error, array(
'!name' => $form['empty_value']['#title'],
)));
$this
->assertNoText(t($error, array(
'!name' => $form['empty_value_one']['#title'],
)));
$this
->assertText(t($error, array(
'!name' => $form['no_default']['#title'],
)));
$this
->assertNoText(t($error, array(
'!name' => $form['no_default_optional']['#title'],
)));
$this
->assertText(t($error, array(
'!name' => $form['no_default_empty_option']['#title'],
)));
$this
->assertNoText(t($error, array(
'!name' => $form['no_default_empty_option_optional']['#title'],
)));
$this
->assertText(t($error, array(
'!name' => $form['no_default_empty_value']['#title'],
)));
$this
->assertText(t($error, array(
'!name' => $form['no_default_empty_value_one']['#title'],
)));
$this
->assertNoText(t($error, array(
'!name' => $form['no_default_empty_value_optional']['#title'],
)));
$this
->assertNoText(t($error, array(
'!name' => $form['multiple']['#title'],
)));
$this
->assertNoText(t($error, array(
'!name' => $form['multiple_no_default']['#title'],
)));
$this
->assertText(t($error, array(
'!name' => $form['multiple_no_default_required']['#title'],
)));
// Post values for required fields.
$edit = array(
'no_default' => 'three',
'no_default_empty_option' => 'three',
'no_default_empty_value' => 'three',
'no_default_empty_value_one' => 'three',
'multiple_no_default_required[]' => 'three',
);
$this
->drupalPost(NULL, $edit, 'Submit');
$values = drupal_json_decode($this
->drupalGetContent());
// Verify expected values.
$expected = array(
'select' => 'one',
'empty_value' => 'one',
'empty_value_one' => 'one',
'no_default' => 'three',
'no_default_optional' => 'one',
'no_default_optional_empty_value' => '',
'no_default_empty_option' => 'three',
'no_default_empty_option_optional' => '',
'no_default_empty_value' => 'three',
'no_default_empty_value_one' => 'three',
'no_default_empty_value_optional' => 0,
'multiple' => array(
'two' => 'two',
),
'multiple_no_default' => array(),
'multiple_no_default_required' => array(
'three' => 'three',
),
);
foreach ($expected as $key => $value) {
$this
->assertIdentical($values[$key], $value, format_string('@name: @actual is equal to @expected.', array(
'@name' => $key,
'@actual' => var_export($values[$key], TRUE),
'@expected' => var_export($value, TRUE),
)));
}
}
/**
* Test handling of disabled elements.
*
* @see _form_test_disabled_elements()
*/
function testDisabledElements() {
// Get the raw form in its original state.
$form_state = array();
$form = _form_test_disabled_elements(array(), $form_state);
// Build a submission that tries to hijack the form by submitting input for
// elements that are disabled.
$edit = array();
foreach (element_children($form) as $key) {
if (isset($form[$key]['#test_hijack_value'])) {
if (is_array($form[$key]['#test_hijack_value'])) {
foreach ($form[$key]['#test_hijack_value'] as $subkey => $value) {
$edit[$key . '[' . $subkey . ']'] = $value;
}
}
else {
$edit[$key] = $form[$key]['#test_hijack_value'];
}
}
}
// Submit the form with no input, as the browser does for disabled elements,
// and fetch the $form_state['values'] that is passed to the submit handler.
$this
->drupalPost('form-test/disabled-elements', array(), t('Submit'));
$returned_values['normal'] = drupal_json_decode($this->content);
// Do the same with input, as could happen if JavaScript un-disables an
// element. drupalPost() emulates a browser by not submitting input for
// disabled elements, so we need to un-disable those elements first.
$this
->drupalGet('form-test/disabled-elements');
$disabled_elements = array();
foreach ($this
->xpath('//*[@disabled]') as $element) {
$disabled_elements[] = (string) $element['name'];
unset($element['disabled']);
}
// All the elements should be marked as disabled, including the ones below
// the disabled container.
$this
->assertEqual(count($disabled_elements), 32, 'The correct elements have the disabled property in the HTML code.');
$this
->drupalPost(NULL, $edit, t('Submit'));
$returned_values['hijacked'] = drupal_json_decode($this->content);
// Ensure that the returned values match the form's default values in both
// cases.
foreach ($returned_values as $type => $values) {
$this
->assertFormValuesDefault($values, $form);
}
}
/**
* Assert that the values submitted to a form matches the default values of the elements.
*/
function assertFormValuesDefault($values, $form) {
foreach (element_children($form) as $key) {
if (isset($form[$key]['#default_value'])) {
if (isset($form[$key]['#expected_value'])) {
$expected_value = $form[$key]['#expected_value'];
}
else {
$expected_value = $form[$key]['#default_value'];
}
if ($key == 'checkboxes_multiple') {
// Checkboxes values are not filtered out.
$values[$key] = array_filter($values[$key]);
}
$this
->assertIdentical($expected_value, $values[$key], format_string('Default value for %type: expected %expected, returned %returned.', array(
'%type' => $key,
'%expected' => var_export($expected_value, TRUE),
'%returned' => var_export($values[$key], TRUE),
)));
}
// Recurse children.
$this
->assertFormValuesDefault($values, $form[$key]);
}
}
/**
* Verify markup for disabled form elements.
*
* @see _form_test_disabled_elements()
*/
function testDisabledMarkup() {
$this
->drupalGet('form-test/disabled-elements');
$form_state = array();
$form = _form_test_disabled_elements(array(), $form_state);
$type_map = array(
'textarea' => 'textarea',
'select' => 'select',
'weight' => 'select',
'date' => 'select',
);
foreach ($form as $name => $item) {
// Skip special #types.
if (!isset($item['#type']) || in_array($item['#type'], array(
'hidden',
'text_format',
))) {
continue;
}
// Setup XPath and CSS class depending on #type.
if (in_array($item['#type'], array(
'image_button',
'button',
'submit',
))) {
$path = "//!type[contains(@class, :div-class) and @value=:value]";
$class = 'form-button-disabled';
}
else {
// starts-with() required for checkboxes.
$path = "//div[contains(@class, :div-class)]/descendant::!type[starts-with(@name, :name)]";
$class = 'form-disabled';
}
// Replace DOM element name in $path according to #type.
$type = 'input';
if (isset($type_map[$item['#type']])) {
$type = $type_map[$item['#type']];
}
$path = strtr($path, array(
'!type' => $type,
));
// Verify that the element exists.
$element = $this
->xpath($path, array(
':name' => check_plain($name),
':div-class' => $class,
':value' => isset($item['#value']) ? $item['#value'] : '',
));
$this
->assertTrue(isset($element[0]), format_string('Disabled form element class found for #type %type.', array(
'%type' => $item['#type'],
)));
}
// Verify special element #type text-format.
$element = $this
->xpath('//div[contains(@class, :div-class)]/descendant::textarea[@name=:name]', array(
':name' => 'text_format[value]',
':div-class' => 'form-disabled',
));
$this
->assertTrue(isset($element[0]), format_string('Disabled form element class found for #type %type.', array(
'%type' => 'text_format[value]',
)));
$element = $this
->xpath('//div[contains(@class, :div-class)]/descendant::select[@name=:name]', array(
':name' => 'text_format[format]',
':div-class' => 'form-disabled',
));
$this
->assertTrue(isset($element[0]), format_string('Disabled form element class found for #type %type.', array(
'%type' => 'text_format[format]',
)));
}
/**
* Test Form API protections against input forgery.
*
* @see _form_test_input_forgery()
*/
function testInputForgery() {
$this
->drupalGet('form-test/input-forgery');
$checkbox = $this
->xpath('//input[@name="checkboxes[two]"]');
$checkbox[0]['value'] = 'FORGERY';
$this
->drupalPost(NULL, array(
'checkboxes[one]' => TRUE,
'checkboxes[two]' => TRUE,
), t('Submit'));
$this
->assertText('An illegal choice has been detected.', 'Input forgery was detected.');
}
/**
* Tests that submitted values are converted to scalar strings for textfields.
*/
public function testTextfieldStringValue() {
// Check multivalued submissions.
$multivalue = array(
'evil' => 'multivalue',
'not so' => 'good',
);
$this
->checkFormValue('textfield', $multivalue, '');
$this
->checkFormValue('password', $multivalue, '');
$this
->checkFormValue('textarea', $multivalue, '');
$this
->checkFormValue('machine_name', $multivalue, '');
$this
->checkFormValue('password_confirm', $multivalue, array(
'pass1' => '',
'pass2' => '',
));
// Check integer submissions.
$integer = 5;
$string = '5';
$this
->checkFormValue('textfield', $integer, $string);
$this
->checkFormValue('password', $integer, $string);
$this
->checkFormValue('textarea', $integer, $string);
$this
->checkFormValue('machine_name', $integer, $string);
$this
->checkFormValue('password_confirm', array(
'pass1' => $integer,
'pass2' => $integer,
), array(
'pass1' => $string,
'pass2' => $string,
));
// Check that invalid array keys are ignored for password confirm elements.
$this
->checkFormValue('password_confirm', array(
'pass1' => 'test',
'pass2' => 'test',
'extra' => 'invalid',
), array(
'pass1' => 'test',
'pass2' => 'test',
));
}
/**
* Checks that a given form input value is sanitized to the expected result.
*
* @param string $element_type
* The form element type. Example: textfield.
* @param mixed $input_value
* The submitted user input value for the form element.
* @param mixed $expected_value
* The sanitized result value in the form state after calling
* form_builder().
*/
protected function checkFormValue($element_type, $input_value, $expected_value) {
$form_id = $this
->randomName();
$form = array();
$form_state = form_state_defaults();
$form['op'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
$form[$element_type] = array(
'#type' => $element_type,
'#title' => 'test',
);
$form_state['input'][$element_type] = $input_value;
$form_state['input']['form_id'] = $form_id;
$form_state['method'] = 'post';
$form_state['values'] = array();
drupal_prepare_form($form_id, $form, $form_state);
// Set the CSRF token in the user-provided input.
$form_state['input']['form_token'] = $form['form_token']['#default_value'];
// This is the main function we want to test: it is responsible for
// populating user supplied $form_state['input'] to sanitized
// $form_state['values'].
form_builder($form_id, $form, $form_state);
$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,
)));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalTestCase:: |
protected | property | Assertions thrown in that test case. | |
DrupalTestCase:: |
protected | property | The database prefix of this test run. | |
DrupalTestCase:: |
protected | property | The original file directory, before it was changed for testing purposes. | |
DrupalTestCase:: |
public | property | Current results of this test case. | |
DrupalTestCase:: |
protected | property | Flag to indicate whether the test has been set up. | |
DrupalTestCase:: |
protected | property | ||
DrupalTestCase:: |
protected | property | ||
DrupalTestCase:: |
protected | property | This class is skipped when looking for the source of an assertion. | |
DrupalTestCase:: |
protected | property | The test run ID. | |
DrupalTestCase:: |
protected | property | Time limit for the test. | |
DrupalTestCase:: |
public | property | Whether to cache the installation part of the setUp() method. | |
DrupalTestCase:: |
public | property | Whether to cache the modules installation part of the setUp() method. | |
DrupalTestCase:: |
protected | property | URL to the verbose output file directory. | |
DrupalTestCase:: |
protected | function | Internal helper: stores the assert. | |
DrupalTestCase:: |
protected | function | Check to see if two values are equal. | |
DrupalTestCase:: |
protected | function | Check to see if a value is false (an empty string, 0, NULL, or FALSE). | |
DrupalTestCase:: |
protected | function | Check to see if two values are identical. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not equal. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not identical. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not NULL. | |
DrupalTestCase:: |
protected | function | Check to see if a value is NULL. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not false (not an empty string, 0, NULL, or FALSE). | |
DrupalTestCase:: |
public static | function | Delete an assertion record by message ID. | |
DrupalTestCase:: |
protected | function | Fire an error assertion. | 1 |
DrupalTestCase:: |
public | function | Handle errors during test runs. | 1 |
DrupalTestCase:: |
protected | function | Handle exceptions. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always negative. | |
DrupalTestCase:: |
public static | function | Converts a list of possible parameters into a stack of permutations. | |
DrupalTestCase:: |
protected | function | Cycles through backtrace until the first non-assertion method is found. | |
DrupalTestCase:: |
public static | function | Returns the database connection to the site running Simpletest. | |
DrupalTestCase:: |
public static | function | Store an assertion from outside the testing context. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always positive. | |
DrupalTestCase:: |
public static | function | Generates a random string containing letters and numbers. | |
DrupalTestCase:: |
public static | function | Generates a random string of ASCII characters of codes 32 to 126. | |
DrupalTestCase:: |
public | function | Run all tests in this class. | |
DrupalTestCase:: |
protected | function | Logs a verbose message in a text file. | |
DrupalWebTestCase:: |
protected | property | Additional cURL options. | |
DrupalWebTestCase:: |
protected | property | The content of the page currently loaded in the internal browser. | |
DrupalWebTestCase:: |
protected | property | The current cookie file used by cURL. | |
DrupalWebTestCase:: |
protected | property | The cookies of the page currently loaded in the internal browser. | |
DrupalWebTestCase:: |
protected | property | The handle of the current cURL connection. | |
DrupalWebTestCase:: |
protected | property | The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser. | |
DrupalWebTestCase:: |
protected | property | The parsed version of the page. | |
DrupalWebTestCase:: |
protected | property | Whether the files were copied to the test files directory. | |
DrupalWebTestCase:: |
protected | property | The headers of the page currently loaded in the internal browser. | |
DrupalWebTestCase:: |
protected | property | HTTP authentication credentials (<username>:<password>). | |
DrupalWebTestCase:: |
protected | property | HTTP authentication method | |
DrupalWebTestCase:: |
protected | property | The current user logged in using the internal browser. | |
DrupalWebTestCase:: |
protected | property | The original shutdown handlers array, before it was cleaned for testing purposes. | |
DrupalWebTestCase:: |
protected | property | The original user, before it was changed to a clean uid = 1 for testing purposes. | |
DrupalWebTestCase:: |
protected | property | The content of the page currently loaded in the internal browser (plain text version). | |
DrupalWebTestCase:: |
protected | property | The profile to install as a basis for testing. | 20 |
DrupalWebTestCase:: |
protected | property | The number of redirects followed during the handling of a request. | |
DrupalWebTestCase:: |
protected | property | The current session ID, if available. | |
DrupalWebTestCase:: |
protected | property | The current session name, if available. | |
DrupalWebTestCase:: |
protected | property | The URL currently loaded in the internal browser. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field exists with the given name or ID. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field exists in the current page with the given ID and value. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field exists in the current page with the given name and value. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field exists in the current page by the given XPath. | |
DrupalWebTestCase:: |
protected | function | Asserts that a checkbox field in the current page is checked. | |
DrupalWebTestCase:: |
protected | function | Pass if a link with the specified label is found, and optional with the specified index. | |
DrupalWebTestCase:: |
protected | function | Pass if a link containing a given href (part) is found. | |
DrupalWebTestCase:: |
protected | function | Asserts that the most recently sent e-mail message has the given value. | |
DrupalWebTestCase:: |
protected | function | Asserts that the most recently sent e-mail message has the pattern in it. | |
DrupalWebTestCase:: |
protected | function | Asserts that the most recently sent e-mail message has the string in it. | |
DrupalWebTestCase:: |
protected | function | Asserts that each HTML ID is used for just a single element. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field does not exist with the given name or ID. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field does not exist with the given ID and value. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field does not exist with the given name and value. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field doesn't exist or its value doesn't match, by XPath. | |
DrupalWebTestCase:: |
protected | function | Asserts that a checkbox field in the current page is not checked. | |
DrupalWebTestCase:: |
protected | function | Pass if a link with the specified label is not found. | |
DrupalWebTestCase:: |
protected | function | Pass if a link containing a given href (part) is not found. | |
DrupalWebTestCase:: |
protected | function | Asserts that a select option in the current page is not checked. | |
DrupalWebTestCase:: |
protected | function | Will trigger a pass if the perl regex pattern is not present in raw content. | |
DrupalWebTestCase:: |
protected | function | Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated. | |
DrupalWebTestCase:: |
protected | function | Asserts the page did not return the specified response code. | |
DrupalWebTestCase:: |
protected | function | Pass if the text is NOT found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents. | |
DrupalWebTestCase:: |
protected | function | Pass if the page title is not the given string. | |
DrupalWebTestCase:: |
protected | function | Pass if the text is found MORE THAN ONCE on the text version of the page. | |
DrupalWebTestCase:: |
protected | function | Asserts that a select option in the current page is checked. | |
DrupalWebTestCase:: |
protected | function | Will trigger a pass if the Perl regex pattern is found in the raw content. | |
DrupalWebTestCase:: |
protected | function | Pass if the raw text IS found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated. | |
DrupalWebTestCase:: |
protected | function | Asserts the page responds with the specified response code. | |
DrupalWebTestCase:: |
protected | function | Pass if the text IS found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents. | |
DrupalWebTestCase:: |
protected | function | Helper for assertText and assertNoText. | |
DrupalWebTestCase:: |
protected | function | Asserts themed output. | |
DrupalWebTestCase:: |
protected | function | Pass if the page title is the given string. | |
DrupalWebTestCase:: |
protected | function | Pass if the text is found ONLY ONCE on the text version of the page. | |
DrupalWebTestCase:: |
protected | function | Helper for assertUniqueText and assertNoUniqueText. | |
DrupalWebTestCase:: |
protected | function | Pass if the internal browser's URL matches the given path. | |
DrupalWebTestCase:: |
protected | function | Builds an XPath query. | |
DrupalWebTestCase:: |
protected | function | Changes the database connection to the prefixed one. | |
DrupalWebTestCase:: |
protected | function | Check for meta refresh tag and if found call drupalGet() recursively. This function looks for the http-equiv attribute to be set to "Refresh" and is case-sensitive. | |
DrupalWebTestCase:: |
protected | function | Check to make sure that the array of permissions are valid. | |
DrupalWebTestCase:: |
protected | function | Follows a link by name. | |
DrupalWebTestCase:: |
protected | function | Helper function: construct an XPath for the given set of attributes and value. | |
DrupalWebTestCase:: |
protected | function | Copy the setup cache from/to another table and files directory. | |
DrupalWebTestCase:: |
protected | function | Runs cron in the Drupal installed by Simpletest. | |
DrupalWebTestCase:: |
protected | function | Close the cURL handler and unset the handler. | |
DrupalWebTestCase:: |
protected | function | Initializes and executes a cURL request. | |
DrupalWebTestCase:: |
protected | function | Reads headers and registers errors received from the tested site. | |
DrupalWebTestCase:: |
protected | function | Initializes the cURL connection. | |
DrupalWebTestCase:: |
protected | function | Compare two files based on size and file name. | |
DrupalWebTestCase:: |
protected | function | Creates a custom content type based on default settings. | |
DrupalWebTestCase:: |
protected | function | Creates a node based on default settings. | |
DrupalWebTestCase:: |
protected | function | Creates a role with specified permissions. | |
DrupalWebTestCase:: |
protected | function | Create a user with a given set of permissions. | |
DrupalWebTestCase:: |
protected | function | Retrieves a Drupal path or an absolute path. | |
DrupalWebTestCase:: |
protected | function | Retrieve a Drupal path or an absolute path and JSON decode the result. | |
DrupalWebTestCase:: |
protected | function | Gets the current raw HTML of requested page. | |
DrupalWebTestCase:: |
protected | function | Gets the value of an HTTP response header. If multiple requests were required to retrieve the page, only the headers from the last request will be checked by default. However, if TRUE is passed as the second argument, all requests will be processed… | |
DrupalWebTestCase:: |
protected | function | Gets the HTTP response headers of the requested page. Normally we are only interested in the headers returned by the last request. However, if a page is redirected or HTTP authentication is in use, multiple requests will be required to retrieve the… | |
DrupalWebTestCase:: |
protected | function | Gets an array containing all e-mails sent during this test case. | |
DrupalWebTestCase:: |
function | Get a node from the database based on its title. | ||
DrupalWebTestCase:: |
protected | function | Gets the value of the Drupal.settings JavaScript variable for the currently loaded page. | |
DrupalWebTestCase:: |
protected | function | Get a list files that can be used in tests. | |
DrupalWebTestCase:: |
protected | function | Generate a token for the currently logged in user. | |
DrupalWebTestCase:: |
protected | function | Retrieves only the headers for a Drupal path or an absolute path. | |
DrupalWebTestCase:: |
protected | function | Log in a user with the internal browser. | |
DrupalWebTestCase:: |
protected | function | ||
DrupalWebTestCase:: |
protected | function | Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser. | |
DrupalWebTestCase:: |
protected | function | Execute an Ajax submission. | |
DrupalWebTestCase:: |
protected | function | Sets the raw HTML content. This can be useful when a page has been fetched outside of the internal browser and assertions need to be made on the returned page. | |
DrupalWebTestCase:: |
protected | function | Sets the value of the Drupal.settings JavaScript variable for the currently loaded page. | |
DrupalWebTestCase:: |
protected | function | Takes a path and returns an absolute path. | |
DrupalWebTestCase:: |
protected | function | Get all option elements, including nested options, in a select. | |
DrupalWebTestCase:: |
protected | function | Get the selected value from a select field. | |
DrupalWebTestCase:: |
protected | function | Returns the cache key used for the setup caching. | |
DrupalWebTestCase:: |
protected | function | Get the current URL from the cURL handler. | |
DrupalWebTestCase:: |
protected | function | Handle form input related to drupalPost(). Ensure that the specified fields exist and attempt to create POST data in the correct manner for the particular field type. | |
DrupalWebTestCase:: |
protected | function | Copies the cached tables and files for a cached installation setup. | |
DrupalWebTestCase:: |
protected | function | Parse content returned from curlExec using DOM and SimpleXML. | |
DrupalWebTestCase:: |
protected | function | Preload the registry from the testing site. | |
DrupalWebTestCase:: |
protected | function | Generates a database prefix for running tests. | |
DrupalWebTestCase:: |
protected | function | Prepares the current environment for running the test. | |
DrupalWebTestCase:: |
protected | function | Recursively copy one directory to another. | |
DrupalWebTestCase:: |
protected | function | Refresh the in-memory set of variables. Useful after a page request is made that changes a variable in a different thread. | 1 |
DrupalWebTestCase:: |
protected | function | Reset all data structures after having enabled new modules. | |
DrupalWebTestCase:: |
protected | function | Store the installation setup to a cache. | |
DrupalWebTestCase:: |
protected | function | Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix. | 6 |
DrupalWebTestCase:: |
protected | function | Outputs to verbose the most recent $count emails sent. | |
DrupalWebTestCase:: |
protected | function | Perform an xpath search on the contents of the internal browser. The search is relative to the root element (HTML tag normally) of the page. | |
DrupalWebTestCase:: |
function |
Constructor for DrupalWebTestCase. Overrides DrupalTestCase:: |
1 | |
FormsTestCase:: |
function | Assert that the values submitted to a form matches the default values of the elements. | ||
FormsTestCase:: |
protected | function | Checks that a given form input value is sanitized to the expected result. | |
FormsTestCase:: |
public static | function | ||
FormsTestCase:: |
function |
Sets up a Drupal site for running functional and integration tests. Overrides DrupalWebTestCase:: |
||
FormsTestCase:: |
function | Test default value handling for checkboxes. | ||
FormsTestCase:: |
function | Test handling of disabled elements. | ||
FormsTestCase:: |
function | Verify markup for disabled form elements. | ||
FormsTestCase:: |
function | Test Form API protections against input forgery. | ||
FormsTestCase:: |
function | Tests validation for required checkbox, select, and radio elements. | ||
FormsTestCase:: |
function | Check several empty values for required forms elements. | ||
FormsTestCase:: |
function | Tests validation for required textfield element without title. | ||
FormsTestCase:: |
function | Tests validation of #type 'select' elements. | ||
FormsTestCase:: |
public | function | Tests that submitted values are converted to scalar strings for textfields. |