public function CommerceExchangerTest::testCommerceExchangerCreation in Commerce Exchanger 8
Tests adding a exchange rate.
File
- tests/
src/ FunctionalJavascript/ CommerceExchangerTest.php, line 68
Class
- CommerceExchangerTest
- Tests the commerce exchanger UI.
Namespace
Drupal\Tests\commerce_exchanger\FunctionalJavascriptCode
public function testCommerceExchangerCreation() {
$this
->drupalGet('admin/commerce/config/exchange-rates');
$this
->getSession()
->getPage()
->clickLink('Add Exchange rates');
$this
->getSession()
->getPage()
->fillField('label', 'European Central Bank');
$this
->getSession()
->getPage()
->selectFieldOption('plugin', 'ecb');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->getSession()
->getPage()
->pressButton('Edit');
$this
->getSession()
->getPage()
->fillField('id', 'ecb');
$add = [
'label' => 'European Central Bank',
'id' => 'ecb_test',
'plugin' => 'ecb',
];
$this
->submitForm($add, 'Save');
$this
->assertSession()
->pageTextContains(t('Saved the @label exchange rates.', [
'@label' => 'European Central Bank',
]));
/** @var \Drupal\commerce_exchanger\Entity\ExchangeRatesInterface $exchange_rates */
$exchange_rates = ExchangeRates::load('ecb_test');
$this
->assertEquals('ecb', $exchange_rates
->getPluginId());
$this
->assertEquals('European Central Bank', $exchange_rates
->label());
$this
->assertEquals(ExchangeRatesInterface::COMMERCE_EXCHANGER_IMPORT . 'ecb_test', $exchange_rates
->getExchangerConfigName());
$rates = $this
->config($exchange_rates
->getExchangerConfigName())
->get('rates');
$this
->assertIsArray($rates);
$this
->assertIsArray($rates['USD']['HRK']);
$this
->assertEquals('0', $rates['USD']['HRK']['value']);
$this
->drupalGet('admin/commerce/config/exchange-rates');
$this
->getSession()
->getPage()
->clickLink('Run import');
$rates = $this
->config($exchange_rates
->getExchangerConfigName())
->get('rates');
$this
->assertIsArray($rates);
$this
->assertIsArray($rates['USD']['HRK']);
$this
->assertIsNotString($rates['USD']['HRK']['value']);
$this
->assertIsFloat($rates['USD']['HRK']['value']);
}