You are here

public function PaymentReferenceBaseTest::testProcess in Payment 8.2

@covers ::process

@depends testGetInfo

File

tests/src/Unit/Element/PaymentReferenceBaseTest.php, line 899

Class

PaymentReferenceBaseTest
@coversDefaultClass \Drupal\payment\Element\PaymentReferenceBase

Namespace

Drupal\Tests\payment\Unit\Element

Code

public function testProcess() {
  $name = $this
    ->randomMachineName();
  $prototype_payment = $this
    ->createMock(PaymentInterface::class);
  $plugin_selector_id = $this
    ->randomMachineName();
  $queue_category_id = $this
    ->randomMachineName();
  $queue_owner_id = mt_rand();
  $element = array(
    '#default_value' => NULL,
    '#limit_allowed_plugin_ids' => NULL,
    '#name' => $name,
    '#plugin_selector_id' => $plugin_selector_id,
    '#prototype_payment' => $prototype_payment,
    '#queue_category_id' => $queue_category_id,
    '#queue_owner_id' => $queue_owner_id,
  );
  $form_state = $this
    ->createMock(FormStateInterface::class);
  $form = [];
  $configuration = [];
  $plugin_id = $this
    ->randomMachineName();
  $payment_form = array(
    '#foo' => $this
      ->randomMachineName(),
  );
  $payment_view = array(
    '#foo' => $this
      ->randomMachineName(),
  );
  $refresh_button = array(
    '#foo' => $this
      ->randomMachineName(),
  );
  $this->sut = $this
    ->getMockBuilder(PaymentReferenceBase::class)
    ->setConstructorArgs(array(
    $configuration,
    $plugin_id,
    $this->pluginDefinition,
    $this->requestStack,
    $this->paymentStorage,
    $this->stringTranslation,
    $this->dateFormatter,
    $this->linkGenerator,
    $this->renderer,
    $this->currentUser,
    $this->pluginSelectorManager,
    $this->paymentMethodType,
    new Random(),
  ))
    ->setMethods(array(
    'buildPaymentForm',
    'buildPaymentView',
    'buildRefreshButton',
  ))
    ->getMockForAbstractClass();
  $this->sut
    ->expects($this
    ->atLeastOnce())
    ->method('buildPaymentForm')
    ->with($this
    ->isType('array'), $form_state)
    ->willReturn($payment_form);
  $this->sut
    ->expects($this
    ->atLeastOnce())
    ->method('buildPaymentView')
    ->with($this
    ->isType('array'), $form_state)
    ->willReturn($payment_view);
  $this->sut
    ->expects($this
    ->atLeastOnce())
    ->method('buildRefreshButton')
    ->with($this
    ->isType('array'), $form_state)
    ->willReturn($refresh_button);
  $this->sut
    ->expects($this
    ->atLeastOnce())
    ->method('getPaymentQueue')
    ->willReturn($this->paymentQueue);
  $build = $this->sut
    ->process($element, $form_state, $form);
  $this
    ->assertTrue(is_callable($build['#element_validate'][0]));
  $this
    ->assertTrue($build['#tree']);
  unset($build['container']['payment_form']['#access']);
  $this
    ->assertSame($payment_form, $build['container']['payment_form']);
  unset($build['container']['payment_view']['#access']);
  $this
    ->assertSame($payment_view, $build['container']['payment_view']);
}