/**
  * @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));
 }
Esempio n. 2
0
 public function testInitEnvironment()
 {
     $prefix = 'payment/braintree/';
     $storeId = 2;
     $environment2 = \Magento\Braintree\Model\Source\Environment::ENVIRONMENT_SANDBOX;
     $merchantId2 = 'merchantId_2';
     $publicKey2 = 'public_key_2';
     $privateKey2 = 'private_key_2';
     $merchantAccountId2 = 'merchantAccountId_2';
     $clientToken2 = 'clientToken_2';
     $this->scopeConfigMock->expects($this->at(0))->method('getValue')->with($prefix . Config::KEY_ACTIVE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null)->willReturn(1);
     //for the initEnvironment call
     $this->scopeConfigMock->expects($this->at(6))->method('getValue')->with($prefix . Config::KEY_ENVIRONMENT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)->willReturn($environment2);
     $this->scopeConfigMock->expects($this->at(7))->method('getValue')->with($prefix . Config::KEY_MERCHANT_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)->willReturn($merchantId2);
     $this->scopeConfigMock->expects($this->at(8))->method('getValue')->with($prefix . Config::KEY_PUBLIC_KEY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)->willReturn($publicKey2);
     $this->scopeConfigMock->expects($this->at(9))->method('getValue')->with($prefix . Config::KEY_PRIVATE_KEY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)->willReturn($privateKey2);
     $this->scopeConfigMock->expects($this->at(10))->method('getValue')->with($prefix . Config::KEY_MERCHANT_ACCOUNT_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)->willReturn($merchantAccountId2);
     //for the initEnvironment call
     $this->braintreeConfigurationMock->expects($this->at(4))->method('environment')->with($environment2);
     $this->braintreeConfigurationMock->expects($this->at(5))->method('merchantId')->with($merchantId2);
     $this->braintreeConfigurationMock->expects($this->at(6))->method('publicKey')->with($publicKey2);
     $this->braintreeConfigurationMock->expects($this->at(7))->method('privateKey')->with($privateKey2);
     $this->model = new Config($this->scopeConfigMock, $this->braintreeConfigurationMock, $this->braintreeClientTokenMock, $this->sourceCountryMock);
     $this->model->initEnvironment($storeId);
     $this->assertEquals($merchantAccountId2, $this->model->getMerchantAccountId());
     $this->braintreeClientTokenMock->expects($this->once())->method('generate')->willReturn($clientToken2);
     $this->assertEquals($clientToken2, $this->model->getClientToken());
     //second call will return cached version
     $this->assertEquals($clientToken2, $this->model->getClientToken());
 }
 public function testDelete()
 {
     $scope = 'website';
     $scopeId = 1;
     $backendModel = $this->getMockBuilder('Magento\\Framework\\App\\Config\\Value')->disableOriginalConstructor()->getMock();
     $this->designConfig->expects($this->once())->method('getExtensionAttributes')->willReturn($this->designConfigExtension);
     $this->designConfigExtension->expects($this->once())->method('getDesignConfigData')->willReturn([$this->designConfigData]);
     $this->transactionFactoryMock->expects($this->once())->method('create')->willReturn($this->transactionMock);
     $this->designConfigData->expects($this->once())->method('getValue')->willReturn('value');
     $this->designConfigData->expects($this->once())->method('getFieldConfig')->willReturn([]);
     $this->designConfig->expects($this->once())->method('getScope')->willReturn($scope);
     $this->designConfig->expects($this->once())->method('getScopeId')->willReturn($scopeId);
     $this->backendModelFactoryMock->expects($this->once())->method('create')->with(['value' => 'value', 'scope' => $scope, 'scopeId' => $scopeId, 'config' => []])->willReturn($backendModel);
     $this->transactionMock->expects($this->once())->method('addObject')->with($backendModel);
     $this->transactionMock->expects($this->once())->method('delete');
     $this->model->delete($this->designConfig);
 }