You are here

function MediaFileFieldTestCase::attachFileField in D7 Media 7.2

Same name and namespace in other branches
  1. 7.4 tests/media.test \MediaFileFieldTestCase::attachFileField()
  2. 7.3 tests/media.test \MediaFileFieldTestCase::attachFileField()

Attaches a file field to an entity.

Parameters

$name: The name of the new field (all lowercase), exclude the "field_" prefix.

$entity_type: The entity type this field will be added to.

$bundle: The bundle this field will be added to.

$field_settings: A list of field settings that will be added to the defaults.

$instance_settings: A list of instance settings that will be added to the instance defaults.

$widget_settings: A list of widget settings that will be added to the widget defaults.

2 calls to MediaFileFieldTestCase::attachFileField()
MediaFileFieldRevisionTestCase::testRevisions in tests/media.test
Tests creating multiple revisions of a node and managing attached files.
MediaFileFieldTestCase::createFileField in tests/media.test
Creates a new file field.

File

tests/media.test, line 142
Tests for media.module.

Class

MediaFileFieldTestCase
Provides methods specifically for testing Media module's field handling.

Code

function attachFileField($name, $entity_type, $bundle, $instance_settings = array(), $widget_settings = array()) {
  $instance = array(
    'field_name' => $name,
    'label' => $name,
    'entity_type' => $entity_type,
    'bundle' => $bundle,
    'required' => !empty($instance_settings['required']),
    'settings' => array(),
    'widget' => array(
      'type' => 'media_generic',
      'settings' => array(),
    ),
  );
  $instance['settings'] = array_merge($instance['settings'], $instance_settings);
  $instance['widget']['settings'] = array_merge($instance['widget']['settings'], $widget_settings);
  field_create_instance($instance);
}