You are here

public function PaymentFormTest::testForm in Payment 8.2

@covers ::form @covers ::getPluginSelector @covers ::getPaymentMethodManager

File

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

Class

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

Namespace

Drupal\Tests\payment_form\Unit\Entity\Payment

Code

public function testForm() {
  $plugin_selector_build = [
    '#type' => $this
      ->randomMachineName(),
  ];
  $this->pluginSelector
    ->expects($this
    ->atLeastOnce())
    ->method('buildSelectorForm')
    ->willReturn($plugin_selector_build);
  $this->pluginSelectorManager
    ->expects($this
    ->once())
    ->method('createInstance')
    ->with($this->configFactoryConfiguration['payment_form.payment_type']['plugin_selector_id'])
    ->willReturn($this->pluginSelector);
  $payment_type = $this
    ->createMock(PaymentTypeInterface::class);
  $this->payment
    ->expects($this
    ->any())
    ->method('getPaymentType')
    ->willReturn($payment_type);
  $entity_type = $this
    ->createMock(EntityTypeInterface::class);
  $this->payment
    ->expects($this
    ->any())
    ->method('getEntityType')
    ->willReturn($entity_type);
  $form = [
    'langcode' => [],
  ];
  $form_state = new FormState();
  $this->sut
    ->setFormDisplay($this->formDisplay, $form_state);
  $build = $this->sut
    ->form($form, $form_state);

  // Build the form a second time to make sure the plugin selector is only
  // instantiated once.
  $this->sut
    ->form($form, $form_state);
  $this
    ->assertIsArray($build);
  $this
    ->assertArrayHasKey('line_items', $build);
  $this
    ->assertSame($this->payment, $build['line_items']['#payment_line_items']);
  $this
    ->assertArrayHasKey('payment_method', $build);
  $this
    ->assertSame($plugin_selector_build, $build['payment_method']);
}