public function PaymentReferenceBaseTest::testBuildPaymentForm in Payment 8.2
@covers ::buildPaymentForm
File
- tests/
src/ Unit/ Element/ PaymentReferenceBaseTest.php, line 814
Class
- PaymentReferenceBaseTest
- @coversDefaultClass \Drupal\payment\Element\PaymentReferenceBase
Namespace
Drupal\Tests\payment\Unit\ElementCode
public function testBuildPaymentForm() {
$payment = $this
->createMock(PaymentInterface::class);
$payment
->expects($this
->atLeastOnce())
->method('createDuplicate')
->willReturnSelf();
$element = array(
'#parents' => array(
$this
->randomMachineName(),
),
'#prototype_payment' => $payment,
);
$form_state = new FormState();
$method = new \ReflectionMethod($this->sut, 'buildPaymentForm');
$method
->setAccessible(TRUE);
$payment = $this
->createMock(PaymentInterface::class);
$plugin_selector = $this
->createMock(PluginSelectorInterface::class);
$plugin_selector
->expects($this
->atLeastOnce())
->method('buildSelectorForm')
->with([], $form_state)
->willReturn([]);
$configuration = [];
$plugin_id = $this
->randomMachineName();
$entity_form_display = $this
->createMock(EntityFormDisplayInterface::class);
$entity_form_display
->expects($this
->once())
->method('buildForm')
->with($payment, $this
->isType('array'), $form_state);
$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(
'getEntityFormDisplay',
'getPluginSelector',
))
->getMockForAbstractClass();
$this->sut
->expects($this
->atLeastOnce())
->method('getEntityFormDisplay')
->willReturn($entity_form_display);
$this->sut
->expects($this
->atLeastOnce())
->method('getPluginSelector')
->with($element, $form_state)
->willReturn($plugin_selector);
$build = $method
->invoke($this->sut, $element, $form_state);
$this
->assertIsArray($build);
$this
->assertTrue(is_callable($build['pay_button']['#ajax']['callback']));
$this
->assertTrue(is_callable($build['pay_button']['#submit'][0]));
$this
->assertTrue(is_callable($build['pay_button']['#process'][0]));
$this
->assertTrue(is_callable($build['pay_link']['#process'][0]));
}