Skip to content

Commit f6f1268

Browse files
committed
MAGETWO-38902: Payment\Gateway update
- order redirect url workaround - refactored tests to be less useless
1 parent 319cdcc commit f6f1268

File tree

15 files changed

+90
-44
lines changed

15 files changed

+90
-44
lines changed

app/code/Magento/Authorizenet/Model/Directpost.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,4 +898,26 @@ protected function addStatusCommentOnUpdate(
898898
}
899899
return $this;
900900
}
901+
902+
/**
903+
* Sets method code
904+
*
905+
* @param string $methodCode
906+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
907+
* @return void
908+
*/
909+
public function setMethodCode($methodCode)
910+
{
911+
}
912+
913+
/**
914+
* Sets path pattern
915+
*
916+
* @param string $pathPattern
917+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
918+
* @return void
919+
*/
920+
public function setPathPattern($pathPattern)
921+
{
922+
}
901923
}

app/code/Magento/Paypal/Model/AbstractConfig.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ abstract class AbstractConfig implements ConfigInterface
4444
*/
4545
protected $_storeId;
4646

47+
/**
48+
* @var string
49+
*/
50+
private $pathPattern;
51+
4752
/**
4853
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
4954
*/
@@ -138,6 +143,28 @@ public function getValue($key, $storeId = null)
138143
return null;
139144
}
140145

146+
/**
147+
* Sets method code
148+
*
149+
* @param string $methodCode
150+
* @return void
151+
*/
152+
public function setMethodCode($methodCode)
153+
{
154+
$this->_methodCode = $methodCode;
155+
}
156+
157+
/**
158+
* Sets path pattern
159+
*
160+
* @param string $pathPattern
161+
* @return void
162+
*/
163+
public function setPathPattern($pathPattern)
164+
{
165+
$this->pathPattern = $pathPattern;
166+
}
167+
141168
/**
142169
* Map any supported payment method into a config path by specified field name
143170
*
@@ -146,6 +173,10 @@ public function getValue($key, $storeId = null)
146173
*/
147174
protected function _getSpecificConfigPath($fieldName)
148175
{
176+
if ($this->pathPattern) {
177+
return sprintf($this->pathPattern, $this->_methodCode, $fieldName);
178+
}
179+
149180
return "payment/{$this->_methodCode}/{$fieldName}";
150181
}
151182

app/code/Magento/Paypal/Model/Direct.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ public function getConfigData($field, $storeId = null)
287287
case 'cctypes':
288288
$value = $this->getAllowedCcTypes();
289289
break;
290+
case 'order_place_redirect_url':
291+
$value = $this->getOrderPlaceRedirectUrl();
292+
break;
290293
default:
291294
$value = $this->_pro->getConfig()->getValue($field);
292295
}

app/code/Magento/Paypal/Model/Express.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ public function isAvailable($quote = null)
335335
*/
336336
public function getConfigData($field, $storeId = null)
337337
{
338+
if ('order_place_redirect_url' === $field) {
339+
return $this->getOrderPlaceRedirectUrl();
340+
}
338341
return $this->_pro->getConfig()->getValue($field);
339342
}
340343

app/code/Magento/Paypal/Test/Unit/Helper/DataTest.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ class DataTest extends \PHPUnit_Framework_TestCase
1313
protected $_paymentDataMock;
1414

1515
/**
16-
* @var \Magento\Paypal\Model\ConfigFactory | \PHPUnit_Framework_MockObject_MockObject
16+
* @var \Magento\Paypal\Model\Config | \PHPUnit_Framework_MockObject_MockObject
1717
*/
18-
protected $configFactoryMock;
18+
protected $configMock;
1919

2020
/**
2121
* @var \Magento\Paypal\Helper\Data
@@ -30,23 +30,27 @@ public function setUp()
3030
['getStoreMethods', 'getPaymentMethods']
3131
)->getMock();
3232

33-
$this->configFactoryMock = $this->getMock(
34-
'Magento\Paypal\Model\ConfigFactory',
35-
['create', 'setMethod', 'getValue'],
33+
$this->configMock = $this->getMock(
34+
'Magento\Paypal\Model\Config',
35+
[],
3636
[],
3737
'',
3838
false
3939
);
40-
$this->configFactoryMock->expects($this->any())->method('create')->will($this->returnSelf());
41-
$this->configFactoryMock->expects($this->any())->method('setMethod')->will($this->returnSelf());
40+
$configMockFactory = $this->getMockBuilder('Magento\Paypal\Model\ConfigFactory')
41+
->disableOriginalConstructor()
42+
->setMethods(['create'])
43+
->getMock();
44+
$configMockFactory->expects($this->any())->method('create')->willReturn($this->configMock);
45+
$this->configMock->expects($this->any())->method('setMethod')->will($this->returnSelf());
4246

4347
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
4448
$this->_helper = $objectManager->getObject(
4549
'Magento\Paypal\Helper\Data',
4650
[
4751
'paymentData' => $this->_paymentDataMock,
4852
'methodCodes' => ['expressCheckout' => 'paypal_express', 'hostedPro' => 'hosted_pro'],
49-
'configFactory' => $this->configFactoryMock
53+
'configFactory' => $configMockFactory
5054
]
5155
);
5256
}
@@ -103,7 +107,7 @@ public function testGetHtmlTransactionId($methodCode, $htmlTransactionId)
103107
$txnId = 'XXX123123XXX';
104108
$htmlTransactionId = sprintf($htmlTransactionId, 'sandbox', $txnId);
105109

106-
$this->configFactoryMock->expects($this->any())
110+
$this->configMock->expects($this->any())
107111
->method('getValue')
108112
->with($this->stringContains('sandboxFlag'))
109113
->willReturn(true);

app/code/Magento/Paypal/Test/Unit/Model/IpnTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,19 @@ protected function setUp()
6666

6767
$this->configFactory = $this->getMock(
6868
'Magento\Paypal\Model\ConfigFactory',
69-
['create', 'isMethodActive', 'isMethodAvailable', 'getValue', 'getPaypalUrl'],
69+
['create'],
7070
[],
7171
'',
7272
false
7373
);
74-
$this->configFactory->expects($this->any())->method('create')->will($this->returnSelf());
75-
$this->configFactory->expects($this->any())->method('isMethodActive')->will($this->returnValue(true));
76-
$this->configFactory->expects($this->any())->method('isMethodAvailable')->will($this->returnValue(true));
77-
$this->configFactory->expects($this->any())->method('getValue')->will($this->returnValue(null));
78-
$this->configFactory->expects($this->any())->method('getPaypalUrl')
74+
$configMock = $this->getMockBuilder('Magento\Paypal\Model\Config')
75+
->disableOriginalConstructor()
76+
->getMock();
77+
$this->configFactory->expects($this->any())->method('create')->willReturn($configMock);
78+
$configMock->expects($this->any())->method('isMethodActive')->will($this->returnValue(true));
79+
$configMock->expects($this->any())->method('isMethodAvailable')->will($this->returnValue(true));
80+
$configMock->expects($this->any())->method('getValue')->will($this->returnValue(null));
81+
$configMock->expects($this->any())->method('getPaypalUrl')
7982
->will($this->returnValue('http://paypal_url'));
8083

8184
$this->curlFactory = $this->getMock(

app/code/Magento/Paypal/Test/Unit/Model/Method/AgreementTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected function setUp()
2929
$paypalConfigMock = $this->getMockBuilder(
3030
'\Magento\Paypal\Model\Config'
3131
)->disableOriginalConstructor()->setMethods(
32-
['getValue']
32+
[]
3333
)->getMock();
3434
$this->_apiNvpMock = $this->getMockBuilder(
3535
'\Magento\Paypal\Model\Api\Nvp'

app/code/Magento/Paypal/Test/Unit/Model/ObserverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected function setUp()
117117
);
118118
$this->paypalConfigMock = $this->getMock(
119119
'Magento\Paypal\Model\Config',
120-
['isMethodAvailable'],
120+
[],
121121
[],
122122
'',
123123
false

app/code/Magento/Paypal/Test/Unit/Model/Payflow/Service/GatewayTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ protected function setUp()
5959
public function testPostRequestOk()
6060
{
6161
$configInterfaceMock = $this->getMockBuilder('\Magento\Payment\Model\Method\ConfigInterface')
62-
->disableOriginalConstructor()
6362
->getMockForAbstractClass();
6463
$zendResponseMock = $this->getMockBuilder('\Zend_Http_Response')
6564
->setMethods(['getBody'])
@@ -96,7 +95,6 @@ public function testPostRequestOk()
9695
public function testPostRequestFail()
9796
{
9897
$configInterfaceMock = $this->getMockBuilder('\Magento\Payment\Model\Method\ConfigInterface')
99-
->disableOriginalConstructor()
10098
->getMockForAbstractClass();
10199
$zendResponseMock = $this->getMockBuilder('\Zend_Http_Response')
102100
->setMethods(['getBody'])

app/code/Magento/Paypal/Test/Unit/Model/Payflow/Service/Response/Validator/AVSResponseTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ protected function setUp()
4242
->setMethods(['get'])
4343
->getMockForAbstractClass();
4444
$this->configMock = $this->getMockBuilder('Magento\Payment\Model\Method\ConfigInterface')
45-
->setMethods(['getValue'])
4645
->getMockForAbstractClass();
4746

4847
$this->setToExpectedCallsInConstructor(

0 commit comments

Comments
 (0)