public function PaymentReferenceBaseTest::testBuildPaymentViewWithPayment in Payment 8.2
@covers ::buildPaymentView
@dataProvider providerTestBuildPaymentViewWithPayment
File
- tests/
src/ Unit/ Element/ PaymentReferenceBaseTest.php, line 715
Class
- PaymentReferenceBaseTest
- @coversDefaultClass \Drupal\payment\Element\PaymentReferenceBase
Namespace
Drupal\Tests\payment\Unit\ElementCode
public function testBuildPaymentViewWithPayment($view_access) {
$element = array(
'#default_value' => mt_rand(),
);
$form_state = $this
->createMock(FormStateInterface::class);
$currency = $this
->createMock(CurrencyInterface::class);
$payment_status = $this
->createMock(PaymentStatusInterface::class);
$payment_status
->expects($this
->atLeastOnce())
->method('getPluginDefinition')
->willReturn([
'label' => 'Example',
]);
$payment = $this
->createMock(PaymentInterface::class);
$payment
->expects($this
->atLeastOnce())
->method('access')
->willReturn($view_access);
$payment
->expects($this
->atLeastOnce())
->method('getCurrency')
->willReturn($currency);
$payment
->expects($this
->atLeastOnce())
->method('getPaymentStatus')
->willReturn($payment_status);
$urlObject = $this
->getMockBuilder(Url::class)
->disableOriginalConstructor()
->getMock();
$urlObject
->expects($view_access ? $this
->once() : $this
->never())
->method('toString');
$payment
->expects($view_access ? $this
->once() : $this
->never())
->method('toUrl')
->willReturn($urlObject);
$this->paymentStorage
->expects($this
->once())
->method('load')
->with($element['#default_value'])
->willReturn($payment);
$method = new \ReflectionMethod($this->sut, 'buildPaymentView');
$method
->setAccessible(TRUE);
$build = $method
->invoke($this->sut, $element, $form_state);
$this
->assertIsArray($build);
}