public function PaymentReferenceBaseTest::testBuildCompletePaymentLinkWithPaymentMethod in Payment 8.2
@covers ::buildCompletePaymentLink
File
- tests/
src/ Unit/ Element/ PaymentReferenceBaseTest.php, line 625
Class
- PaymentReferenceBaseTest
- @coversDefaultClass \Drupal\payment\Element\PaymentReferenceBase
Namespace
Drupal\Tests\payment\Unit\ElementCode
public function testBuildCompletePaymentLinkWithPaymentMethod() {
$configuration = [];
$plugin_id = $this
->randomMachineName();
$this->pluginDefinition = [];
$element = array(
'#foo' => $this
->randomMachineName(),
);
$form_state = $this
->createMock(FormStateInterface::class);
$payment = $this
->createMock(PaymentInterface::class);
$payment_method = $this
->createMock(PaymentMethodInterface::class);
$payment_method
->expects($this
->atLeastOnce())
->method('getPayment')
->willReturn($payment);
$payment_method
->expects($this
->atLeastOnce())
->method('getPluginDefinition')
->willReturn([
'label' => 'Example',
]);
$plugin_selector = $this
->createMock(PluginSelectorInterface::class);
$plugin_selector
->expects($this
->atLeastOnce())
->method('getSelectedPlugin')
->willReturn($payment_method);
$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(
'getPluginSelector',
))
->getMockForAbstractClass();
$this->sut
->expects($this
->atLeastOnce())
->method('getPluginSelector')
->with($element, $form_state)
->willReturn($plugin_selector);
$method = new \ReflectionMethod($this->sut, 'buildCompletePaymentLink');
$method
->setAccessible(TRUE);
$build = $method
->invoke($this->sut, $element, $form_state);
$this
->assertIsArray($build);
$this
->assertSame('link', $build['link']['#type']);
}