You are here

public function PaymentFormTest::testSubmitForm in Payment 8.2

@covers ::submitForm @covers ::getPluginSelector @covers ::getPaymentMethodManager

File

modules/payment_form/tests/src/Unit/Entity/Payment/PaymentFormTest.php, line 274

Class

PaymentFormTest
@coversDefaultClass \Drupal\payment_form\Entity\Payment\PaymentForm

Namespace

Drupal\Tests\payment_form\Unit\Entity\Payment

Code

public function testSubmitForm() {
  $symfony_response = $this
    ->prophesize(Response::class);
  $completion_response = $this
    ->prophesize(ResponseInterface::class);
  $completion_response
    ->getResponse()
    ->willReturn($symfony_response
    ->reveal());
  $result = $this
    ->createMock(OperationResultInterface::class);
  $result
    ->expects($this
    ->atLeastOnce())
    ->method('getCompletionResponse')
    ->willReturn($completion_response
    ->reveal());
  $form = [
    'payment_method' => [
      '#type' => $this
        ->randomMachineName(),
    ],
  ];
  $form_state = new FormState();
  $form_display = $this
    ->prophesize(EntityFormDisplayInterface::class);
  $form_display
    ->extractFormValues(Argument::any(), $form, $form_state);
  $form_state
    ->set('form_display', $form_display
    ->reveal());
  $entity_type = new EntityType([
    'id' => 'payment',
  ]);
  $this->payment
    ->expects($this
    ->any())
    ->method('getEntityType')
    ->willReturn($entity_type);
  $payment_method = $this
    ->createMock(PaymentMethodInterface::class);
  $this->pluginSelectorManager
    ->expects($this
    ->once())
    ->method('createInstance')
    ->with($this->configFactoryConfiguration['payment_form.payment_type']['plugin_selector_id'])
    ->willReturn($this->pluginSelector);
  $this->pluginSelector
    ->expects($this
    ->atLeastOnce())
    ->method('getSelectedPlugin')
    ->willReturn($payment_method);
  $this->pluginSelector
    ->expects($this
    ->atLeastOnce())
    ->method('submitSelectorForm')
    ->with($form['payment_method'], $form_state);
  $this->payment
    ->expects($this
    ->atLeastOnce())
    ->method('setPaymentMethod')
    ->with($payment_method);
  $this->payment
    ->expects($this
    ->atLeastOnce())
    ->method('save');
  $this->payment
    ->expects($this
    ->atLeastOnce())
    ->method('execute')
    ->willReturn($result);
  $this->sut
    ->submitForm($form, $form_state);
  $this
    ->assertSame($symfony_response
    ->reveal(), $form_state
    ->getResponse());
}