You are here

public function PluginBasedExchangeRateProviderFormTest::testSubmitForm in Currency 8.3

Same name in this branch
  1. 8.3 tests/src/Unit/Controller/PluginBasedExchangeRateProviderFormTest.php \Drupal\Tests\currency\Unit\Controller\PluginBasedExchangeRateProviderFormTest::testSubmitForm()
  2. 8.3 tests/src/Unit/Form/PluginBasedExchangeRateProviderFormTest.php \Drupal\Tests\currency\Unit\Form\PluginBasedExchangeRateProviderFormTest::testSubmitForm()

@covers ::submitForm

File

tests/src/Unit/Form/PluginBasedExchangeRateProviderFormTest.php, line 162

Class

PluginBasedExchangeRateProviderFormTest
@coversDefaultClass \Drupal\currency\Form\PluginBasedExchangeRateProviderForm

Namespace

Drupal\Tests\currency\Unit\Form

Code

public function testSubmitForm() {
  $plugin_id_a = $this
    ->randomMachineName();
  $plugin_enabled_a = (bool) mt_rand(0, 1);
  $plugin_id_b = $this
    ->randomMachineName();
  $plugin_enabled_b = (bool) mt_rand(0, 1);
  $plugin_id_c = $this
    ->randomMachineName();
  $plugin_enabled_c = (bool) mt_rand(0, 1);
  $configuration = [
    $plugin_id_c => $plugin_enabled_c,
    $plugin_id_a => $plugin_enabled_a,
    $plugin_id_b => $plugin_enabled_b,
  ];
  $values = [
    'exchange_rate_providers' => [
      $plugin_id_c => [
        'enabled' => $plugin_enabled_c,
        'weight' => mt_rand(9, 99),
      ],
      $plugin_id_a => [
        'enabled' => $plugin_enabled_a,
        'weight' => mt_rand(999, 9999),
      ],
      $plugin_id_b => [
        'enabled' => $plugin_enabled_b,
        'weight' => mt_rand(99999, 999999),
      ],
    ],
  ];
  $form = [];
  $form_state = new FormState();
  $form_state
    ->setValues($values);
  $this->exchangeRateProvider
    ->expects($this
    ->once())
    ->method('saveConfiguration')
    ->with($configuration);
  $this->sut
    ->submitForm($form, $form_state);
}