You are here

function NumberFieldTestCase::testNumberIntegerField in Drupal 7

Test number_integer field.

File

modules/field/modules/number/number.test, line 122
Tests for number.module.

Class

NumberFieldTestCase
Tests for number field types.

Code

function testNumberIntegerField() {

  // Display the "Add content type" form.
  $this
    ->drupalGet('admin/structure/types/add');

  // Add a content type.
  $name = $this
    ->randomName();
  $type = drupal_strtolower($name);
  $edit = array(
    'name' => $name,
    'type' => $type,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save and add fields'));

  // Add an integer field to the newly-created type.
  $label = $this
    ->randomName();
  $field_name = drupal_strtolower($label);
  $edit = array(
    'fields[_add_new_field][label]' => $label,
    'fields[_add_new_field][field_name]' => $field_name,
    'fields[_add_new_field][type]' => 'number_integer',
    'fields[_add_new_field][widget_type]' => 'number',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Set the formatter to "number_integer" and to "unformatted", and just
  // check that the settings summary does not generate warnings.
  $this
    ->drupalGet("admin/structure/types/manage/{$type}/display");
  $edit = array(
    "fields[field_{$field_name}][type]" => 'number_integer',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $edit = array(
    "fields[field_{$field_name}][type]" => 'number_unformatted',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
}