function FieldExampleTest::createField

Utility function to create fields on a content type.

Parameters

string $field_name: Name of the field, like field_something

string $widget_type: Widget type, like field_example_3text

int $cardinality: Cardinality

1 call to FieldExampleTest::createField()
FieldExampleTest::testExampleFieldBasic in field_example/field_example.test
Test basic functionality of the example field.

File

field_example/field_example.test, line 155

Class

FieldExampleTest
Functional tests for the Field Example module.

Code

protected function createField($field_name, $widget_type, $cardinality) {
    // Add a singleton field_example_text field.
    $edit = array(
        'fields[_add_new_field][label]' => $field_name,
        'fields[_add_new_field][field_name]' => $field_name,
        'fields[_add_new_field][type]' => 'field_example_rgb',
        'fields[_add_new_field][widget_type]' => $widget_type,
    );
    $this->drupalPost(NULL, $edit, t('Save'));
    // There are no settings for this, so just press the button.
    $this->drupalPost(NULL, array(), t('Save field settings'));
    $edit = array(
        'field[cardinality]' => (string) $cardinality,
    );
    // Using all the default settings, so press the button.
    $this->drupalPost(NULL, $edit, t('Save settings'));
    debug(t('Saved settings for field %field_name with widget %widget_type and cardinality %cardinality', array(
        '%field_name' => $field_name,
        '%widget_type' => $widget_type,
        '%cardinality' => $cardinality,
    )));
    $this->assertText(t('Saved @name configuration.', array(
        '@name' => $field_name,
    )));
}