1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
* (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* PAYONE Magento 2 Connector is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Lesser General Public License for more details. |
13
|
|
|
* |
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
15
|
|
|
* along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>. |
16
|
|
|
* |
17
|
|
|
* PHP version 5 |
18
|
|
|
* |
19
|
|
|
* @category Payone |
20
|
|
|
* @package Payone_Magento2_Plugin |
21
|
|
|
* @author FATCHIP GmbH <[email protected]> |
22
|
|
|
* @copyright 2003 - 2017 Payone GmbH |
23
|
|
|
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License |
24
|
|
|
* @link http://www.payone.de |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace Payone\Core\Test\Unit\Model\Api; |
28
|
|
|
|
29
|
|
|
use Payone\Core\Model\Api\Invoice as ClassToTest; |
30
|
|
|
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
31
|
|
|
use Payone\Core\Helper\Toolkit; |
32
|
|
|
use Payone\Core\Model\Api\Request\Authorization; |
33
|
|
|
use Magento\Sales\Model\Order; |
34
|
|
|
use Magento\Sales\Model\Order\Item; |
35
|
|
|
|
36
|
|
|
class InvoiceTest extends \PHPUnit_Framework_TestCase |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* @var ClassToTest |
40
|
|
|
*/ |
41
|
|
|
private $classToTest; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var Toolkit |
45
|
|
|
*/ |
46
|
|
|
private $toolkitHelper; |
47
|
|
|
|
48
|
|
|
protected function setUp() |
49
|
|
|
{ |
50
|
|
|
$objectManager = new ObjectManager($this); |
51
|
|
|
|
52
|
|
|
$this->toolkitHelper = $this->getMockBuilder(Toolkit::class)->disableOriginalConstructor()->getMock(); |
53
|
|
|
$this->toolkitHelper->method('getInvoiceAppendix')->willReturn('invoice appendix'); |
54
|
|
|
$this->toolkitHelper->method('getConfigParam')->willReturn('sku'); |
55
|
|
|
$this->toolkitHelper->expects($this->any()) |
56
|
|
|
->method('formatNumber') |
57
|
|
|
->willReturnMap([ |
58
|
|
|
[100, 2, '100.00'], |
59
|
|
|
[5, 2, '5.00'], |
60
|
|
|
[-5, 2, '-5.00'], |
61
|
|
|
[90, 2, '90.00'], |
62
|
|
|
[105, 2, '105.00'], |
63
|
|
|
]); |
64
|
|
|
|
65
|
|
|
$this->classToTest = $objectManager->getObject(ClassToTest::class, [ |
66
|
|
|
'toolkitHelper' => $this->toolkitHelper |
67
|
|
|
]); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Returns item mock object |
72
|
|
|
* |
73
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
74
|
|
|
*/ |
75
|
|
|
private function getItemMock() |
76
|
|
|
{ |
77
|
|
|
$item = $this->getMockBuilder(Item::class)->disableOriginalConstructor()->getMock(); |
78
|
|
|
$item->method('isDummy')->willReturn(false); |
79
|
|
|
$item->method('getProductId')->willReturn('12345'); |
80
|
|
|
$item->method('getQtyOrdered')->willReturn('1'); |
81
|
|
|
$item->method('getSku')->willReturn('test_123'); |
82
|
|
|
$item->method('getPriceInclTax')->willReturn('100'); |
83
|
|
|
$item->method('getName')->willReturn('Test product'); |
84
|
|
|
$item->method('getTaxPercent')->willReturn('19'); |
85
|
|
|
return $item; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testAddProductInfo() |
89
|
|
|
{ |
90
|
|
|
$authorization = $this->getMockBuilder(Authorization::class)->disableOriginalConstructor()->getMock(); |
91
|
|
|
|
92
|
|
|
$items = [$this->getItemMock()]; |
93
|
|
|
|
94
|
|
|
$expected = 90; |
95
|
|
|
|
96
|
|
|
$order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); |
97
|
|
|
$order->method('getAllItems')->willReturn($items); |
98
|
|
|
$order->method('getBaseShippingInclTax')->willReturn(-5); |
99
|
|
|
$order->method('getBaseDiscountAmount')->willReturn(-5); |
100
|
|
|
$order->method('getCouponCode')->willReturn('test'); |
101
|
|
|
$order->method('getGrandTotal')->willReturn($expected); |
102
|
|
|
|
103
|
|
|
$result = $this->classToTest->addProductInfo($authorization, $order, false); |
104
|
|
|
$this->assertEquals($expected, $result); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function testAddProductInfoSurcharge() |
108
|
|
|
{ |
109
|
|
|
$authorization = $this->getMockBuilder(Authorization::class)->disableOriginalConstructor()->getMock(); |
110
|
|
|
|
111
|
|
|
$items = [$this->getItemMock()]; |
112
|
|
|
|
113
|
|
|
$expected = 100; |
114
|
|
|
|
115
|
|
|
$order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); |
116
|
|
|
$order->method('getAllItems')->willReturn($items); |
117
|
|
|
$order->method('getBaseShippingInclTax')->willReturn(5); |
118
|
|
|
$order->method('getBaseDiscountAmount')->willReturn(-5); |
119
|
|
|
$order->method('getCouponCode')->willReturn('test'); |
120
|
|
|
$order->method('getGrandTotal')->willReturn($expected); |
121
|
|
|
|
122
|
|
|
$positions = ['12345' => ['amount' => '1']]; |
123
|
|
|
|
124
|
|
|
$result = $this->classToTest->addProductInfo($authorization, $order, $positions); |
125
|
|
|
$this->assertEquals($expected, $result); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|