You are here

public function FixedRatesFormTest::testSubmitFormWitDelete in Currency 8.3

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

@covers ::submitForm

File

tests/src/Unit/Form/FixedRatesFormTest.php, line 302

Class

FixedRatesFormTest
@coversDefaultClass \Drupal\currency\Form\FixedRatesForm

Namespace

Drupal\Tests\currency\Unit\Form

Code

public function testSubmitFormWitDelete() {
  $currency_code_from = $this
    ->randomMachineName();
  $currency_code_to = $this
    ->randomMachineName();
  $values = [
    'currency_code_from' => $currency_code_from,
    'currency_code_to' => $currency_code_to,
  ];
  $form = [
    'actions' => [
      'save' => [
        '#name' => 'save',
        '#foo' => $this
          ->randomMachineName(),
      ],
      'delete' => [
        '#name' => 'delete',
        '#foo' => $this
          ->randomMachineName(),
      ],
    ],
  ];
  $form_state = $this
    ->createMock(FormStateInterface::class);
  $form_state
    ->expects($this
    ->atLeastOnce())
    ->method('getTriggeringElement')
    ->willReturn($form['actions']['delete']);
  $form_state
    ->expects($this
    ->atLeastOnce())
    ->method('getValues')
    ->willReturn($values);
  $form_state
    ->expects($this
    ->atLeastOnce())
    ->method('setRedirect')
    ->with('currency.exchange_rate_provider.fixed_rates.overview');
  $exchange_rate_provider = $this
    ->getMockBuilder(FixedRates::class)
    ->disableOriginalConstructor()
    ->getMock();
  $exchange_rate_provider
    ->expects($this
    ->once())
    ->method('delete')
    ->with($currency_code_from, $currency_code_to);
  $this->currencyExchangeRateProviderManager
    ->expects($this
    ->once())
    ->method('createInstance')
    ->with('currency_fixed_rates')
    ->willReturn($exchange_rate_provider);
  $currency_from = $this
    ->createMock(CurrencyInterface::class);
  $currency_to = $this
    ->createMock(CurrencyInterface::class);
  $map = [
    [
      $currency_code_from,
      $currency_from,
    ],
    [
      $currency_code_to,
      $currency_to,
    ],
  ];
  $this->currencyStorage
    ->expects($this
    ->atLeastOnce())
    ->method('load')
    ->willReturnMap($map);
  $this->sut
    ->submitForm($form, $form_state);
}