/** * @param array $data * @param boolean|array $expected * @dataProvider getLoggedInCustomerCardsDataProvider */ public function testGetLoggedInCustomerCards($data, $expected) { $this->sessionQuote->expects($this->once())->method('getStoreId')->willReturn(1); $this->scopeConfig->expects($this->any())->method('getValue')->willReturn($data['vault']); if ($data['vault']) { $this->sessionQuote->expects($this->any())->method('getCustomerId')->willReturn(1); $this->paymentHelper->expects($this->any())->method('generateCustomerId')->willReturn(1); $this->paymentHelper->expects($this->any())->method('getCcAvailableCardTypes')->willReturn(['VI' => "VISA", 'MC' => "MasterCard"]); $this->paymentHelper->expects($this->any())->method('getCcTypeCodeByName')->willReturn(count($expected) ? 'VI' : false); $ccobj = json_decode(json_encode(['creditCards' => null])); $ccobj->creditCards[] = json_decode(json_encode(['cardType' => 'AE'])); $ccobj->creditCards[] = json_decode(json_encode(['cardType' => 'VI'])); $ccobj->creditCards[] = json_decode(json_encode(['cardType' => 'MC'])); $this->braintreeCustomerAdapter->expects($this->any())->method('find')->willReturn($ccobj); $billing = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote\\Address')->disableOriginalConstructor()->setMethods(['getCountryId'])->getMock(); $billing->expects($this->once())->method('getCountryId')->willReturn("US"); $quote = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['getBillingAddress'])->getMock(); $this->sessionQuote->expects($this->any())->method('getCustomerEmail')->willReturn("*****@*****.**"); $quote->expects($this->any())->method('getBillingAddress')->willReturn($billing); $this->sessionQuote->expects($this->any())->method('getQuote')->willReturn($quote); } $result = $this->model->getLoggedInCustomerCards(); $this->assertEquals($expected, $result); }
/** * @param array $creditCardsArray * @param boolean $useVault * @param stdClass $braintreeCustomerObject * @dataProvider dataProviderCurrentCustomerStoredCards */ public function testCurrentCustomerStoredCards($creditCardsArray = [], $useVault = false, $braintreeCustomerObject = null) { $customerId = 1; $this->configMock->expects($this->once())->method('useVault')->willReturn($useVault); $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn(true); $this->customerFactoryMock->expects($this->any())->method('create')->willReturn($this->customerMock); $this->helperMock->expects($this->any())->method('generateCustomerId')->willReturn($customerId); $this->customerMock->expects($this->any())->method('load')->willReturn($this->customerMock); if ($braintreeCustomerObject != null) { $this->braintreeCustomerMock->expects($this->any())->method('find')->with($customerId)->willReturn($braintreeCustomerObject); } else { $this->braintreeCustomerMock->expects($this->any())->method('find')->with($customerId)->willThrowException(new \Braintree_Exception()); } $result = $this->model->currentCustomerStoredCards(); $this->assertEquals($creditCardsArray, $result); }