Skip to content

Commit 5257c5b

Browse files
author
Kostiantyn Poida
committed
Merge branch 'MAGETWO-31363' of github.corp.ebay.com:magento-mpi/magento2ce into MAGETWO-31363
Conflicts: dev/tests/unit/testsuite/Magento/OfflineShipping/Block/Adminhtml/Carrier/Tablerate/GridTest.php
2 parents 619125f + 567d9e1 commit 5257c5b

File tree

8 files changed

+390
-4
lines changed

8 files changed

+390
-4
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\OfflinePayments\Block\Form;
7+
8+
class BanktransferTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\OfflinePayments\Block\Form\Banktransfer
12+
*/
13+
protected $_object;
14+
15+
protected function setUp()
16+
{
17+
$objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
18+
$this->_object = $objectManagerHelper->getObject('Magento\OfflinePayments\Block\Form\Banktransfer');
19+
}
20+
21+
public function testGetInstructions()
22+
{
23+
$method = $this->getMock(
24+
'Magento\Payment\Model\MethodInterface',
25+
['getInstructions', 'getCode', 'getFormBlockType', 'getTitle'],
26+
[],
27+
'',
28+
false
29+
);
30+
$method->expects($this->once())
31+
->method('getInstructions')
32+
->willReturn('instructions');
33+
$this->_object->setData('method', $method);
34+
35+
$this->assertEquals('instructions', $this->_object->getInstructions());
36+
}
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\OfflinePayments\Block\Form;
7+
8+
class CashondeliveryTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\OfflinePayments\Block\Form\Cashondelivery
12+
*/
13+
protected $_object;
14+
15+
protected function setUp()
16+
{
17+
$objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
18+
$this->_object = $objectManagerHelper->getObject('Magento\OfflinePayments\Block\Form\Cashondelivery');
19+
}
20+
21+
public function testGetInstructions()
22+
{
23+
$method = $this->getMock(
24+
'Magento\Payment\Model\MethodInterface',
25+
['getInstructions', 'getCode', 'getFormBlockType', 'getTitle'],
26+
[],
27+
'',
28+
false
29+
);
30+
$method->expects($this->once())
31+
->method('getInstructions')
32+
->willReturn('instructions');
33+
$this->_object->setData('method', $method);
34+
35+
$this->assertEquals('instructions', $this->_object->getInstructions());
36+
}
37+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\OfflinePayments\Block\Info;
7+
8+
class CheckmoTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\OfflinePayments\Block\Info\Checkmo
12+
*/
13+
protected $_object;
14+
15+
/**
16+
* @var \PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $_scopeConfig;
19+
20+
protected function setUp()
21+
{
22+
$objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
23+
$eventManager = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false);
24+
$paymentDataMock = $this->getMock('Magento\Payment\Helper\Data', [], [], '', false);
25+
$this->_scopeConfig = $this->getMock(
26+
'Magento\Framework\App\Config\ScopeConfigInterface',
27+
['getValue', 'isSetFlag'],
28+
[],
29+
'',
30+
false
31+
);
32+
$this->_object = $objectManagerHelper->getObject(
33+
'Magento\OfflinePayments\Block\Info\Checkmo',
34+
[
35+
'eventManager' => $eventManager,
36+
'paymentData' => $paymentDataMock,
37+
'scopeConfig' => $this->_scopeConfig,
38+
]
39+
);
40+
}
41+
42+
/**
43+
* @dataProvider getPayableToDataProvider
44+
*/
45+
public function testGetPayableTo($details, $expected)
46+
{
47+
$info = $this->getMock('Magento\Payment\Model\Info', ['getAdditionalData'], [], '', false);
48+
$info->expects($this->once())
49+
->method('getAdditionalData')
50+
->willReturn(serialize($details));
51+
$this->_object->setData('info', $info);
52+
53+
$this->assertEquals($expected, $this->_object->getPayableTo());
54+
}
55+
56+
/**
57+
* @return array
58+
*/
59+
public function getPayableToDataProvider()
60+
{
61+
return [
62+
[['payable_to' => 'payable'], 'payable'],
63+
['', '']
64+
];
65+
}
66+
67+
/**
68+
* @dataProvider getMailingAddressDataProvider
69+
*/
70+
public function testGetMailingAddress($details, $expected)
71+
{
72+
$info = $this->getMock('Magento\Payment\Model\Info', ['getAdditionalData'], [], '', false);
73+
$info->expects($this->once())
74+
->method('getAdditionalData')
75+
->willReturn(serialize($details));
76+
$this->_object->setData('info', $info);
77+
78+
$this->assertEquals($expected, $this->_object->getMailingAddress());
79+
}
80+
81+
/**
82+
* @return array
83+
*/
84+
public function getMailingAddressDataProvider()
85+
{
86+
return [
87+
[['mailing_address' => 'blah@blah.com'], 'blah@blah.com'],
88+
['', '']
89+
];
90+
}
91+
}

dev/tests/unit/testsuite/Magento/OfflinePayments/Model/BanktransferTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,23 @@ class BanktransferTest extends \PHPUnit_Framework_TestCase
1212
*/
1313
protected $_object;
1414

15+
/**
16+
* @var \PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $_scopeConfig;
19+
1520
protected function setUp()
1621
{
1722
$objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
1823
$eventManager = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false);
1924
$paymentDataMock = $this->getMock('Magento\Payment\Helper\Data', [], [], '', false);
20-
$scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface');
25+
$this->_scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface', [], [], '', false);
2126
$this->_object = $objectManagerHelper->getObject(
2227
'Magento\OfflinePayments\Model\Banktransfer',
2328
[
2429
'eventManager' => $eventManager,
2530
'paymentData' => $paymentDataMock,
26-
'scopeConfig' => $scopeConfig,
31+
'scopeConfig' => $this->_scopeConfig,
2732
]
2833
);
2934
}
@@ -32,4 +37,14 @@ public function testGetInfoBlockType()
3237
{
3338
$this->assertEquals('Magento\Payment\Block\Info\Instructions', $this->_object->getInfoBlockType());
3439
}
40+
41+
public function testGetInstructions()
42+
{
43+
$this->_object->setStore(1);
44+
$this->_scopeConfig->expects($this->once())
45+
->method('getValue')
46+
->with('payment/banktransfer/instructions', 'store', 1)
47+
->willReturn('payment configuration');
48+
$this->assertEquals('payment configuration', $this->_object->getInstructions());
49+
}
3550
}

dev/tests/unit/testsuite/Magento/OfflinePayments/Model/CashondeliveryTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,25 @@ class CashondeliveryTest extends \PHPUnit_Framework_TestCase
1212
*/
1313
protected $_object;
1414

15+
/**
16+
* @var \PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $_scopeConfig;
19+
1520
protected function setUp()
1621
{
1722
$helper = new \Magento\TestFramework\Helper\ObjectManager($this);
1823

1924
$eventManager = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false);
2025
$paymentDataMock = $this->getMock('Magento\Payment\Helper\Data', [], [], '', false);
2126

22-
$scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface');
27+
$this->_scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface', [], [], '', false);
2328
$this->_object = $helper->getObject(
2429
'Magento\OfflinePayments\Model\Cashondelivery',
2530
[
2631
'eventManager' => $eventManager,
2732
'paymentData' => $paymentDataMock,
28-
'scopeConfig' => $scopeConfig,
33+
'scopeConfig' => $this->_scopeConfig,
2934
]
3035
);
3136
}
@@ -34,4 +39,14 @@ public function testGetInfoBlockType()
3439
{
3540
$this->assertEquals('Magento\Payment\Block\Info\Instructions', $this->_object->getInfoBlockType());
3641
}
42+
43+
public function testGetInstructions()
44+
{
45+
$this->_object->setStore(1);
46+
$this->_scopeConfig->expects($this->once())
47+
->method('getValue')
48+
->with('payment/cashondelivery/instructions', 'store', 1)
49+
->willReturn('payment configuration');
50+
$this->assertEquals('payment configuration', $this->_object->getInstructions());
51+
}
3752
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\OfflinePayments\Model;
7+
8+
class CheckmoTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\OfflinePayments\Model\Checkmo
12+
*/
13+
protected $_object;
14+
15+
/**
16+
* @var \PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $_scopeConfig;
19+
20+
protected function setUp()
21+
{
22+
$objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
23+
$eventManager = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false);
24+
$paymentDataMock = $this->getMock('Magento\Payment\Helper\Data', [], [], '', false);
25+
$this->_scopeConfig = $this->getMock(
26+
'Magento\Framework\App\Config\ScopeConfigInterface',
27+
['getValue', 'isSetFlag'],
28+
[],
29+
'',
30+
false
31+
);
32+
$this->_object = $objectManagerHelper->getObject(
33+
'Magento\OfflinePayments\Model\Checkmo',
34+
[
35+
'eventManager' => $eventManager,
36+
'paymentData' => $paymentDataMock,
37+
'scopeConfig' => $this->_scopeConfig,
38+
]
39+
);
40+
}
41+
42+
public function testGetPayableTo()
43+
{
44+
$this->_object->setStore(1);
45+
$this->_scopeConfig->expects($this->once())
46+
->method('getValue')
47+
->with('payment/checkmo/payable_to', 'store', 1)
48+
->willReturn('payable');
49+
$this->assertEquals('payable', $this->_object->getPayableTo());
50+
}
51+
52+
public function testGetMailingAddress()
53+
{
54+
$this->_object->setStore(1);
55+
$this->_scopeConfig->expects($this->once())
56+
->method('getValue')
57+
->with('payment/checkmo/mailing_address', 'store', 1)
58+
->willReturn('blah@blah.com');
59+
$this->assertEquals('blah@blah.com', $this->_object->getMailingAddress());
60+
}
61+
62+
public function testAssignData()
63+
{
64+
$details['payable_to'] = 'payable';
65+
$details['mailing_address'] = 'blah@blah.com';
66+
$this->_object->setStore(1);
67+
$this->_scopeConfig->expects($this->any())
68+
->method('getValue')
69+
->willReturnMap([
70+
['payment/checkmo/payable_to', 'store', 1, 'payable'],
71+
['payment/checkmo/mailing_address', 'store', 1, 'blah@blah.com']
72+
]);
73+
$instance = $this->getMock('Magento\Payment\Model\Info', ['setAdditionalData'], [], '', false);
74+
$instance->expects($this->once())
75+
->method('setAdditionalData')
76+
->with(serialize($details));
77+
$this->_object->setData('info_instance', $instance);
78+
$this->_object->assignData('');
79+
}
80+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\OfflinePayments\Model;
7+
8+
class ObserverTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\OfflinePayments\Model\Observer
12+
*/
13+
protected $_model;
14+
15+
protected function setUp()
16+
{
17+
$objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
18+
$this->_model = $objectManagerHelper->getObject('Magento\OfflinePayments\Model\Observer');
19+
}
20+
21+
public function testBeforeOrderPaymentSave()
22+
{
23+
$observer = $this->getMock('Magento\Framework\Event\Observer', ['getEvent'], [], '', false);
24+
$event = $this->getMock('Magento\Framework\Event', ['getPayment'], [], '', false);
25+
$payment = $this->getMock(
26+
'Magento\Sales\Model\Order\Payment',
27+
['getMethod', 'setAdditionalInformation', 'getMethodInstance'],
28+
[],
29+
'',
30+
false
31+
);
32+
$payment->expects($this->once())
33+
->method('getMethod')
34+
->willReturn('banktransfer');
35+
$payment->expects($this->once())
36+
->method('setAdditionalInformation')
37+
->with('instructions', 'payment configuration');
38+
$method = $this->getMock(
39+
'Magento\Payment\Model\MethodInterface',
40+
['getInstructions', 'getFormBlockType', 'getTitle', 'getCode'],
41+
[],
42+
'',
43+
false
44+
);
45+
$method->expects($this->once())
46+
->method('getInstructions')
47+
->willReturn('payment configuration');
48+
$payment->expects($this->once())
49+
->method('getMethodInstance')
50+
->willReturn($method);
51+
$event->expects($this->once())
52+
->method('getPayment')
53+
->willReturn($payment);
54+
$observer->expects($this->once())
55+
->method('getEvent')
56+
->willReturn($event);
57+
$this->_model->beforeOrderPaymentSave($observer);
58+
}
59+
}

0 commit comments

Comments
 (0)