FixedRatesFormWebTest.php in Currency 8.3
File
tests/src/Functional/Form/FixedRatesFormWebTest.php
View source
<?php
namespace Drupal\Tests\currency\Functional\Form;
use Drupal\Tests\BrowserTestBase;
class FixedRatesFormWebTest extends BrowserTestBase {
public static $modules = array(
'currency',
);
protected $defaultTheme = 'stark';
function testForm() {
$plugin = \Drupal::service('plugin.manager.currency.exchange_rate_provider')
->createInstance('currency_fixed_rates');
$user = $this
->drupalCreateUser(array(
'currency.exchange_rate_provider.fixed_rates.administer',
));
$this
->drupalLogin($user);
$path = 'admin/config/regional/currency-exchange/fixed';
$this
->drupalGet($path);
$this
->assertText(t('Add an exchange rate'));
$config_importer = \Drupal::service('currency.config_importer');
$config_importer
->importCurrency('EUR');
$config_importer
->importCurrency('UAH');
$currency_code_from = 'EUR';
$currency_code_to = 'UAH';
$rate = '3';
$values = array(
'currency_code_from' => $currency_code_from,
'currency_code_to' => $currency_code_to,
'rate[amount]' => $rate,
);
$this
->drupalPostForm($path . '/add', $values, t('Save'));
$exchange_rate = $plugin
->load($currency_code_from, $currency_code_to);
$this
->assertIdentical($exchange_rate
->getRate(), $rate);
$this
->assertIdentical($exchange_rate
->getSourceCurrencyCode(), $currency_code_from);
$this
->assertIdentical($exchange_rate
->getDestinationCurrencyCode(), $currency_code_to);
$rate = '6';
$values = array(
'rate[amount]' => $rate,
);
$this
->drupalPostForm($path . '/' . $currency_code_from . '/' . $currency_code_to, $values, t('Save'));
$exchange_rate = $plugin
->load($currency_code_from, $currency_code_to);
$this
->assertIdentical($exchange_rate
->getRate(), $rate);
$this
->drupalPostForm($path . '/' . $currency_code_from . '/' . $currency_code_to, $values, t('Delete'));
$this
->assertNull($plugin
->load($currency_code_from, $currency_code_to));
}
}