Expanded class hierarchy of FieldFormTestCase
class FieldFormTestCase extends FieldTestCase {
public static function getInfo() {
return array(
'name' => 'Field form tests',
'description' => 'Test Field form handling.',
'group' => 'Field API',
);
}
function setUp() {
parent::setUp('field_test');
$web_user = $this
->drupalCreateUser(array(
'access field_test content',
'administer field_test content',
));
$this
->drupalLogin($web_user);
$this->field_single = array(
'field_name' => 'field_single',
'type' => 'test_field',
);
$this->field_multiple = array(
'field_name' => 'field_multiple',
'type' => 'test_field',
'cardinality' => 4,
);
$this->field_unlimited = array(
'field_name' => 'field_unlimited',
'type' => 'test_field',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
$this->instance = array(
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'label' => $this
->randomName() . '_label',
'description' => $this
->randomName() . '_description',
'weight' => mt_rand(0, 127),
'settings' => array(
'test_instance_setting' => $this
->randomName(),
),
'widget' => array(
'type' => 'test_field_widget',
'label' => 'Test Field',
'settings' => array(
'test_widget_setting' => $this
->randomName(),
),
),
);
}
function testFieldFormSingle() {
$this->field = $this->field_single;
$this->field_name = $this->field['field_name'];
$this->instance['field_name'] = $this->field_name;
field_create_field($this->field);
field_create_instance($this->instance);
$langcode = LANGUAGE_NONE;
// Display creation form.
$this
->drupalGet('test-entity/add/test-bundle');
$this
->assertFieldByName("{$this->field_name}[{$langcode}][0][value]", '', 'Widget is displayed');
$this
->assertNoField("{$this->field_name}[{$langcode}][1][value]", 'No extraneous widget is displayed');
// TODO : check that the widget is populated with default value ?
// Submit with invalid value (field-level validation).
$edit = array(
"{$this->field_name}[{$langcode}][0][value]" => -1,
);
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertRaw(t('%name does not accept the value -1.', array(
'%name' => $this->instance['label'],
)), 'Field validation fails with invalid input.');
// TODO : check that the correct field is flagged for error.
// Create an entity
$value = mt_rand(1, 127);
$edit = array(
"{$this->field_name}[{$langcode}][0][value]" => $value,
);
$this
->drupalPost(NULL, $edit, t('Save'));
preg_match('|test-entity/manage/(\\d+)/edit|', $this->url, $match);
$id = $match[1];
$this
->assertRaw(t('test_entity @id has been created.', array(
'@id' => $id,
)), 'Entity was created');
$entity = field_test_entity_test_load($id);
$this
->assertEqual($entity->{$this->field_name}[$langcode][0]['value'], $value, 'Field value was saved');
// Display edit form.
$this
->drupalGet('test-entity/manage/' . $id . '/edit');
$this
->assertFieldByName("{$this->field_name}[{$langcode}][0][value]", $value, 'Widget is displayed with the correct default value');
$this
->assertNoField("{$this->field_name}[{$langcode}][1][value]", 'No extraneous widget is displayed');
// Update the entity.
$value = mt_rand(1, 127);
$edit = array(
"{$this->field_name}[{$langcode}][0][value]" => $value,
);
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertRaw(t('test_entity @id has been updated.', array(
'@id' => $id,
)), 'Entity was updated');
$entity = field_test_entity_test_load($id);
$this
->assertEqual($entity->{$this->field_name}[$langcode][0]['value'], $value, 'Field value was updated');
// Empty the field.
$value = '';
$edit = array(
"{$this->field_name}[{$langcode}][0][value]" => $value,
);
$this
->drupalPost('test-entity/manage/' . $id . '/edit', $edit, t('Save'));
$this
->assertRaw(t('test_entity @id has been updated.', array(
'@id' => $id,
)), 'Entity was updated');
$entity = field_test_entity_test_load($id);
$this
->assertIdentical($entity->{$this->field_name}, array(), 'Field was emptied');
}
function testFieldFormSingleRequired() {
$this->field = $this->field_single;
$this->field_name = $this->field['field_name'];
$this->instance['field_name'] = $this->field_name;
$this->instance['required'] = TRUE;
field_create_field($this->field);
field_create_instance($this->instance);
$langcode = LANGUAGE_NONE;
// Submit with missing required value.
$edit = array();
$this
->drupalPost('test-entity/add/test-bundle', $edit, t('Save'));
$this
->assertRaw(t('!name field is required.', array(
'!name' => $this->instance['label'],
)), 'Required field with no value fails validation');
// Create an entity
$value = mt_rand(1, 127);
$edit = array(
"{$this->field_name}[{$langcode}][0][value]" => $value,
);
$this
->drupalPost(NULL, $edit, t('Save'));
preg_match('|test-entity/manage/(\\d+)/edit|', $this->url, $match);
$id = $match[1];
$this
->assertRaw(t('test_entity @id has been created.', array(
'@id' => $id,
)), 'Entity was created');
$entity = field_test_entity_test_load($id);
$this
->assertEqual($entity->{$this->field_name}[$langcode][0]['value'], $value, 'Field value was saved');
// Edit with missing required value.
$value = '';
$edit = array(
"{$this->field_name}[{$langcode}][0][value]" => $value,
);
$this
->drupalPost('test-entity/manage/' . $id . '/edit', $edit, t('Save'));
$this
->assertRaw(t('!name field is required.', array(
'!name' => $this->instance['label'],
)), 'Required field with no value fails validation');
}
// function testFieldFormMultiple() {
// $this->field = $this->field_multiple;
// $this->field_name = $this->field['field_name'];
// $this->instance['field_name'] = $this->field_name;
// field_create_field($this->field);
// field_create_instance($this->instance);
// }
function testFieldFormUnlimited() {
$this->field = $this->field_unlimited;
$this->field_name = $this->field['field_name'];
$this->instance['field_name'] = $this->field_name;
field_create_field($this->field);
field_create_instance($this->instance);
$langcode = LANGUAGE_NONE;
// Display creation form -> 1 widget.
$this
->drupalGet('test-entity/add/test-bundle');
$this
->assertFieldByName("{$this->field_name}[{$langcode}][0][value]", '', 'Widget 1 is displayed');
$this
->assertNoField("{$this->field_name}[{$langcode}][1][value]", 'No extraneous widget is displayed');
// Press 'add more' button -> 2 widgets.
$this
->drupalPost(NULL, array(), t('Add another item'));
$this
->assertFieldByName("{$this->field_name}[{$langcode}][0][value]", '', 'Widget 1 is displayed');
$this
->assertFieldByName("{$this->field_name}[{$langcode}][1][value]", '', 'New widget is displayed');
$this
->assertNoField("{$this->field_name}[{$langcode}][2][value]", 'No extraneous widget is displayed');
// TODO : check that non-field inpurs are preserved ('title')...
// Yet another time so that we can play with more values -> 3 widgets.
$this
->drupalPost(NULL, array(), t('Add another item'));
// Prepare values and weights.
$count = 3;
$delta_range = $count - 1;
$values = $weights = $pattern = $expected_values = $edit = array();
for ($delta = 0; $delta <= $delta_range; $delta++) {
// Assign unique random values and weights.
do {
$value = mt_rand(1, 127);
} while (in_array($value, $values));
do {
$weight = mt_rand(-$delta_range, $delta_range);
} while (in_array($weight, $weights));
$edit["{$this->field_name}[{$langcode}][{$delta}][value]"] = $value;
$edit["{$this->field_name}[{$langcode}][{$delta}][_weight]"] = $weight;
// We'll need three slightly different formats to check the values.
$values[$delta] = $value;
$weights[$delta] = $weight;
$field_values[$weight]['value'] = (string) $value;
$pattern[$weight] = "<input [^>]*value=\"{$value}\" [^>]*";
}
// Press 'add more' button -> 4 widgets
$this
->drupalPost(NULL, $edit, t('Add another item'));
for ($delta = 0; $delta <= $delta_range; $delta++) {
$this
->assertFieldByName("{$this->field_name}[{$langcode}][{$delta}][value]", $values[$delta], "Widget {$delta} is displayed and has the right value");
$this
->assertFieldByName("{$this->field_name}[{$langcode}][{$delta}][_weight]", $weights[$delta], "Widget {$delta} has the right weight");
}
ksort($pattern);
$pattern = implode('.*', array_values($pattern));
$this
->assertPattern("|{$pattern}|s", 'Widgets are displayed in the correct order');
$this
->assertFieldByName("{$this->field_name}[{$langcode}][{$delta}][value]", '', "New widget is displayed");
$this
->assertFieldByName("{$this->field_name}[{$langcode}][{$delta}][_weight]", $delta, "New widget has the right weight");
$this
->assertNoField("{$this->field_name}[{$langcode}][" . ($delta + 1) . '][value]', 'No extraneous widget is displayed');
// Submit the form and create the entity.
$this
->drupalPost(NULL, $edit, t('Save'));
preg_match('|test-entity/manage/(\\d+)/edit|', $this->url, $match);
$id = $match[1];
$this
->assertRaw(t('test_entity @id has been created.', array(
'@id' => $id,
)), 'Entity was created');
$entity = field_test_entity_test_load($id);
ksort($field_values);
$field_values = array_values($field_values);
$this
->assertIdentical($entity->{$this->field_name}[$langcode], $field_values, 'Field values were saved in the correct order');
// Display edit form: check that the expected number of widgets is
// displayed, with correct values change values, reorder, leave an empty
// value in the middle.
// Submit: check that the entity is updated with correct values
// Re-submit: check that the field can be emptied.
// Test with several multiple fields in a form
}
/**
* Tests widget handling of multiple required radios.
*/
function testFieldFormMultivalueWithRequiredRadio() {
// Create a multivalue test field.
$this->field = $this->field_unlimited;
$this->field_name = $this->field['field_name'];
$this->instance['field_name'] = $this->field_name;
field_create_field($this->field);
field_create_instance($this->instance);
$langcode = LANGUAGE_NONE;
// Add a required radio field.
field_create_field(array(
'field_name' => 'required_radio_test',
'type' => 'list_text',
'settings' => array(
'allowed_values' => array(
'yes' => 'yes',
'no' => 'no',
),
),
));
field_create_instance(array(
'field_name' => 'required_radio_test',
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'required' => TRUE,
'widget' => array(
'type' => 'options_buttons',
),
));
// Display creation form.
$this
->drupalGet('test-entity/add/test-bundle');
// Press the 'Add more' button.
$this
->drupalPost(NULL, array(), t('Add another item'));
// Verify that no error is thrown by the radio element.
$this
->assertNoFieldByXpath('//div[contains(@class, "error")]', FALSE, 'No error message is displayed.');
// Verify that the widget is added.
$this
->assertFieldByName("{$this->field_name}[{$langcode}][0][value]", '', 'Widget 1 is displayed');
$this
->assertFieldByName("{$this->field_name}[{$langcode}][1][value]", '', 'New widget is displayed');
$this
->assertNoField("{$this->field_name}[{$langcode}][2][value]", 'No extraneous widget is displayed');
}
function testFieldFormJSAddMore() {
$this->field = $this->field_unlimited;
$this->field_name = $this->field['field_name'];
$this->instance['field_name'] = $this->field_name;
field_create_field($this->field);
field_create_instance($this->instance);
$langcode = LANGUAGE_NONE;
// Display creation form -> 1 widget.
$this
->drupalGet('test-entity/add/test-bundle');
// Press 'add more' button a couple times -> 3 widgets.
// drupalPostAJAX() will not work iteratively, so we add those through
// non-JS submission.
$this
->drupalPost(NULL, array(), t('Add another item'));
$this
->drupalPost(NULL, array(), t('Add another item'));
// Prepare values and weights.
$count = 3;
$delta_range = $count - 1;
$values = $weights = $pattern = $expected_values = $edit = array();
for ($delta = 0; $delta <= $delta_range; $delta++) {
// Assign unique random values and weights.
do {
$value = mt_rand(1, 127);
} while (in_array($value, $values));
do {
$weight = mt_rand(-$delta_range, $delta_range);
} while (in_array($weight, $weights));
$edit["{$this->field_name}[{$langcode}][{$delta}][value]"] = $value;
$edit["{$this->field_name}[{$langcode}][{$delta}][_weight]"] = $weight;
// We'll need three slightly different formats to check the values.
$values[$delta] = $value;
$weights[$delta] = $weight;
$field_values[$weight]['value'] = (string) $value;
$pattern[$weight] = "<input [^>]*value=\"{$value}\" [^>]*";
}
// Press 'add more' button through Ajax, and place the expected HTML result
// as the tested content.
$commands = $this
->drupalPostAJAX(NULL, $edit, $this->field_name . '_add_more');
$this->content = $commands[1]['data'];
for ($delta = 0; $delta <= $delta_range; $delta++) {
$this
->assertFieldByName("{$this->field_name}[{$langcode}][{$delta}][value]", $values[$delta], "Widget {$delta} is displayed and has the right value");
$this
->assertFieldByName("{$this->field_name}[{$langcode}][{$delta}][_weight]", $weights[$delta], "Widget {$delta} has the right weight");
}
ksort($pattern);
$pattern = implode('.*', array_values($pattern));
$this
->assertPattern("|{$pattern}|s", 'Widgets are displayed in the correct order');
$this
->assertFieldByName("{$this->field_name}[{$langcode}][{$delta}][value]", '', "New widget is displayed");
$this
->assertFieldByName("{$this->field_name}[{$langcode}][{$delta}][_weight]", $delta, "New widget has the right weight");
$this
->assertNoField("{$this->field_name}[{$langcode}][" . ($delta + 1) . '][value]', 'No extraneous widget is displayed');
}
/**
* Tests widgets handling multiple values.
*/
function testFieldFormMultipleWidget() {
// Create a field with fixed cardinality and an instance using a multiple
// widget.
$this->field = $this->field_multiple;
$this->field_name = $this->field['field_name'];
$this->instance['field_name'] = $this->field_name;
$this->instance['widget']['type'] = 'test_field_widget_multiple';
field_create_field($this->field);
field_create_instance($this->instance);
$langcode = LANGUAGE_NONE;
// Display creation form.
$this
->drupalGet('test-entity/add/test-bundle');
$this
->assertFieldByName("{$this->field_name}[{$langcode}]", '', 'Widget is displayed.');
// Create entity with three values.
$edit = array(
"{$this->field_name}[{$langcode}]" => '1, 2, 3',
);
$this
->drupalPost(NULL, $edit, t('Save'));
preg_match('|test-entity/manage/(\\d+)/edit|', $this->url, $match);
$id = $match[1];
// Check that the values were saved.
$entity_init = field_test_create_stub_entity($id);
$this
->assertFieldValues($entity_init, $this->field_name, $langcode, array(
1,
2,
3,
));
// Display the form, check that the values are correctly filled in.
$this
->drupalGet('test-entity/manage/' . $id . '/edit');
$this
->assertFieldByName("{$this->field_name}[{$langcode}]", '1, 2, 3', 'Widget is displayed.');
// Submit the form with more values than the field accepts.
$edit = array(
"{$this->field_name}[{$langcode}]" => '1, 2, 3, 4, 5',
);
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertRaw('this field cannot hold more than 4 values', 'Form validation failed.');
// Check that the field values were not submitted.
$this
->assertFieldValues($entity_init, $this->field_name, $langcode, array(
1,
2,
3,
));
}
/**
* Tests fields with no 'edit' access.
*/
function testFieldFormAccess() {
// Create a "regular" field.
$field = $this->field_single;
$field_name = $field['field_name'];
$instance = $this->instance;
$instance['field_name'] = $field_name;
field_create_field($field);
field_create_instance($instance);
// Create a field with no edit access - see field_test_field_access().
$field_no_access = array(
'field_name' => 'field_no_edit_access',
'type' => 'test_field',
);
$field_name_no_access = $field_no_access['field_name'];
$instance_no_access = array(
'field_name' => $field_name_no_access,
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'default_value' => array(
0 => array(
'value' => 99,
),
),
);
field_create_field($field_no_access);
field_create_instance($instance_no_access);
$langcode = LANGUAGE_NONE;
// Test that the form structure includes full information for each delta
// apart from #access.
$entity_type = 'test_entity';
$entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
$form = array();
$form_state = form_state_defaults();
field_attach_form($entity_type, $entity, $form, $form_state);
$this
->assertEqual($form[$field_name_no_access][$langcode][0]['value']['#entity_type'], $entity_type, 'The correct entity type is set in the field structure.');
$this
->assertFalse($form[$field_name_no_access]['#access'], 'Field #access is FALSE for the field without edit access.');
// Display creation form.
$this
->drupalGet('test-entity/add/test-bundle');
$this
->assertNoFieldByName("{$field_name_no_access}[{$langcode}][0][value]", '', 'Widget is not displayed if field access is denied.');
// Create entity.
$edit = array(
"{$field_name}[{$langcode}][0][value]" => 1,
);
$this
->drupalPost(NULL, $edit, t('Save'));
preg_match('|test-entity/manage/(\\d+)/edit|', $this->url, $match);
$id = $match[1];
// Check that the default value was saved.
$entity = field_test_entity_test_load($id);
$this
->assertEqual($entity->{$field_name_no_access}[$langcode][0]['value'], 99, 'Default value was saved for the field with no edit access.');
$this
->assertEqual($entity->{$field_name}[$langcode][0]['value'], 1, 'Entered value vas saved for the field with edit access.');
// Create a new revision.
$edit = array(
"{$field_name}[{$langcode}][0][value]" => 2,
'revision' => TRUE,
);
$this
->drupalPost('test-entity/manage/' . $id . '/edit', $edit, t('Save'));
// Check that the new revision has the expected values.
$entity = field_test_entity_test_load($id);
$this
->assertEqual($entity->{$field_name_no_access}[$langcode][0]['value'], 99, 'New revision has the expected value for the field with no edit access.');
$this
->assertEqual($entity->{$field_name}[$langcode][0]['value'], 2, 'New revision has the expected value for the field with edit access.');
// Check that the revision is also saved in the revisions table.
$entity = field_test_entity_test_load($id, $entity->ftvid);
$this
->assertEqual($entity->{$field_name_no_access}[$langcode][0]['value'], 99, 'New revision has the expected value for the field with no edit access.');
$this
->assertEqual($entity->{$field_name}[$langcode][0]['value'], 2, 'New revision has the expected value for the field with edit access.');
}
/**
* Tests Field API form integration within a subform.
*/
function testNestedFieldForm() {
// Add two instances on the 'test_bundle'
field_create_field($this->field_single);
field_create_field($this->field_unlimited);
$this->instance['field_name'] = 'field_single';
$this->instance['label'] = 'Single field';
field_create_instance($this->instance);
$this->instance['field_name'] = 'field_unlimited';
$this->instance['label'] = 'Unlimited field';
field_create_instance($this->instance);
// Create two entities.
$entity_1 = field_test_create_stub_entity(1, 1);
$entity_1->is_new = TRUE;
$entity_1->field_single[LANGUAGE_NONE][] = array(
'value' => 0,
);
$entity_1->field_unlimited[LANGUAGE_NONE][] = array(
'value' => 1,
);
field_test_entity_save($entity_1);
$entity_2 = field_test_create_stub_entity(2, 2);
$entity_2->is_new = TRUE;
$entity_2->field_single[LANGUAGE_NONE][] = array(
'value' => 10,
);
$entity_2->field_unlimited[LANGUAGE_NONE][] = array(
'value' => 11,
);
field_test_entity_save($entity_2);
// Display the 'combined form'.
$this
->drupalGet('test-entity/nested/1/2');
$this
->assertFieldByName('field_single[und][0][value]', 0, 'Entity 1: field_single value appears correctly is the form.');
$this
->assertFieldByName('field_unlimited[und][0][value]', 1, 'Entity 1: field_unlimited value 0 appears correctly is the form.');
$this
->assertFieldByName('entity_2[field_single][und][0][value]', 10, 'Entity 2: field_single value appears correctly is the form.');
$this
->assertFieldByName('entity_2[field_unlimited][und][0][value]', 11, 'Entity 2: field_unlimited value 0 appears correctly is the form.');
// Submit the form and check that the entities are updated accordingly.
$edit = array(
'field_single[und][0][value]' => 1,
'field_unlimited[und][0][value]' => 2,
'field_unlimited[und][1][value]' => 3,
'entity_2[field_single][und][0][value]' => 11,
'entity_2[field_unlimited][und][0][value]' => 12,
'entity_2[field_unlimited][und][1][value]' => 13,
);
$this
->drupalPost(NULL, $edit, t('Save'));
field_cache_clear();
$entity_1 = field_test_create_stub_entity(1);
$entity_2 = field_test_create_stub_entity(2);
$this
->assertFieldValues($entity_1, 'field_single', LANGUAGE_NONE, array(
1,
));
$this
->assertFieldValues($entity_1, 'field_unlimited', LANGUAGE_NONE, array(
2,
3,
));
$this
->assertFieldValues($entity_2, 'field_single', LANGUAGE_NONE, array(
11,
));
$this
->assertFieldValues($entity_2, 'field_unlimited', LANGUAGE_NONE, array(
12,
13,
));
// Submit invalid values and check that errors are reported on the
// correct widgets.
$edit = array(
'field_unlimited[und][1][value]' => -1,
);
$this
->drupalPost('test-entity/nested/1/2', $edit, t('Save'));
$this
->assertRaw(t('%label does not accept the value -1', array(
'%label' => 'Unlimited field',
)), 'Entity 1: the field validation error was reported.');
$error_field = $this
->xpath('//input[@id=:id and contains(@class, "error")]', array(
':id' => 'edit-field-unlimited-und-1-value',
));
$this
->assertTrue($error_field, 'Entity 1: the error was flagged on the correct element.');
$edit = array(
'entity_2[field_unlimited][und][1][value]' => -1,
);
$this
->drupalPost('test-entity/nested/1/2', $edit, t('Save'));
$this
->assertRaw(t('%label does not accept the value -1', array(
'%label' => 'Unlimited field',
)), 'Entity 2: the field validation error was reported.');
$error_field = $this
->xpath('//input[@id=:id and contains(@class, "error")]', array(
':id' => 'edit-entity-2-field-unlimited-und-1-value',
));
$this
->assertTrue($error_field, 'Entity 2: the error was flagged on the correct element.');
// Test that reordering works on both entities.
$edit = array(
'field_unlimited[und][0][_weight]' => 0,
'field_unlimited[und][1][_weight]' => -1,
'entity_2[field_unlimited][und][0][_weight]' => 0,
'entity_2[field_unlimited][und][1][_weight]' => -1,
);
$this
->drupalPost('test-entity/nested/1/2', $edit, t('Save'));
field_cache_clear();
$this
->assertFieldValues($entity_1, 'field_unlimited', LANGUAGE_NONE, array(
3,
2,
));
$this
->assertFieldValues($entity_2, 'field_unlimited', LANGUAGE_NONE, array(
13,
12,
));
// Test the 'add more' buttons. Only Ajax submission is tested, because
// the two 'add more' buttons present in the form have the same #value,
// which confuses drupalPost().
// 'Add more' button in the first entity:
$this
->drupalGet('test-entity/nested/1/2');
$this
->drupalPostAJAX(NULL, array(), 'field_unlimited_add_more');
$this
->assertFieldByName('field_unlimited[und][0][value]', 3, 'Entity 1: field_unlimited value 0 appears correctly is the form.');
$this
->assertFieldByName('field_unlimited[und][1][value]', 2, 'Entity 1: field_unlimited value 1 appears correctly is the form.');
$this
->assertFieldByName('field_unlimited[und][2][value]', '', 'Entity 1: field_unlimited value 2 appears correctly is the form.');
$this
->assertFieldByName('field_unlimited[und][3][value]', '', 'Entity 1: an empty widget was added for field_unlimited value 3.');
// 'Add more' button in the first entity (changing field values):
$edit = array(
'entity_2[field_unlimited][und][0][value]' => 13,
'entity_2[field_unlimited][und][1][value]' => 14,
'entity_2[field_unlimited][und][2][value]' => 15,
);
$this
->drupalPostAJAX(NULL, $edit, 'entity_2_field_unlimited_add_more');
$this
->assertFieldByName('entity_2[field_unlimited][und][0][value]', 13, 'Entity 2: field_unlimited value 0 appears correctly is the form.');
$this
->assertFieldByName('entity_2[field_unlimited][und][1][value]', 14, 'Entity 2: field_unlimited value 1 appears correctly is the form.');
$this
->assertFieldByName('entity_2[field_unlimited][und][2][value]', 15, 'Entity 2: field_unlimited value 2 appears correctly is the form.');
$this
->assertFieldByName('entity_2[field_unlimited][und][3][value]', '', 'Entity 2: an empty widget was added for field_unlimited value 3.');
// Save the form and check values are saved correclty.
$this
->drupalPost(NULL, array(), t('Save'));
field_cache_clear();
$this
->assertFieldValues($entity_1, 'field_unlimited', LANGUAGE_NONE, array(
3,
2,
));
$this
->assertFieldValues($entity_2, 'field_unlimited', LANGUAGE_NONE, array(
13,
14,
15,
));
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FieldTestCase:: |
function | Generate random values for a field_test field. | ||
FieldTestCase:: |
function | Assert that a field has the expected values in an entity. | ||
FieldTestCase:: |
property | |||
FieldFormTestCase:: |
function | Tests Field API form integration within a subform. | ||
FieldFormTestCase:: |
function | |||
FieldFormTestCase:: |
function | |||
FieldFormTestCase:: |
function | |||
FieldFormTestCase:: |
function | Tests widget handling of multiple required radios. | ||
FieldFormTestCase:: |
function | Tests widgets handling multiple values. | ||
FieldFormTestCase:: |
function | |||
FieldFormTestCase:: |
function | Tests fields with no 'edit' access. | ||
FieldFormTestCase:: |
function |
Set the default field storage backend for fields created during tests. Overrides FieldTestCase:: |
||
FieldFormTestCase:: |
public static | function | ||
DrupalWebTestCase:: |
function |
Constructor for DrupalWebTestCase. Overrides DrupalTestCase:: |
1 | |
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:: |
protected | function | Outputs to verbose the most recent $count emails sent. | |
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 | Reset all data structures after having enabled new modules. | |
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 | Prepares the current environment for running the test. | |
DrupalWebTestCase:: |
protected | function | Generates a database prefix for running tests. | |
DrupalWebTestCase:: |
protected | function | Preload the registry from the testing site. | |
DrupalWebTestCase:: |
protected | function | Parse content returned from curlExec using DOM and SimpleXML. | |
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 | Get the current URL from the cURL handler. | |
DrupalWebTestCase:: |
protected | function | Get the selected value from a select field. | |
DrupalWebTestCase:: |
protected | function | Get all option elements, including nested options, in a select. | |
DrupalWebTestCase:: |
protected | function | Takes a path and returns an absolute path. | |
DrupalWebTestCase:: |
protected | function | Sets the value of the Drupal.settings JavaScript variable for the currently loaded page. | |
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 | Execute an Ajax submission. | |
DrupalWebTestCase:: |
protected | function | Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser. | |
DrupalWebTestCase:: |
protected | function | ||
DrupalWebTestCase:: |
protected | function | Log in a user with the internal browser. | |
DrupalWebTestCase:: |
protected | function | Retrieves only the headers for a Drupal path or an absolute path. | |
DrupalWebTestCase:: |
protected | function | Generate a token for the currently logged in user. | |
DrupalWebTestCase:: |
protected | function | Get a list files that can be used in tests. | |
DrupalWebTestCase:: |
protected | function | Gets the value of the Drupal.settings JavaScript variable for the currently loaded page. | |
DrupalWebTestCase:: |
function | Get a node from the database based on its title. | ||
DrupalWebTestCase:: |
protected | function | Gets an array containing all e-mails sent during this test case. | |
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 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 current raw HTML of requested page. | |
DrupalWebTestCase:: |
protected | function | Retrieve a Drupal path or an absolute path and JSON decode the result. | |
DrupalWebTestCase:: |
protected | function | Retrieves a Drupal path or an absolute path. | |
DrupalWebTestCase:: |
protected | function | Create a user with a given set of permissions. | |
DrupalWebTestCase:: |
protected | function | Creates a role with specified permissions. | |
DrupalWebTestCase:: |
protected | function | Creates a node based on default settings. | |
DrupalWebTestCase:: |
protected | function | Creates a custom content type based on default settings. | |
DrupalWebTestCase:: |
protected | function | Compare two files based on size and file name. | |
DrupalWebTestCase:: |
protected | function | Initializes the cURL connection. | |
DrupalWebTestCase:: |
protected | function | Reads headers and registers errors received from the tested site. | |
DrupalWebTestCase:: |
protected | function | Initializes and executes a cURL request. | |
DrupalWebTestCase:: |
protected | function | Close the cURL handler and unset the handler. | |
DrupalWebTestCase:: |
protected | function | Runs cron in the Drupal installed by Simpletest. | |
DrupalWebTestCase:: |
protected | function | Helper function: construct an XPath for the given set of attributes and value. | |
DrupalWebTestCase:: |
protected | function | Follows a link by name. | |
DrupalWebTestCase:: |
protected | function | Check to make sure that the array of permissions are valid. | |
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 | Changes the database connection to the prefixed one. | |
DrupalWebTestCase:: |
protected | function | Builds an XPath query. | |
DrupalWebTestCase:: |
protected | function | Pass if the internal browser's URL matches the given path. | |
DrupalWebTestCase:: |
protected | function | Helper for assertUniqueText and assertNoUniqueText. | |
DrupalWebTestCase:: |
protected | function | Pass if the text is found ONLY ONCE on the text version of the page. | |
DrupalWebTestCase:: |
protected | function | Pass if the page title is the given string. | |
DrupalWebTestCase:: |
protected | function | Asserts themed output. | |
DrupalWebTestCase:: |
protected | function | Helper for assertText and assertNoText. | |
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 | Asserts the page responds with the specified response code. | |
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 | Will trigger a pass if the Perl regex pattern is found in the raw content. | |
DrupalWebTestCase:: |
protected | function | Asserts that a select option in the current page is checked. | |
DrupalWebTestCase:: |
protected | function | Pass if the text is found MORE THAN ONCE on the text version of the page. | |
DrupalWebTestCase:: |
protected | function | Pass if the page title is not the given string. | |
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 | Asserts the page did not return the specified response code. | |
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 | Will trigger a pass if the perl regex pattern is not present in raw content. | |
DrupalWebTestCase:: |
protected | function | Asserts that a select option in the current page is not checked. | |
DrupalWebTestCase:: |
protected | function | Pass if a link containing a given href (part) is not found. | |
DrupalWebTestCase:: |
protected | function | Pass if a link with the specified label is not found. | |
DrupalWebTestCase:: |
protected | function | Asserts that a checkbox field in the current page is not checked. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field doesn't exist or its value doesn't match, by XPath. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field does not exist with the given name and value. | |
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 or ID. | |
DrupalWebTestCase:: |
protected | function | Asserts that each HTML ID is used for just a single element. | |
DrupalWebTestCase:: |
protected | function | Asserts that the most recently sent e-mail message has the string in it. | |
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 given value. | |
DrupalWebTestCase:: |
protected | function | Pass if a link containing a given href (part) is found. | |
DrupalWebTestCase:: |
protected | function | Pass if a link with the specified label is found, and optional with the specified index. | |
DrupalWebTestCase:: |
protected | function | Asserts that a checkbox field in the current page is checked. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field exists in the current page by the given XPath. | |
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 with the given ID and value. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field exists with the given name or ID. | |
DrupalWebTestCase:: |
protected | property | The URL currently loaded in the internal browser. | |
DrupalWebTestCase:: |
protected | property | The current session name, if available. | |
DrupalWebTestCase:: |
protected | property | The current session ID, if available. | |
DrupalWebTestCase:: |
protected | property | The number of redirects followed during the handling of a request. | |
DrupalWebTestCase:: |
protected | property | The profile to install as a basis for testing. | 20 |
DrupalWebTestCase:: |
protected | property | The content of the page currently loaded in the internal browser (plain text version). | |
DrupalWebTestCase:: |
protected | property | The original user, before it was changed to a clean uid = 1 for testing purposes. | |
DrupalWebTestCase:: |
protected | property | The original shutdown handlers array, before it was cleaned for testing purposes. | |
DrupalWebTestCase:: |
protected | property | The current user logged in using the internal browser. | |
DrupalWebTestCase:: |
protected | property | HTTP authentication method | |
DrupalWebTestCase:: |
protected | property | HTTP authentication credentials (<username>:<password>). | |
DrupalWebTestCase:: |
protected | property | The headers of the page currently loaded in the internal browser. | |
DrupalWebTestCase:: |
protected | property | Whether the files were copied to the test files directory. | |
DrupalWebTestCase:: |
protected | property | The parsed version of the page. | |
DrupalWebTestCase:: |
protected | property | The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser. | |
DrupalWebTestCase:: |
protected | property | The handle of the current cURL connection. | |
DrupalWebTestCase:: |
protected | property | The cookies of the page currently loaded in the internal browser. | |
DrupalWebTestCase:: |
protected | property | The current cookie file used by cURL. | |
DrupalWebTestCase:: |
protected | property | The content of the page currently loaded in the internal browser. | |
DrupalWebTestCase:: |
protected | property | Additional cURL options. | |
DrupalTestCase:: |
protected | function | Logs a verbose message in a text file. | |
DrupalTestCase:: |
public | function | Run all tests in this class. | |
DrupalTestCase:: |
public static | function | Generates a random string of ASCII characters of codes 32 to 126. | |
DrupalTestCase:: |
public static | function | Generates a random string containing letters and numbers. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always positive. | |
DrupalTestCase:: |
public static | function | Store an assertion from outside the testing context. | |
DrupalTestCase:: |
public static | function | Returns the database connection to the site running Simpletest. | |
DrupalTestCase:: |
protected | function | Cycles through backtrace until the first non-assertion method is found. | |
DrupalTestCase:: |
public static | function | Converts a list of possible parameters into a stack of permutations. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always negative. | |
DrupalTestCase:: |
protected | function | Handle exceptions. | |
DrupalTestCase:: |
public | function | Handle errors during test runs. | 1 |
DrupalTestCase:: |
protected | function | Fire an error assertion. | 1 |
DrupalTestCase:: |
public static | function | Delete an assertion record by message ID. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not false (not an empty string, 0, NULL, or FALSE). | |
DrupalTestCase:: |
protected | function | Check to see if a value is NULL. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not NULL. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not identical. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not equal. | |
DrupalTestCase:: |
protected | function | Check to see if two values are identical. | |
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 equal. | |
DrupalTestCase:: |
protected | function | Internal helper: stores the assert. | |
DrupalTestCase:: |
protected | property | URL to the verbose output file directory. | |
DrupalTestCase:: |
protected | property | Time limit for the test. | |
DrupalTestCase:: |
protected | property | The test run ID. | |
DrupalTestCase:: |
protected | property | This class is skipped when looking for the source of an assertion. | |
DrupalTestCase:: |
protected | property | ||
DrupalTestCase:: |
protected | property | ||
DrupalTestCase:: |
protected | property | Flag to indicate whether the test has been set up. | |
DrupalTestCase:: |
public | property | Current results of this test case. | |
DrupalTestCase:: |
protected | property | The original file directory, before it was changed for testing purposes. | |
DrupalTestCase:: |
protected | property | The database prefix of this test run. | |
DrupalTestCase:: |
protected | property | Assertions thrown in that test case. |