public function PriceElementTest::testSingleCurrency in Commerce Core 8.2
Tests the element with a single currency.
File
- modules/
price/ tests/ src/ Functional/ PriceElementTest.php, line 27
Class
- PriceElementTest
- Tests the price element.
Namespace
Drupal\Tests\commerce_price\FunctionalCode
public function testSingleCurrency() {
$this
->drupalGet('/commerce_price_test/price_test_form');
$this
->assertSession()
->fieldExists('amount[number]');
// Default value.
$this
->assertSession()
->fieldValueEquals('amount[number]', '99.99');
// Invalid submit.
$edit = [
'amount[number]' => 'invalid',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('Amount must be a number.');
// Valid submit.
$edit = [
'amount[number]' => '10.99',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('The number is "10.99" and the currency code is "USD".');
// Ensure that the form titles are displayed as expected.
$elements = $this
->xpath('//input[@id="edit-amount-hidden-title-number"]/preceding-sibling::label[@for="edit-amount-hidden-title-number" and contains(@class, "visually-hidden")]');
$this
->assertTrue(isset($elements[0]), 'Label preceding field and label class is visually-hidden.');
$elements = $this
->xpath('//input[@id="edit-amount-number"]/preceding-sibling::label[@for="edit-amount-number" and not(contains(@class, "visually-hidden"))]');
$this
->assertTrue(isset($elements[0]), 'Label preceding field and label class is not visually visually-hidden.');
}