function GenericFieldTest::formAddAllFields

Add all fields using Form API.

Parameters

mixed $node_type: A content type object. If none is specified, the test fails.

1 call to GenericFieldTest::formAddAllFields()
GenericFieldTest::formTestGenericFieldNodeAddDeleteForm in field_permission_example/tests/field_permission_example.test
Add and delete all field types through Form API.

File

field_permission_example/tests/field_permission_example.test, line 237

Class

GenericFieldTest
A generic field testing class.

Code

protected function formAddAllFields($node_type = NULL) {
    if (!$node_type) {
        $this->fail('No content type specified.');
    }
    // Get all our field types.
    $field_types = $this->getFieldTypes();
    // Keep a list of no_ui fields so we can tell the user.
    $unsafe_field_types = array();
    $field_names = array();
    $manage_path = 'admin/structure/types/manage/' . $node_type->name . '/fields';
    foreach ($field_types as $field_type) {
        // Get the field info.
        $field_info = field_info_field_types($field_type);
        // Exclude no_ui field types.
        if (isset($field_info['no_ui']) && $field_info['no_ui']) {
            $unsafe_field_types[] = $field_type;
        }
        else {
            // Generate a name for our field.
            // 26 is max length for field name.
            $field_name = drupal_strtolower($this->randomName(26));
            $field_names[$field_type] = $field_name;
            // Create the field through Form API.
            $this->formCreateField($manage_path, $field_type, $field_name, $field_info['default_widget'], 1);
        }
    }
    // Tell the user which fields we couldn't test.
    if (!empty($unsafe_field_types)) {
        debug('Unable to attach these no_ui fields: ' . implode(', ', $unsafe_field_types));
    }
    // Somehow clicking "save" isn't enough, and we have to
    // rebuild a few caches.
    node_types_rebuild();
    menu_rebuild();
    return $field_names;
}