diff --git a/core/modules/field/lib/Drupal/field/Tests/Number/NumberFieldTest.php b/core/modules/field/lib/Drupal/field/Tests/Number/NumberFieldTest.php index 569ea05..6f429cf 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Number/NumberFieldTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/Number/NumberFieldTest.php @@ -161,6 +161,14 @@ function testNumberIntegerField() { 'type' => 'integer', ))->save(); + // Create unbounded field without limits. + $field_name_unlimited = drupal_strtolower($this->randomName()); + entity_create('field_config', array( + 'name' => $field_name_unlimited, + 'entity_type' => 'entity_test', + 'type' => 'integer', + ))->save(); + entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', @@ -170,6 +178,13 @@ function testNumberIntegerField() { ) ))->save(); + entity_create('field_instance_config', array( + 'field_name' => $field_name_unlimited, + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', + 'settings' => array() + ))->save(); + entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($field_name, array( 'type' => 'number', @@ -177,11 +192,20 @@ function testNumberIntegerField() { 'placeholder' => '4' ), )) + ->setComponent($field_name_unlimited, array( + 'type' => 'number', + 'settings' => array( + 'placeholder' => '4' + ), + )) ->save(); entity_get_display('entity_test', 'entity_test', 'default') ->setComponent($field_name, array( 'type' => 'number_integer', )) + ->setComponent($field_name_unlimited, array( + 'type' => 'number_integer', + )) ->save(); // Display creation form. @@ -251,11 +275,32 @@ function testNumberIntegerField() { $this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created'); $this->assertRaw($valid_entry, 'Value is displayed.'); } + + // Create a node and test that integer sizes are correctly validated. + // Integer too big. + $this->drupalGet('entity_test/add'); + $edit = array( + 'user_id' => 1, + 'name' => $this->randomName(), + "{$field_name_unlimited}[0][value]" => NUMBER_MAX_INT + 1, + ); + $this->drupalPostForm(NULL, $edit, t('Save')); + $this->assertText('the value may be no greater than', 'Found too big integer.'); + + // Integer too small. + $this->drupalGet('entity_test/add'); + $edit = array( + 'user_id' => 1, + 'name' => $this->randomName(), + "{$field_name_unlimited}[0][value]" => NUMBER_MIN_INT - 1, + ); + $this->drupalPostForm(NULL, $edit, t('Save')); + $this->assertText('the value may be no less than', 'Found too small integer.'); } /** - * Test float field. - */ + * Test float field. + */ function testNumberFloatField() { // Create a field with settings to validate. $field_name = drupal_strtolower($this->randomName());