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()); }
/** * Initializes environment. This function can be called more than once with different storeId * * @param int $storeId * @return $this */ public function initEnvironment($storeId) { if ($this->getConfigData('environment', $storeId) == \Magento\Braintree\Model\Source\Environment::ENVIRONMENT_PRODUCTION) { $this->braintreeConfiguration->environment(\Magento\Braintree\Model\Source\Environment::ENVIRONMENT_PRODUCTION); } else { $this->braintreeConfiguration->environment(\Magento\Braintree\Model\Source\Environment::ENVIRONMENT_SANDBOX); } $this->braintreeConfiguration->merchantId($this->getConfigData(self::KEY_MERCHANT_ID, $storeId)); $this->braintreeConfiguration->publicKey($this->getConfigData(self::KEY_PUBLIC_KEY, $storeId)); $this->braintreeConfiguration->privateKey($this->getConfigData(self::KEY_PRIVATE_KEY, $storeId)); $this->merchantAccountId = $this->getConfigData(self::KEY_MERCHANT_ACCOUNT_ID, $storeId); $this->storeId = $storeId; //Need to set clientToken to null after initialization $this->clientToken = null; return $this; }