You are here

function FixedRatesFormWebTest::testForm in Currency 8.3

Same name in this branch
  1. 8.3 tests/src/Functional/Controller/FixedRatesFormWebTest.php \Drupal\Tests\currency\Functional\Controller\FixedRatesFormWebTest::testForm()
  2. 8.3 tests/src/Functional/Form/FixedRatesFormWebTest.php \Drupal\Tests\currency\Functional\Form\FixedRatesFormWebTest::testForm()

Tests the form.

File

tests/src/Functional/Controller/FixedRatesFormWebTest.php, line 24

Class

FixedRatesFormWebTest
\Drupal\currency\Form\FixedRatesForm web test.

Namespace

Drupal\Tests\currency\Functional\Controller

Code

function testForm() {

  /** @var \Drupal\currency\Plugin\Currency\ExchangeRateProvider\ExchangeRateProviderInterface $plugin */
  $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';

  // Test the overview.
  $this
    ->drupalGet($path);
  $this
    ->assertText(t('Add an exchange rate'));

  // Set up the currencies.

  /** @var \Drupal\currency\ConfigImporterInterface $config_importer */
  $config_importer = \Drupal::service('currency.config_importer');
  $config_importer
    ->importCurrency('EUR');
  $config_importer
    ->importCurrency('UAH');
  $currency_code_from = 'EUR';
  $currency_code_to = 'UAH';

  // Test adding a exchange rate.
  $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);

  // Test editing a exchange rate.
  $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);

  // Test deleting a exchange rate.
  $this
    ->drupalPostForm($path . '/' . $currency_code_from . '/' . $currency_code_to, $values, t('Delete'));
  $this
    ->assertNull($plugin
    ->load($currency_code_from, $currency_code_to));
}