public function NumberElementTest::testInput in Commerce Core 8.2
Tests the element with valid and invalid input.
File
- modules/
price/ tests/ src/ Functional/ NumberElementTest.php, line 28
Class
- NumberElementTest
- Tests the number element.
Namespace
Drupal\Tests\commerce_price\FunctionalCode
public function testInput() {
$this
->drupalGet('/commerce_price_test/number_test_form');
$this
->assertSession()
->fieldExists('number');
// Default value.
$this
->assertSession()
->fieldValueEquals('number', '99.99');
// Not a number.
$edit = [
'number' => 'invalid',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('Amount must be a number.');
// Number too low.
$edit = [
'number' => '1',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('Amount must be higher than or equal to 2.');
// Number too high.
$edit = [
'number' => '101',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('Amount must be lower than or equal to 100.');
// Valid submit. Ensure that the value is trimmed.
$edit = [
'number' => '10.99 ',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('The number is "10.99".');
}