function NumberFieldTest::testNumberIntegerField

Test number_integer field.

File

drupal/core/modules/field/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php, line 131
Definition of Drupal\number\NumberFieldTest.

Class

NumberFieldTest
Tests for number field types.

Namespace

Drupal\number\Tests

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 manage 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'));
}