123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Paypal\Test\Unit\Model;
- use Magento\Framework\App\Config\ScopeConfigInterface;
- use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
- use Magento\Paypal\Model\PayflowConfig;
- use Magento\Payment\Model\MethodInterface;
- use Magento\Payment\Model\Method\AbstractMethod;
- use Magento\Paypal\Model\Config;
- use Magento\Store\Model\ScopeInterface;
- /**
- * Class PayflowConfigTest
- */
- class PayflowConfigTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $scopeConfigMock;
- /**
- * @var MethodInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $methodInterfaceMock;
- /**
- * @var PayflowConfig|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $config;
- protected function setUp()
- {
- $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
- ->setMethods(['getValue', 'isSetFlag'])
- ->getMockForAbstractClass();
- $this->methodInterfaceMock = $this->getMockBuilder(\Magento\Payment\Model\MethodInterface::class)
- ->getMockForAbstractClass();
- $om = new ObjectManager($this);
- $this->config = $om->getObject(
- \Magento\Paypal\Model\PayflowConfig::class,
- [
- 'scopeConfig' => $this->scopeConfigMock
- ]
- );
- }
- /**
- * @param string $paymentAction
- * @param string|null $expectedValue
- *
- * @dataProvider getTrxTypeDataProvider
- */
- public function testGetTrxType($paymentAction, $expectedValue)
- {
- $this->scopeConfigMock->expects($this->any())
- ->method('getValue')
- ->willReturn($paymentAction);
- $this->assertEquals($expectedValue, $this->config->getTrxType());
- }
- /**
- * @return array
- */
- public function getTrxTypeDataProvider()
- {
- return [
- [PayflowConfig::PAYMENT_ACTION_AUTH, PayflowConfig::TRXTYPE_AUTH_ONLY],
- [PayflowConfig::PAYMENT_ACTION_SALE, PayflowConfig::TRXTYPE_SALE],
- ['other', null],
- ];
- }
- /**
- * @param string $paymentAction
- * @param string|null $expectedValue
- *
- * @dataProvider getPaymentActionDataProvider
- */
- public function testGetPaymentAction($paymentAction, $expectedValue)
- {
- $this->scopeConfigMock->expects($this->any())
- ->method('getValue')
- ->willReturn($paymentAction);
- $this->assertEquals($expectedValue, $this->config->getPaymentAction());
- }
- /**
- * @return array
- */
- public function getPaymentActionDataProvider()
- {
- return [
- [PayflowConfig::PAYMENT_ACTION_AUTH, AbstractMethod::ACTION_AUTHORIZE],
- [PayflowConfig::PAYMENT_ACTION_SALE, AbstractMethod::ACTION_AUTHORIZE_CAPTURE],
- ['other', null],
- ];
- }
- public function testGetTransactionUrlWithTestModeOn()
- {
- $this->scopeConfigMock->expects($this->never())
- ->method('getValue');
- $this->methodInterfaceMock->expects($this->once())
- ->method('getConfigData')
- ->with('transaction_url_test_mode')
- ->willReturn('transaction_url_test_mode');
- $this->config->setMethodInstance($this->methodInterfaceMock);
- $this->assertEquals('transaction_url_test_mode', $this->config->getTransactionUrl(1));
- }
- public function testGetTransactionUrlWithTestModeOff()
- {
- $this->scopeConfigMock->expects($this->never())
- ->method('getValue');
- $this->methodInterfaceMock->expects($this->once())
- ->method('getConfigData')
- ->with('transaction_url')
- ->willReturn('transaction_url');
- $this->config->setMethodInstance($this->methodInterfaceMock);
- $this->assertEquals('transaction_url', $this->config->getTransactionUrl(0));
- }
- public function testGetTransactionUrlWithTestModeEmptyAndSandboxOn()
- {
- $this->scopeConfigMock->expects($this->once())
- ->method('getValue')
- ->willReturn(1);
- $this->methodInterfaceMock->expects($this->once())
- ->method('getConfigData')
- ->with('transaction_url_test_mode')
- ->willReturn('transaction_url_test_mode');
- $this->config->setMethodInstance($this->methodInterfaceMock);
- $this->assertEquals('transaction_url_test_mode', $this->config->getTransactionUrl());
- }
- public function testGetTransactionUrlWithTestModeEmptyAndSandboxOff()
- {
- $this->scopeConfigMock->expects($this->once())
- ->method('getValue')
- ->willReturn(0);
- $this->methodInterfaceMock->expects($this->once())
- ->method('getConfigData')
- ->with('transaction_url')
- ->willReturn('transaction_url');
- $this->config->setMethodInstance($this->methodInterfaceMock);
- $this->assertEquals('transaction_url', $this->config->getTransactionUrl());
- }
- /**
- * @param array $expectsMethods
- * @param string $currentMethod
- * @param bool $result
- *
- * @dataProvider dataProviderForTestIsMethodActive
- */
- public function testIsMethodActive(array $expectsMethods, $currentMethod, $result)
- {
- $this->config->setStoreId(5);
- $this->scopeConfigMock->expects($this->any())
- ->method('getValue')
- ->with('paypal/general/merchant_country')
- ->will($this->returnValue('US'));
- $i = 0;
- foreach ($expectsMethods as $method => $isActive) {
- $this->scopeConfigMock->expects($this->at($i++))
- ->method('isSetFlag')
- ->with(
- "payment/{$method}/active",
- ScopeInterface::SCOPE_STORE,
- 5
- )->willReturn($isActive);
- }
- $this->assertEquals($result, $this->config->isMethodActive($currentMethod));
- }
- /**
- * @return array
- */
- public function dataProviderForTestIsMethodActive()
- {
- return [
- [
- 'expectsMethods' => [
- Config::METHOD_PAYMENT_PRO => 0,
- Config::METHOD_PAYFLOWPRO => 1,
- ],
- 'currentMethod' => Config::METHOD_PAYMENT_PRO,
- 'result' => true,
- ],
- [
- 'expectsMethods' => [
- Config::METHOD_PAYMENT_PRO => 1
- ],
- 'currentMethod' => Config::METHOD_PAYFLOWPRO,
- 'result' => true,
- ],
- [
- 'expectsMethods' => [
- Config::METHOD_PAYMENT_PRO => 0,
- Config::METHOD_PAYFLOWPRO => 0,
- ],
- 'currentMethod' => 777,
- 'result' => false,
- ],
- ];
- }
- }
|