public function FractionFieldTest::testFractionWidgetDecimalNegative in Fraction 8
Same name and namespace in other branches
- 2.x tests/src/Functional/FractionFieldTest.php \Drupal\Tests\fraction\Functional\FractionFieldTest::testFractionWidgetDecimalNegative()
Test decimal widget field with negative values.
File
- tests/
src/ Functional/ FractionFieldTest.php, line 163
Class
- FractionFieldTest
- Tests the creation of fraction fields.
Namespace
Drupal\Tests\fraction\FunctionalCode
public function testFractionWidgetDecimalNegative() {
// Create the test field.
$field_name = mb_strtolower($this
->randomMachineName());
FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'fraction',
])
->save();
FieldConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
])
->save();
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
$display_repository = \Drupal::service('entity_display.repository');
$display_repository
->getFormDisplay('entity_test', 'entity_test')
->setComponent($field_name, [
'type' => 'fraction_decimal',
])
->save();
$display_repository
->getViewDisplay('entity_test', 'entity_test')
->setComponent($field_name, [
'type' => 'fraction_decimal',
])
->save();
// Display creation form.
$this
->drupalGet('entity_test/add');
$this
->assertFieldByName("{$field_name}[0][decimal]", '', 'Widget is displayed');
// Submit negative decimal value.
$value = '-14.5678';
$edit = [
"{$field_name}[0][decimal]" => $value,
];
$this
->drupalPostForm(NULL, $edit, $this
->t('Save'));
preg_match('|entity_test/manage/(\\d+)|', $this
->getUrl(), $match);
$id = $match[1];
$this
->assertText($this
->t('entity_test @id has been created.', [
'@id' => $id,
]), 'Entity was created');
$this
->assertRaw($value, 'Value is displayed.');
}