17 use PHPUnit_Framework_MockObject_MockObject as MockObject;
22 class FormTest extends \PHPUnit\Framework\TestCase
25 'AE' =>
'American Express',
30 'CUP' =>
'China Union Pay',
35 'AE',
'VI',
'MC',
'DI',
'JBC' 46 private $sessionQuoteMock;
51 private $gatewayConfigMock;
61 private $paymentDataHelperMock;
66 private $storeId =
'1';
70 $this->initCcTypeMock();
71 $this->initSessionQuoteMock();
72 $this->initGatewayConfigMock();
74 $this->paymentDataHelperMock = $this->getMockBuilder(Data::class)
75 ->disableOriginalConstructor()
76 ->setMethods([
'getMethodInstance'])
80 $this->block = $managerHelper->getObject(Form::class, [
81 'paymentConfig' => $managerHelper->getObject(Config::class),
82 'sessionQuote' => $this->sessionQuoteMock,
83 'gatewayConfig' => $this->gatewayConfigMock,
84 'ccType' => $this->ccTypeMock,
85 'paymentDataHelper' =>$this->paymentDataHelperMock,
98 $this->sessionQuoteMock->expects(static::once())
99 ->method(
'getCountryId')
100 ->willReturn($countryId);
102 $this->gatewayConfigMock->expects(static::once())
103 ->method(
'getAvailableCardTypes')
104 ->with($this->storeId)
105 ->willReturn(self::$configCardTypes);
107 $this->gatewayConfigMock->expects(static::once())
108 ->method(
'getCountryAvailableCardTypes')
109 ->with($countryId, $this->storeId)
110 ->willReturn($availableTypes);
112 $result = $this->block->getCcAvailableTypes();
113 static::assertEquals($expected, array_values(
$result));
123 [
'US', [
'AE',
'VI'], [
'American Express',
'Visa']],
124 [
'UK', [
'VI'], [
'Visa']],
125 [
'CA', [
'MC'], [
'MasterCard']],
126 [
'UA', [], [
'American Express',
'Visa',
'MasterCard',
'Discover',
'JBC']],
135 $vaultPayment = $this->getMockForAbstractClass(VaultPaymentInterface::class);
136 $this->paymentDataHelperMock->expects(static::once())
137 ->method(
'getMethodInstance')
139 ->willReturn($vaultPayment);
141 $vaultPayment->expects(static::once())
143 ->with($this->storeId)
146 static::assertTrue($this->block->isVaultEnabled());
152 private function initCcTypeMock()
154 $this->ccTypeMock = $this->getMockBuilder(CcType::class)
155 ->disableOriginalConstructor()
156 ->setMethods([
'getCcTypeLabelMap'])
159 $this->ccTypeMock->expects(static::any())
160 ->method(
'getCcTypeLabelMap')
161 ->willReturn(self::$baseCardTypes);
167 private function initSessionQuoteMock()
169 $this->sessionQuoteMock = $this->getMockBuilder(Quote::class)
170 ->disableOriginalConstructor()
171 ->setMethods([
'getQuote',
'getBillingAddress',
'getCountryId',
'__wakeup',
'getStoreId'])
174 $this->sessionQuoteMock->expects(static::any())
177 $this->sessionQuoteMock->expects(static::any())
178 ->method(
'getBillingAddress')
180 $this->sessionQuoteMock->expects(static::any())
181 ->method(
'getStoreId')
182 ->willReturn($this->storeId);
188 private function initGatewayConfigMock()
190 $this->gatewayConfigMock = $this->getMockBuilder(GatewayConfig::class)
191 ->disableOriginalConstructor()
192 ->setMethods([
'getCountryAvailableCardTypes',
'getAvailableCardTypes'])