PriceElementTest.php in Commerce Core 8.2
File
modules/price/tests/src/Functional/PriceElementTest.php
View source
<?php
namespace Drupal\Tests\commerce_price\Functional;
use Drupal\Tests\commerce\Functional\CommerceBrowserTestBase;
class PriceElementTest extends CommerceBrowserTestBase {
public static $modules = [
'commerce_price_test',
'language',
];
public function testSingleCurrency() {
$this
->drupalGet('/commerce_price_test/price_test_form');
$this
->assertSession()
->fieldExists('amount[number]');
$this
->assertSession()
->fieldValueEquals('amount[number]', '99.99');
$edit = [
'amount[number]' => 'invalid',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('Amount must be a number.');
$edit = [
'amount[number]' => '10.99',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('The number is "10.99" and the currency code is "USD".');
$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.');
}
public function testMultipleCurrency() {
$this->container
->get('commerce_price.currency_importer')
->import('EUR');
$this->container
->get('commerce_price.currency_importer')
->import('CHF');
$this
->drupalGet('/commerce_price_test/price_test_form');
$this
->assertSession()
->fieldExists('amount[number]');
$this
->assertSession()
->fieldExists('amount[currency_code]');
$this
->assertSession()
->fieldValueEquals('amount[number]', '99.99');
$this
->assertSession()
->optionExists('amount[currency_code]', 'EUR');
$element = $this
->assertSession()
->optionExists('amount[currency_code]', 'USD');
$this
->assertNotEmpty($element
->isSelected());
$this
->assertSession()
->optionNotExists('amount[currency_code]', 'CHF');
$edit = [
'amount[number]' => 'invalid',
'amount[currency_code]' => 'USD',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('Amount must be a number.');
$edit = [
'amount[number]' => '10.99',
'amount[currency_code]' => 'EUR',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('The number is "10.99" and the currency code is "EUR".');
}
}