You are here

public function PaymentStatusFormTest::testForm in Payment 8.2

Same name in this branch
  1. 8.2 tests/src/Unit/Entity/PaymentStatus/PaymentStatusFormTest.php \Drupal\Tests\payment\Unit\Entity\PaymentStatus\PaymentStatusFormTest::testForm()
  2. 8.2 tests/src/Unit/Entity/Payment/PaymentStatusFormTest.php \Drupal\Tests\payment\Unit\Entity\Payment\PaymentStatusFormTest::testForm()

@covers ::form @covers ::getPluginSelector

File

tests/src/Unit/Entity/Payment/PaymentStatusFormTest.php, line 166

Class

PaymentStatusFormTest
@coversDefaultClass \Drupal\payment\Entity\Payment\PaymentStatusForm

Namespace

Drupal\Tests\payment\Unit\Entity\Payment

Code

public function testForm() {
  $form = [];
  $form_state = new FormState();
  $settable_payment_status_ids = array(
    $this
      ->randomMachineName(),
  );
  $language = $this
    ->createMock(LanguageInterface::class);
  $payment_method = $this
    ->createMock(PaymentStatusFormUnitTestDummyPaymentMethodUpdateStatusInterface::class);
  $payment_method
    ->expects($this
    ->once())
    ->method('getSettablePaymentStatuses')
    ->with($this->currentUser)
    ->willReturn($settable_payment_status_ids);
  $this->payment
    ->expects($this
    ->atLeastOnce())
    ->method('getPaymentMethod')
    ->willReturn($payment_method);
  $this->payment
    ->expects($this
    ->any())
    ->method('language')
    ->willReturn($language);
  $entity_type = $this
    ->createMock(EntityTypeInterface::class);
  $this->payment
    ->expects($this
    ->any())
    ->method('getEntityType')
    ->willReturn($entity_type);
  $this->pluginSelectorManager
    ->expects($this
    ->once())
    ->method('createInstance')
    ->willReturn($this->pluginSelector);
  $plugin_selector_form = [
    'foo' => $this
      ->randomMachineName(),
  ];
  $form = [
    'langcode' => [],
  ];
  $form_state = new FormState();
  $this->sut
    ->setFormDisplay($this->formDisplay, $form_state);
  $this->pluginSelector
    ->expects($this
    ->atLeastOnce())
    ->method('buildSelectorForm')
    ->with([], $form_state)
    ->willReturn($plugin_selector_form);
  $payment_status_manager = $this
    ->prophesize(PaymentStatusManagerInterface::class);
  $this->paymentStatusPluginType
    ->getPluginManager()
    ->willReturn($payment_status_manager
    ->reveal());
  $build = $this->sut
    ->form($form, $form_state);
  $this
    ->assertIsArray($build);
  $this
    ->assertArrayHasKey('payment_status', $build);
  $this
    ->assertSame($plugin_selector_form, $build['payment_status']);

  // Build the form again to make sure the plugin selector is only created
  // once.
  $this->sut
    ->form($form, $form_state);
}