5
5
*/
6
6
namespace Magento \Quote \Test \Unit \Model \Quote ;
7
7
8
+ use Magento \Framework \DataObject ;
9
+ use Magento \Framework \Event \ManagerInterface ;
10
+ use Magento \Payment \Model \Checks \Composite ;
11
+ use Magento \Payment \Model \Checks \SpecificationFactory ;
12
+ use Magento \Payment \Model \MethodInterface ;
13
+ use Magento \Quote \Api \Data \PaymentInterface ;
14
+ use Magento \Quote \Model \Quote ;
8
15
use \Magento \Quote \Model \Quote \Payment ;
9
16
10
17
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
@@ -16,11 +23,31 @@ class PaymentTest extends \PHPUnit_Framework_TestCase
16
23
*/
17
24
private $ model ;
18
25
26
+ /**
27
+ * @var \PHPUnit_Framework_MockObject_MockObject|SpecificationFactory
28
+ */
29
+ private $ specificationFactory ;
30
+
31
+ /**
32
+ * @var \PHPUnit_Framework_MockObject_MockObject|ManagerInterface
33
+ */
34
+ private $ eventManager ;
35
+
19
36
protected function setUp ()
20
37
{
21
38
$ objectManager = new ObjectManager ($ this );
39
+ $ this ->specificationFactory = $ this ->getMockBuilder (
40
+ SpecificationFactory::class
41
+ )->disableOriginalConstructor ()
42
+ ->getMock ();
43
+ $ this ->eventManager = $ this ->getMock (ManagerInterface::class);
44
+
22
45
$ this ->model = $ objectManager ->getObject (
23
- '\Magento\Quote\Model\Quote\Payment '
46
+ Payment::class,
47
+ [
48
+ 'methodSpecificationFactory ' => $ this ->specificationFactory ,
49
+ 'eventDispatcher ' => $ this ->eventManager
50
+ ]
24
51
);
25
52
}
26
53
@@ -32,7 +59,7 @@ protected function setUp()
32
59
public function testGetCcExpYearReturnsValidValue ($ databaseValue , $ expectedValue )
33
60
{
34
61
$ this ->model ->setData ('cc_exp_year ' , $ databaseValue );
35
- $ this -> assertEquals ($ expectedValue , $ this ->model ->getCcExpYear ());
62
+ static :: assertEquals ($ expectedValue , $ this ->model ->getCcExpYear ());
36
63
}
37
64
38
65
/**
@@ -47,4 +74,141 @@ public function yearValueDataProvider()
47
74
[1939 , 1939 ],
48
75
];
49
76
}
77
+
78
+ /**
79
+ * @param array $data
80
+ * @param array $convertedData
81
+ * @param array $dataToAssign
82
+ * @param array $checks
83
+ * @dataProvider importDataPositiveCheckDataProvider
84
+ */
85
+ public function testImportDataPositiveCheck (
86
+ array $ data ,
87
+ array $ convertedData ,
88
+ array $ dataToAssign ,
89
+ array $ checks
90
+ ) {
91
+ $ quoteId = 1 ;
92
+ $ storeId = 1 ;
93
+
94
+ $ paymentMethod = $ this ->getMock (MethodInterface::class);
95
+ $ quote = $ this ->getMockBuilder (Quote::class)
96
+ ->disableOriginalConstructor ()
97
+ ->getMock ();
98
+ $ methodSpecification = $ this ->getMockBuilder (Composite::class)
99
+ ->disableOriginalConstructor ()
100
+ ->getMock ();
101
+
102
+ $ quote ->expects (static ::once ())
103
+ ->method ('getId ' )
104
+ ->willReturn ($ quoteId );
105
+
106
+ $ this ->model ->setQuote ($ quote );
107
+ $ this ->model ->setMethodInstance ($ paymentMethod );
108
+ $ this ->eventManager ->expects (static ::once ())
109
+ ->method ('dispatch ' )
110
+ ->with (
111
+ 'sales_quote_payment_import_data_before ' ,
112
+ [
113
+ 'payment ' => $ this ->model ,
114
+ 'input ' => new DataObject ($ convertedData )
115
+ ]
116
+ );
117
+ $ quote ->expects (static ::once ())
118
+ ->method ('getStoreId ' )
119
+ ->willReturn ($ storeId );
120
+
121
+ $ quote ->expects (static ::once ())
122
+ ->method ('collectTotals ' );
123
+
124
+ $ this ->specificationFactory ->expects (static ::once ())
125
+ ->method ('create ' )
126
+ ->with ($ checks )
127
+ ->willReturn ($ methodSpecification );
128
+
129
+ $ paymentMethod ->expects (static ::once ())
130
+ ->method ('isAvailable ' )
131
+ ->with ($ quote )
132
+ ->willReturn (true );
133
+ $ methodSpecification ->expects (static ::once ())
134
+ ->method ('isApplicable ' )
135
+ ->with ($ paymentMethod , $ quote )
136
+ ->willReturn (true );
137
+
138
+ $ paymentMethod ->expects (static ::once ())
139
+ ->method ('assignData ' )
140
+ ->with (new DataObject ($ dataToAssign ));
141
+ $ paymentMethod ->expects (static ::once ())
142
+ ->method ('validate ' );
143
+
144
+ $ this ->model ->importData ($ data );
145
+ }
146
+
147
+ /**
148
+ * @return array
149
+ */
150
+ public function importDataPositiveCheckDataProvider ()
151
+ {
152
+ return [
153
+ [
154
+ [
155
+ PaymentInterface::KEY_METHOD => 'payment_method_code ' ,
156
+ 'cc_number ' => '1111 ' ,
157
+ 'cc_type ' => 'VI ' ,
158
+ 'cc_owner ' => 'John Doe '
159
+ ],
160
+ [
161
+ PaymentInterface::KEY_METHOD => 'payment_method_code ' ,
162
+ PaymentInterface::KEY_PO_NUMBER => null ,
163
+ PaymentInterface::KEY_ADDITIONAL_DATA => [
164
+ 'cc_number ' => '1111 ' ,
165
+ 'cc_type ' => 'VI ' ,
166
+ 'cc_owner ' => 'John Doe '
167
+ ],
168
+ 'checks ' => []
169
+ ],
170
+ [
171
+ PaymentInterface::KEY_METHOD => 'payment_method_code ' ,
172
+ PaymentInterface::KEY_PO_NUMBER => null ,
173
+ PaymentInterface::KEY_ADDITIONAL_DATA => [
174
+ 'cc_number ' => '1111 ' ,
175
+ 'cc_type ' => 'VI ' ,
176
+ 'cc_owner ' => 'John Doe '
177
+ ],
178
+ 'checks ' => []
179
+ ],
180
+ []
181
+ ],
182
+ [
183
+ [
184
+ PaymentInterface::KEY_METHOD => 'payment_method_code ' ,
185
+ 'cc_number ' => '1111 ' ,
186
+ 'cc_type ' => 'VI ' ,
187
+ 'cc_owner ' => 'John Doe ' ,
188
+ 'checks ' => ['check_code1 ' , 'check_code2 ' ]
189
+ ],
190
+ [
191
+ PaymentInterface::KEY_METHOD => 'payment_method_code ' ,
192
+ PaymentInterface::KEY_PO_NUMBER => null ,
193
+ PaymentInterface::KEY_ADDITIONAL_DATA => [
194
+ 'cc_number ' => '1111 ' ,
195
+ 'cc_type ' => 'VI ' ,
196
+ 'cc_owner ' => 'John Doe '
197
+ ],
198
+ 'checks ' => ['check_code1 ' , 'check_code2 ' ]
199
+ ],
200
+ [
201
+ PaymentInterface::KEY_METHOD => 'payment_method_code ' ,
202
+ PaymentInterface::KEY_PO_NUMBER => null ,
203
+ PaymentInterface::KEY_ADDITIONAL_DATA => [
204
+ 'cc_number ' => '1111 ' ,
205
+ 'cc_type ' => 'VI ' ,
206
+ 'cc_owner ' => 'John Doe '
207
+ ],
208
+ 'checks ' => ['check_code1 ' , 'check_code2 ' ]
209
+ ],
210
+ ['check_code1 ' , 'check_code2 ' ]
211
+ ]
212
+ ];
213
+ }
50
214
}
0 commit comments