function NumberFieldTest::testMinimumValues

Same name in other branches
  1. 10 core/modules/field/tests/src/Functional/Number/NumberFieldTest.php \Drupal\Tests\field\Functional\Number\NumberFieldTest::testMinimumValues()

Tests setting minimum values through the interface.

File

core/modules/field/tests/src/Functional/Number/NumberFieldTest.php, line 395

Class

NumberFieldTest
Tests the creation of numeric fields.

Namespace

Drupal\Tests\field\Functional\Number

Code

public function testMinimumValues() : void {
    // Create a float field.
    $field_name = $this->randomMachineName();
    FieldStorageConfig::create([
        'field_name' => $field_name,
        'entity_type' => 'entity_test',
        'type' => 'float',
    ])->save();
    $field = FieldConfig::create([
        'field_name' => $field_name,
        'entity_type' => 'entity_test',
        'bundle' => 'entity_test',
    ]);
    $field->save();
    // Set the minimum value to a float value.
    $this->assertSetMinimumValue($field, 0.0001);
    // Set the minimum value to an integer value.
    $this->assertSetMinimumValue($field, 1);
    // Create a decimal field.
    $field_name = $this->randomMachineName();
    FieldStorageConfig::create([
        'field_name' => $field_name,
        'entity_type' => 'entity_test',
        'type' => 'decimal',
    ])->save();
    $field = FieldConfig::create([
        'field_name' => $field_name,
        'entity_type' => 'entity_test',
        'bundle' => 'entity_test',
    ]);
    $field->save();
    // Set the minimum value to a decimal value.
    $this->assertSetMinimumValue($field, 0.1);
    // Set the minimum value to an integer value.
    $this->assertSetMinimumValue($field, 1);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.