You are here

final protected function FeedsMapperTestCase::createContentType in Feeds 6

Same name and namespace in other branches
  1. 7.2 tests/feeds_mapper.test \FeedsMapperTestCase::createContentType()
  2. 7 tests/feeds_mapper_test.inc \FeedsMapperTestCase::createContentType()

Create a new content-type, and add a field to it. Mostly copied from cck/tests/content.crud.test ContentUICrud::testAddFieldUI

Parameters

$settings: (Optional) An array of settings to pass through to drupalCreateContentType().

$fields: (Optional) an keyed array of $field_name => $field_type used to add additional fields to the new content type.

Return value

The machine name of the new content type.

See also

DrupalWebTestCase::drupalCreateContentType()

8 calls to FeedsMapperTestCase::createContentType()
FeedsMapperContentTaxonomyTestCase::test in tests/feeds_mapper_content_taxonomy.test
Basic test loading a single entry CSV file.
FeedsMapperContentTestCase::test in tests/feeds_mapper_content.test
Basic test loading a doulbe entry CSV file.
FeedsMapperDateTestCase::test in tests/feeds_mapper_date.test
Basic test loading a single entry CSV file.
FeedsMapperEmailTestCase::test in tests/feeds_mapper_email.test
Basic test loading a doulbe entry CSV file.
FeedsMapperEmfieldTestCase::test in tests/feeds_mapper_emfield.test
Basic test loading a doulbe entry CSV file.

... See full list

File

tests/feeds_mapper.test, line 103
Helper class with auxiliary functions for feeds mapper module tests.

Class

FeedsMapperTestCase
Base class for implementing Feeds Mapper test cases.

Code

protected final function createContentType(array $settings = array(), array $fields = array()) {
  $type = $this
    ->drupalCreateContentType($settings);
  $typename = $type->type;
  $admin_type_url = 'admin/content/node-type/' . str_replace('_', '-', $typename);

  // Create the fields
  foreach ($fields as $field_name => $options) {
    if (is_string($options)) {
      $options = array(
        'type' => $options,
      );
    }
    $field_type = isset($options['type']) ? $options['type'] : 'text';
    $field_widget = isset($options['widget']) ? $options['widget'] : $this
      ->selectFieldWidget($field_name, $field_type);
    $this
      ->assertTrue($field_widget !== NULL, "Field type {$field_type} supported");
    $label = $field_name . '_' . $field_type . '_label';
    $edit = array(
      '_add_new_field[label]' => $label,
      '_add_new_field[field_name]' => $field_name,
      '_add_new_field[type]' => $field_type,
      '_add_new_field[widget_type]' => $field_widget,
    );
    $this
      ->drupalPost($admin_type_url . '/fields', $edit, 'Save');

    // (Default) Configure the field.
    $edit = isset($options['settings']) ? $options['settings'] : array();
    $this
      ->drupalPost(NULL, $edit, 'Save field settings');
    $this
      ->assertText('Added field ' . $label);
  }
  return $typename;
}