You are here

public function CurrencyImportFormTest::testSubmitFormImportEdit in Currency 8.3

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

@covers ::submitForm

File

tests/src/Unit/Controller/CurrencyImportFormTest.php, line 181

Class

CurrencyImportFormTest
@coversDefaultClass \Drupal\currency\Form\CurrencyImportForm

Namespace

Drupal\Tests\currency\Unit\Controller

Code

public function testSubmitFormImportEdit() {
  $currency_code = $this
    ->randomMachineName();
  $url = new Url($this
    ->randomMachineName());
  $currency = $this
    ->createMock(CurrencyInterface::class);
  $currency
    ->expects($this
    ->atLeastOnce())
    ->method('toUrl')
    ->with('edit-form')
    ->willReturn($url);
  $this->configImporter
    ->expects($this
    ->once())
    ->method('importCurrency')
    ->with($currency_code)
    ->willReturn($currency);
  $form = [
    'actions' => [
      'import' => [
        '#name' => 'import',
      ],
      'import_edit' => [
        '#name' => 'import_edit',
      ],
    ],
  ];
  $form_state = $this
    ->createMock(FormStateInterface::class);
  $form_state
    ->expects($this
    ->atLeastOnce())
    ->method('getValues')
    ->willReturn([
    'currency_code' => $currency_code,
  ]);
  $form_state
    ->expects($this
    ->atLeastOnce())
    ->method('getTriggeringElement')
    ->willReturn($form['actions']['import_edit']);
  $form_state
    ->expects($this
    ->atLeastOnce())
    ->method('setRedirectUrl');
  $this->sut
    ->submitForm($form, $form_state);
}