You are here

function TMGMTFieldCollectionSourceTestCase::createFieldCollectionInstance in Translation Management Tool 7

Creates a node and field collection entity pair.

1 call to TMGMTFieldCollectionSourceTestCase::createFieldCollectionInstance()
TMGMTFieldCollectionSourceTestCase::setUp in sources/field/tmgmt_field_collection.test
Overrides DrupalWebTestCase::setUp()

File

sources/field/tmgmt_field_collection.test, line 29

Class

TMGMTFieldCollectionSourceTestCase
Basic Field Collection Source tests.

Code

function createFieldCollectionInstance() {
  $this->field_name = 'field_test_collection';
  $node_field = array(
    'field_name' => $this->field_name,
    'type' => 'field_collection',
    'cardinality' => 4,
    'translatable' => TRUE,
  );
  field_create_field($node_field);
  $node_field_instance = array(
    'field_name' => $this->field_name,
    'entity_type' => 'node',
    'bundle' => 'page',
    'label' => $this
      ->randomName() . '_label',
    'description' => $this
      ->randomName() . '_description',
    'weight' => mt_rand(0, 127),
    'settings' => array(),
    'widget' => array(
      'type' => 'hidden',
      'label' => 'Test',
      'settings' => array(),
    ),
  );
  field_create_instance($node_field_instance);

  // Add a field to the collection.
  $field_collection_field = array(
    'field_name' => 'field_text',
    'type' => 'text',
    'cardinality' => 1,
    'translatable' => TRUE,
  );
  field_create_field($field_collection_field);
  $field_collection_field_instance = array(
    'entity_type' => 'field_collection_item',
    'field_name' => 'field_text',
    'bundle' => $this->field_name,
    'label' => 'Test text field',
    'widget' => array(
      'type' => 'text_textfield',
    ),
  );
  field_create_instance($field_collection_field_instance);
}