You are here

public function PriceElementTest::testMultipleCurrency in Commerce Core 8.2

Tests the element with multiple currencies.

File

modules/price/tests/src/Functional/PriceElementTest.php, line 58

Class

PriceElementTest
Tests the price element.

Namespace

Drupal\Tests\commerce_price\Functional

Code

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]');

  // Default value.
  $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());

  // CHF is not in #availabe_currencies so it must not be present.
  $this
    ->assertSession()
    ->optionNotExists('amount[currency_code]', 'CHF');

  // Invalid submit.
  $edit = [
    'amount[number]' => 'invalid',
    'amount[currency_code]' => 'USD',
  ];
  $this
    ->submitForm($edit, 'Submit');
  $this
    ->assertSession()
    ->pageTextContains('Amount must be a number.');

  // Valid submit.
  $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".');
}