Exemplo n.º 1
0
 /**
  * Executes the dispatch override
  */
 public function testDispatchNotLoggedIn()
 {
     $objectManager = new ObjectManagerHelper($this);
     $this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
     $this->resultRedirect->expects($this->any())->method('setPath')->willReturnSelf();
     $this->customerSession->expects($this->any())->method('authenticate')->willReturn(false);
     $this->config->expects($this->any())->method('useVault')->willReturn(true);
     /**
      * @var \Magento\Framework\App\RequestInterface $requestInterface
      */
     $requestInterface = $this->getMockBuilder('\\Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock();
     $notification = $objectManager->getObject('Magento\\Braintree\\Controller\\MyCreditCards', ['customerSession' => $this->customerSession, 'resultRedirectFactory' => $this->resultRedirectFactory, 'config' => $this->config, 'customerUrl' => $this->customerUrl, 'response' => $this->_response]);
     $this->assertSame($this->_response, $notification->dispatch($requestInterface));
 }
 /**
  * @dataProvider processBraintreePaymentSkipDataProvider
  */
 public function testProcessBraintreePaymentSkip($config)
 {
     $index = 0;
     foreach ($config as $key => $value) {
         $this->configMock->expects($this->at($index))->method('getConfigData')->with($key)->willReturn($value);
         $index++;
     }
     $paymentObj = new \Magento\Framework\DataObject(['method' => PaymentMethod::METHOD_CODE]);
     $orderMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $orderMock->expects($this->once())->method('getPayment')->willReturn($paymentObj);
     $orderMock->expects($this->once())->method('canInvoice')->willReturn(true);
     $observer = new \Magento\Framework\Event\Observer(['event' => new \Magento\Framework\DataObject(['shipment' => new \Magento\Framework\DataObject(['order' => $orderMock])])]);
     $this->transactionFactoryMock->expects($this->never())->method('create');
     $this->assertEquals($this->processBraintreePaymentObserver, $this->processBraintreePaymentObserver->execute($observer));
 }
Exemplo n.º 3
0
 /**
  * @param string $params
  * @dataProvider dataProcessNonce
  */
 public function testProcessNonceException($params = null, $exceptionMessage = null)
 {
     $this->customerSessionMock->expects($this->any())->method('getCustomerId')->willReturn($params['customerId']);
     $countryCollectionMock = $this->getMockBuilder('\\Magento\\Directory\\Model\\Resource\\Country\\Collection')->disableOriginalConstructor()->getMock();
     $countryCollectionMock->expects($this->any())->method('addCountryCodeFilter')->willReturn($countryCollectionMock);
     $this->countryFactoryMock->expects($this->any())->method('create')->willReturn($countryCollectionMock);
     $this->configMock->expects($this->any())->method('canUseForCountry')->willReturn($params['canUseForCountry']);
     $this->configMock->expects($this->any())->method('canUseCcTypeForCountry')->willReturn($params['canUseCcTypeForCountry']);
     $this->helperMock->expects($this->any())->method('generateCustomerId')->willReturn($params['customerId']);
     $this->customerMock->expects($this->any())->method('load')->willReturn($this->customerMock);
     $this->customerFactoryMock->expects($this->any())->method('create')->willReturn($this->customerMock);
     if (is_object($params['paymentMethodObj'])) {
         if (!$params['optionsArray']['update']) {
             $this->braintreePaymentMethodMock->expects($this->once())->method('create')->willReturn($params['paymentMethodObj']);
         } else {
             $this->braintreePaymentMethodMock->expects($this->once())->method('update')->willReturn($params['paymentMethodObj']);
         }
         if (!$params['paymentMethodObj']->success) {
             $this->errorHelperMock->expects($this->once())->method('parseBraintreeError')->willReturn(new \Magento\Framework\Phrase($exceptionMessage));
         } else {
             $this->errorHelperMock->expects($this->never())->method('parseBraintreeError');
         }
     }
     try {
         $this->model->processNonce($params['nonce'], $params['optionsArray'], $params['billingAddress']);
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->assertEquals($exceptionMessage, $e->getMessage());
     }
 }
 /**
  * @dataProvider getCustomerEmptyDataProvider
  */
 public function testGetCustomerEmpty($useVault, $isLoggedIn)
 {
     $this->configMock->expects($this->any())->method('useVault')->willReturn($useVault);
     $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn($isLoggedIn);
     $this->assertEquals('', $this->block->currentCustomerName());
     $this->assertEquals('', $this->block->currentCustomerLastName());
 }
 public function testGetConfigData()
 {
     $field = 'configFieldName';
     $storeId = '2';
     $configValue = 'configValue';
     $this->configMock->expects($this->once())->method('getConfigData')->with($field, $storeId)->willReturn($configValue);
     $this->assertEquals($configValue, $this->model->getConfigData($field, $storeId));
 }
 /**
  * @param bool $isActive
  * @param bool $isExistingCustomer
  * @param bool $deleteCustomer
  * @dataProvider deleteBraintreeCustomerDataProvider
  */
 public function testDeleteBraintreeCustomer($isActive, $isExistingCustomer, $deleteCustomer)
 {
     $braintreeCustoemrId = 'braintreeCustomerId';
     $customerId = '10002';
     $customerEmail = '*****@*****.**';
     $this->configMock->expects($this->once())->method('isActive')->willReturn($isActive);
     $customer = new \Magento\Framework\DataObject(['id' => $customerId, 'email' => $customerEmail]);
     $this->helperMock->expects($this->any())->method('generateCustomerId')->with($customerId, $customerEmail)->willReturn($braintreeCustoemrId);
     $observer = new \Magento\Framework\Event\Observer(['event' => new \Magento\Framework\DataObject(['customer' => $customer])]);
     $this->vaultMock->expects($this->any())->method('exists')->with($braintreeCustoemrId)->willReturn($isExistingCustomer);
     if ($deleteCustomer) {
         $this->vaultMock->expects($this->once())->method('deleteCustomer')->with($braintreeCustoemrId);
     } else {
         $this->vaultMock->expects($this->never())->method('deleteCustomer');
     }
     $this->assertEquals($this->deleteBraintreeCustomerObserver, $this->deleteBraintreeCustomerObserver->execute($observer));
 }
Exemplo n.º 7
0
 /**
  * @param array $data
  * @param array $expected
  * @dataProvider getCcAvailableCardTypesDataProvider
  */
 public function testGetCcAvailableCardTypes($data, $expected)
 {
     $this->braintreeCcConfig->expects($this->any())->method('getConfigData')->willReturn($data['cctypes']);
     $this->braintreeCcConfig->expects($this->any())->method('getCountrySpecificCardTypeConfig')->willReturn($data['cctypesCountrySpecific']);
     $this->braintreeCcConfig->expects($this->any())->method('getApplicableCardTypes')->willReturn($data['applicableCards']);
     $this->paymentConfig->expects($this->any())->method('getCcTypes')->willReturn($data['ccTypes']);
     $result = $this->model->getCcAvailableCardTypes($data['country']);
     $this->assertEquals($expected, $result);
 }
Exemplo n.º 8
0
 protected function setupAuthorizeRequest(array $configData, array $paymentInfo, array $expectedRequestAttributes, $paymentObject, $storeId, $amount)
 {
     //setup general payment and order information
     $transactionRequest = $this->setupPaymentObject($paymentObject, $storeId);
     //setup config options
     foreach ($configData as $methodName => $value) {
         $this->configMock->expects($this->any())->method($methodName)->willReturn($value);
     }
     //setup payment info instance
     $this->infoInstanceMock->expects($this->any())->method('getAdditionalInformation')->willReturnMap($paymentInfo);
     $this->model->setInfoInstance($this->infoInstanceMock);
     $expectedRequestAttribs = array_merge($transactionRequest, $expectedRequestAttributes);
     $expectedRequestAttribs['amount'] = $amount;
     return $expectedRequestAttribs;
 }
 /**
  * @dataProvider getConfigDataProvider
  */
 public function testGetConfig($configData, $vaultData, $tokenNonceMap, $expectedResult)
 {
     foreach ($configData as $key => $value) {
         $this->configMock->expects($this->any())->method($key)->willReturn($value);
     }
     foreach ($vaultData as $key => $value) {
         $this->vaultMock->expects($this->any())->method($key)->willReturn($value);
     }
     $this->vaultMock->expects($this->any())->method('generatePaymentMethodToken')->willReturnMap($tokenNonceMap);
     $cardTypeMap = [['Visa', 'VI'], ['Master Card', 'MA'], ['American Express', 'AE'], ['Discover Card', 'DI']];
     $this->helperMock->expects($this->any())->method('getCcTypeCodeByName')->willReturnMap($cardTypeMap);
     $this->helperMock->expects($this->once())->method('getTodayMonth')->willReturn(self::TODAY_MONTH);
     $this->helperMock->expects($this->once())->method('getTodayYear')->willReturn(self::TODAY_YEAR);
     $this->helperMock->expects($this->once())->method('getCcAvailableCardTypes')->willReturn($this->availableCardTypes);
     $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn(true);
     $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('braintree/creditcard/generate')->willReturn(self::PAYMENT_NONCE_GENERATION_URL);
     $this->assertEquals($expectedResult, $this->model->getConfig());
 }
Exemplo n.º 10
0
 /**
  * @dataProvider getConfigDataProvider
  */
 public function testGetConfig($configData, $vaultData, $tokenNonceMap, $expectedResult)
 {
     foreach ($configData as $key => $value) {
         $this->configMock->expects($this->any())->method($key)->willReturn($value);
     }
     foreach ($vaultData as $key => $value) {
         $this->vaultMock->expects($this->any())->method($key)->willReturn($value);
     }
     $this->vaultMock->expects($this->any())->method('generatePaymentMethodToken')->willReturnMap($tokenNonceMap);
     $quoteMock = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->getMock();
     $quoteMock->expects($this->once())->method('getBillingAddress')->willReturn(new \Magento\Framework\Object(['country_id' => 'US']));
     $this->checkoutSessionMock->expects($this->once())->method('getQuote')->willReturn($quoteMock);
     $cardTypeMap = [['Visa', 'VI'], ['Master Card', 'MA'], ['American Express', 'AE'], ['Discover Card', 'DI']];
     $this->helperMock->expects($this->any())->method('getCcTypeCodeByName')->willReturnMap($cardTypeMap);
     $this->helperMock->expects($this->once())->method('getTodayMonth')->willReturn(self::TODAY_MONTH);
     $this->helperMock->expects($this->once())->method('getTodayYear')->willReturn(self::TODAY_YEAR);
     $this->helperMock->expects($this->once())->method('getCcAvailableCardTypes')->willReturn($this->availableCardTypes);
     $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn(true);
     $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('braintree/creditcard/generate')->willReturn(self::PAYMENT_NONCE_GENERATION_URL);
     $this->assertEquals($expectedResult, $this->model->getConfig());
 }