diff --git a/core/modules/field/src/Tests/Number/NumberFieldTest.php b/core/modules/field/src/Tests/Number/NumberFieldTest.php index a82eafb..54fed49 100644 --- a/core/modules/field/src/Tests/Number/NumberFieldTest.php +++ b/core/modules/field/src/Tests/Number/NumberFieldTest.php @@ -464,11 +464,12 @@ function testNumberFormatter() { */ function testCreateNumberFloatField() { // Create a float field. + $field_type = 'float'; $field_name = Unicode::strtolower($this->randomMachineName()); entity_create('field_storage_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', - 'type' => 'float', + 'type' => $field_type, ))->save(); entity_create('field_config', array( @@ -477,28 +478,52 @@ function testCreateNumberFloatField() { 'bundle' => 'entity_test', ))->save(); - $field_configuration_url = 'entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name; + // Set the minimum value to an decimal value. + $this->setMinimumValue($field_type, $field_name, 0.1); + // Set the minimum value to an integer value. + $this->setMinimumValue($field_type, $field_name, 1); + } - // Set the minimum value to a decimal value. - $edit = array( - 'field[settings][min]' => 0.1, - ); - $this->drupalPostForm($field_configuration_url, $edit, t('Save settings')); - // Check if an error message is shown. - $this->assertNoRaw(t('%name is not a valid number.', array('%name' => t('Minimum'))), 'Saved decimal value as minimal value on a float field'); - // Check if the minimum value was actually set. - $this->drupalGet($field_configuration_url); - $this->assertFieldById('edit-field-settings-min', 0.1, 'Minimal decimal value was set on a float field.'); + /** + * Tests setting the minimum value of a decimal field through the interface. + */ + function testCreateNumberDecimalField() { + // Create a decimal field. + $field_type = 'decimal'; + $field_name = Unicode::strtolower($this->randomMachineName()); + entity_create('field_storage_config', array( + 'field_name' => $field_name, + 'entity_type' => 'entity_test', + 'type' => $field_type, + ))->save(); + + entity_create('field_config', array( + 'field_name' => $field_name, + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', + ))->save(); + // Set the minimum value to an decimal value. + $this->setMinimumValue($field_type, $field_name, 0.1); // Set the minimum value to an integer value. + $this->setMinimumValue($field_type, $field_name, 1); + } + + /** + * Helper function to set the minimum value of a field. + */ + function setMinimumValue($field_type, $field_name, $minimum_value) { + $field_configuration_url = 'entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name; + + // Set the minimum value. $edit = array( - 'field[settings][min]' => 1, + 'field[settings][min]' => $minimum_value, ); $this->drupalPostForm($field_configuration_url, $edit, t('Save settings')); // Check if an error message is shown. - $this->assertNoRaw(t('%name is not a valid number.', array('%name' => t('Minimum'))), 'Saved integer value as minimal value on a float field'); + $this->assertNoRaw(t('%name is not a valid number.', array('%name' => t('Minimum'))), 'Saved ' . gettype($minimum_value) .' value as minimal value on a ' . $field_type . ' field'); // Check if the minimum value was actually set. $this->drupalGet($field_configuration_url); - $this->assertFieldById('edit-field-settings-min', 1, 'Minimal integer value was set on a float field.'); + $this->assertFieldById('edit-field-settings-min', $minimum_value, 'Minimal ' . gettype($minimum_value) .' value was set on a ' . $field_type . ' field.'); } }