You are here

protected function SelectOrOtherTestBase::prepareTestFields in Select (or other) 7.3

Generate content types and fields for testing.

Parameters

string $field_type: The type of field to create.

array $widgets: The types of widgets to use.

array $widget_settings: The widget settings.

$field_formatter: Machine name of the field formatter to use for display.

Throws

\Exception

\FieldException

3 calls to SelectOrOtherTestBase::prepareTestFields()
SelectOrOtherNumberTestCase::setUp in tests/select_or_other_number.test
Sets up a Drupal site for running functional and integration tests.
SelectOrOtherTaxonomyTestCase::prepareTestFields in modules/select_or_other_taxonomy/tests/select_or_other_taxonomy.test
Generate content types and fields for testing.
SelectOrOtherTextTestCase::setUp in tests/select_or_other_text.test
Sets up a Drupal site for running functional and integration tests.
1 method overrides SelectOrOtherTestBase::prepareTestFields()
SelectOrOtherTaxonomyTestCase::prepareTestFields in modules/select_or_other_taxonomy/tests/select_or_other_taxonomy.test
Generate content types and fields for testing.

File

tests/SelectOrOtherTestBase.test, line 147
Contains SelectOrOtherTestBase.

Class

SelectOrOtherTestBase
Class SelectOrOtherTestBase Base class for select_or_other testing.

Code

protected function prepareTestFields($field_type, $field_settings, $widgets, $widget_settings, $field_formatter) {

  // Configure fields.
  foreach ($widgets as $widget) {
    foreach (array(
      1,
      -1,
    ) as $cardinality) {
      foreach (array(
        TRUE,
        FALSE,
      ) as $required) {
        $content_type = $this
          ->drupalCreateContentType();
        $field_info = array(
          'content_type' => $content_type,
          'widget' => $widget,
          'cardinality' => $cardinality,
        );

        // Create the field.
        $field = array(
          'type' => $field_type,
          'field_name' => strtolower($this
            ->randomName()),
          'cardinality' => $cardinality,
          'settings' => $field_settings,
        );
        field_create_field($field);
        $field_info['field_settings'] = $field;
        $instance_settings = array(
          'entity_type' => 'node',
          'required' => $required,
          'bundle' => $field_info['content_type']->name,
          'field_name' => $field['field_name'],
          'widget' => array(
            'type' => $widget,
            'settings' => $widget_settings,
          ),
          'display' => array(
            'full' => array(
              'type' => $field_formatter,
            ),
          ),
        );
        $field_info['instance_settings'] = field_create_instance($instance_settings);
        $this->fields[$field['field_name']] = $field_info;
      }
    }
  }

  // Determine required permissions.
  $this->defaultPermissions = array(
    'bypass node access',
  );
}