You are here

function ABTWebTestCase::createFieldInstances in Access By Term 7

1 call to ABTWebTestCase::createFieldInstances()
ABTWebTestCase::setUpContentStructure in ./abt.test

File

./abt.test, line 99

Class

ABTWebTestCase

Code

function createFieldInstances($field, $content_type, $entity_types = array(
  'node',
  'user',
)) {
  $instances = $entity_types;
  for ($i = 0; $i < count($entity_types); $i++) {
    for ($j = 0; $j < count($field); $j++) {
      $instances[$entity_types[$i]][$j] = array(
        'field_name' => $field[$j]['field_name'],
        'entity_type' => $entity_types[$i],
        'bundle' => $entity_types[$i] == 'user' ? 'user' : $content_type->type,
        'label' => $field[$j]['field_name'] . '_fl_inst_label',
        'description' => $this
          ->randomName() . '_fl_inst_description',
        'weight' => mt_rand(0, 127),
        // test_field has no instance settings
        'widget' => array(
          'type' => 'test_field_widget',
          'settings' => array(
            'size' => mt_rand(0, 255),
          ),
        ),
      );
      field_create_instance($instances[$entity_types[$i]][$j]);
    }
  }
  return $instances;
}