You are here

public function CommerceExchangerTest::testCommerceExchangerEditing in Commerce Exchanger 8

Tests editing a exchange rate.

File

tests/src/FunctionalJavascript/CommerceExchangerTest.php, line 126

Class

CommerceExchangerTest
Tests the commerce exchanger UI.

Namespace

Drupal\Tests\commerce_exchanger\FunctionalJavascript

Code

public function testCommerceExchangerEditing() {
  $exchange_rates = $this
    ->createEntity('commerce_exchange_rates', [
    'label' => 'ECB',
    'id' => 'ecb',
    'plugin' => 'ecb',
    'status' => TRUE,
  ]);

  // There is no rates upon creation.
  $this
    ->expectException(ExchangeRatesDataMismatchException::class);
  $this->container
    ->get('commerce_exchanger.calculate')
    ->priceConversion($this->priceHrk, 'USD');

  // Import rates.
  $this
    ->drupalGet('admin/commerce/config/exchange-rates');
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Run import');
  $price_test = $this->container
    ->get('commerce_exchanger.calculate')
    ->priceConversion($this->priceHrk, 'USD');
  $this
    ->assertNotEqual($price_test
    ->getNumber(), '100.00');
  $this
    ->drupalGet('admin/commerce/config/exchange-rates/' . $exchange_rates
    ->id() . '/edit');
  $edit = [
    'label' => 'ECB edited',
    'plugin' => 'fixer',
    'configuration[ecb][enterprise]' => 1,
    'status' => 0,
  ];
  $this
    ->submitForm($edit, 'Save');
  $exchange_rates = ExchangeRates::load('ecb');
  $this
    ->assertEqual($edit['label'], $exchange_rates
    ->label());
  $this
    ->assertNotEqual($edit['plugin'], $exchange_rates
    ->getPluginId());
  $this
    ->assertEqual($edit['status'], $exchange_rates
    ->status());
  $this
    ->assertNotEqual($edit['configuration[ecb][enterprise]'], $exchange_rates
    ->getPluginConfiguration()['enterprise']);
}