You are here

function ReadMoreControlTestCase::addNumberIntegerField in Read More Control 7

Adds a number_integer field and sets the default formatter options.

1 call to ReadMoreControlTestCase::addNumberIntegerField()
ReadMoreControlTestCase::testNodeEntities in ./readmorecontrol.test
Tests three node content types and fields.

File

./readmorecontrol.test, line 286
Tests for readmorecontrol.module.

Class

ReadMoreControlTestCase
Tests for number field types.

Code

function addNumberIntegerField($entity_type, $entity_bundle, $field_name = 'field_number', $display = 'number_unformatted') {

  // Create a field with settings to validate.
  $field = field_info_field($field_name);
  if (empty($field)) {
    $field = array(
      'field_name' => $field_name,
      'type' => 'number_integer',
      'settings' => array(),
    );
    field_create_field($field);
  }
  $instance = field_info_instance($entity_type, $field_name, $entity_bundle);
  if (!$instance) {
    $instance = array(
      'field_name' => $field_name,
      'entity_type' => $entity_type,
      'bundle' => $entity_bundle,
      'widget' => array(
        'type' => 'number',
      ),
      'display' => array(
        'default' => array(
          'type' => $display,
        ),
      ),
    );
    field_create_instance($instance);
  }
  else {

    // Updates the formatter if required.
    $this
      ->setNodeFieldDisplay($entity_type, $field_name, $display);
  }
}