@@ -13,188 +13,82 @@ class GuestPaymentMethodManagementTest extends \PHPUnit_Framework_TestCase
13
13
protected $ model ;
14
14
15
15
/**
16
- * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
16
+ * @var \PHPUnit_Framework_MockObject_MockObject
17
17
*/
18
- protected $ objectManager ;
18
+ protected $ quoteIdMaskFactoryMock ;
19
19
20
20
/**
21
21
* @var \PHPUnit_Framework_MockObject_MockObject
22
22
*/
23
- protected $ quoteRepositoryMock ;
23
+ protected $ quoteIdMaskMock ;
24
24
25
25
/**
26
26
* @var \PHPUnit_Framework_MockObject_MockObject
27
27
*/
28
- protected $ methodListMock ;
28
+ protected $ paymentMethodManagementMock ;
29
29
30
30
/**
31
31
* @var \PHPUnit_Framework_MockObject_MockObject
32
32
*/
33
- protected $ zeroTotalMock ;
33
+ protected $ paymentMock ;
34
34
35
35
/**
36
- * @var \PHPUnit_Framework_MockObject_MockObject
36
+ * @var string
37
37
*/
38
- protected $ quoteIdMaskFactoryMock ;
38
+ protected $ maskedCartId ;
39
39
40
40
/**
41
- * @var \PHPUnit_Framework_MockObject_MockObject
41
+ * @var int
42
42
*/
43
- protected $ quoteIdMaskMock ;
43
+ protected $ cartId ;
44
44
45
45
protected function setUp ()
46
46
{
47
- $ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
48
- $ this ->quoteRepositoryMock = $ this ->getMock ('Magento\Quote\Model\QuoteRepository ' , [], [], '' , false );
49
- $ this ->methodListMock = $ this ->getMock ('Magento\Payment\Model\MethodList ' , [], [], '' , false );
50
- $ this ->zeroTotalMock = $ this ->getMock ('Magento\Payment\Model\Checks\ZeroTotal ' , [], [], '' , false );
51
- $ this ->quoteIdMaskFactoryMock = $ this ->getMock ('Magento\Quote\Model\QuoteIdMaskFactory ' , [], [], '' , false );
52
- $ this ->quoteIdMaskMock = $ this ->getMock ('Magento\Quote\Model\QuoteIdMask ' , [], [], '' , false );
47
+ $ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
48
+ $ this ->paymentMethodManagementMock = $ this ->getMock (
49
+ 'Magento\Quote\Model\PaymentMethodManagement ' ,
50
+ [],
51
+ [],
52
+ '' ,
53
+ false
54
+ );
55
+ $ this ->paymentMock = $ this ->getMock ('Magento\Quote\Model\Quote\Payment ' , [], [], '' , false );
56
+
57
+ $ this ->maskedCartId = 'f216207248d65c789b17be8545e0aa73 ' ;
58
+ $ this ->cartId = 11 ;
59
+
60
+ $ guestCartTestHelper = new GuestCartTestHelper ($ this );
61
+ list ($ this ->quoteIdMaskFactoryMock , $ this ->quoteIdMaskMock ) = $ guestCartTestHelper ->mockQuoteIdMask (
62
+ $ this ->maskedCartId ,
63
+ $ this ->cartId
64
+ );
53
65
54
- $ this ->model = $ this -> objectManager ->getObject (
66
+ $ this ->model = $ objectManager ->getObject (
55
67
'Magento\Quote\Model\GuestCart\GuestPaymentMethodManagement ' ,
56
68
[
57
- 'quoteRepository ' => $ this ->quoteRepositoryMock ,
58
- 'methodList ' => $ this ->methodListMock ,
59
- 'zeroTotalValidator ' => $ this ->zeroTotalMock ,
69
+ 'paymentMethodManagement ' => $ this ->paymentMethodManagementMock ,
60
70
'quoteIdMaskFactory ' => $ this ->quoteIdMaskFactoryMock
61
71
]
62
72
);
63
73
}
64
74
65
- public function testGetPaymentSuccess ()
75
+ public function testGet ()
66
76
{
67
- $ maskedCartId = 'f216207248d65c789b17be8545e0aa73 ' ;
68
- $ cartId = 11 ;
69
-
70
- $ this ->quoteIdMaskFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteIdMaskMock );
71
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
72
- ->method ('load ' )
73
- ->with ($ maskedCartId , 'masked_id ' )
74
- ->willReturn ($ this ->quoteIdMaskMock );
75
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
76
- ->method ('getId ' )
77
- ->willReturn ($ cartId );
78
-
79
- $ paymentMock = $ this ->getMock ('Magento\Quote\Model\Quote\Payment ' , [], [], '' , false );
80
- $ paymentMock ->expects ($ this ->once ())->method ('getId ' )->will ($ this ->returnValue (1 ));
81
-
82
- $ quoteMock = $ this ->getMock ('Magento\Quote\Model\Quote ' , [], [], '' , false );
83
- $ quoteMock ->expects ($ this ->once ())->method ('getPayment ' )->will ($ this ->returnValue ($ paymentMock ));
84
-
85
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
86
- ->method ('getActive ' )
87
- ->with ($ cartId )
88
- ->will ($ this ->returnValue ($ quoteMock ));
89
- $ this ->assertEquals ($ paymentMock , $ this ->model ->get ($ maskedCartId ));
77
+ $ this ->paymentMethodManagementMock ->expects ($ this ->once ())->method ('get ' )->willReturn ($ this ->paymentMock );
78
+ $ this ->assertEquals ($ this ->paymentMock , $ this ->model ->get ($ this ->maskedCartId ));
90
79
}
91
80
92
81
public function testGetList ()
93
82
{
94
- $ maskedCartId = 'f216207248d65c789b17be8545e0aa73 ' ;
95
- $ cartId = 10 ;
96
-
97
- $ this ->quoteIdMaskFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteIdMaskMock );
98
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
99
- ->method ('load ' )
100
- ->with ($ maskedCartId , 'masked_id ' )
101
- ->willReturn ($ this ->quoteIdMaskMock );
102
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
103
- ->method ('getId ' )
104
- ->willReturn ($ cartId );
105
-
106
- $ quoteMock = $ this ->getMock ('Magento\Quote\Model\Quote ' , [], [], '' , false );
107
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
108
- ->method ('getActive ' )
109
- ->with ($ cartId )
110
- ->will ($ this ->returnValue ($ quoteMock ));
111
-
112
- $ paymentMethod = $ this ->getMock ('Magento\Quote\Api\Data\PaymentMethodInterface ' );
113
- $ this ->methodListMock ->expects ($ this ->once ())
114
- ->method ('getAvailableMethods ' )
115
- ->with ($ quoteMock )
116
- ->will ($ this ->returnValue ([$ paymentMethod ]));
117
- $ this ->assertEquals ([$ paymentMethod ], $ this ->model ->getList ($ maskedCartId ));
83
+ $ paymentMethod = $ this ->getMock ('Magento\Quote\Api\Data\PaymentMethodInterface ' , [], [], '' , false );
84
+ $ this ->paymentMethodManagementMock ->expects ($ this ->once ())->method ('getList ' )->willReturn ([$ paymentMethod ]);
85
+ $ this ->assertEquals ([$ paymentMethod ], $ this ->model ->getList ($ this ->maskedCartId ));
118
86
}
119
87
120
88
public function testSetSimpleProduct ()
121
89
{
122
- $ maskedCartId = 'f216207248d65c789b17be8545e0aa73 ' ;
123
- $ cartId = 100 ;
124
90
$ paymentId = 20 ;
125
- $ methodData = ['method ' => 'data ' ];
126
- $ paymentMethod = 'checkmo ' ;
127
-
128
- $ this ->quoteIdMaskFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteIdMaskMock );
129
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
130
- ->method ('load ' )
131
- ->with ($ maskedCartId , 'masked_id ' )
132
- ->willReturn ($ this ->quoteIdMaskMock );
133
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
134
- ->method ('getId ' )
135
- ->willReturn ($ cartId );
136
-
137
- $ quoteMock = $ this ->getMock (
138
- '\Magento\Quote\Model\Quote ' ,
139
- ['getPayment ' , 'isVirtual ' , 'getShippingAddress ' , 'setTotalsCollectedFlag ' , 'collectTotals ' , 'save ' ],
140
- [],
141
- '' ,
142
- false
143
- );
144
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('getActive ' )->with ($ cartId )->willReturn ($ quoteMock );
145
-
146
- $ methodMock = $ this ->getMock ('Magento\Quote\Model\Quote\Payment ' , ['setChecks ' , 'getData ' ], [], '' , false );
147
- $ methodMock ->expects ($ this ->once ())
148
- ->method ('setChecks ' )
149
- ->with ([
150
- \Magento \Payment \Model \Method \AbstractMethod::CHECK_USE_CHECKOUT ,
151
- \Magento \Payment \Model \Method \AbstractMethod::CHECK_USE_FOR_COUNTRY ,
152
- \Magento \Payment \Model \Method \AbstractMethod::CHECK_USE_FOR_CURRENCY ,
153
- \Magento \Payment \Model \Method \AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX ,
154
- ])
155
- ->willReturnSelf ();
156
- $ methodMock ->expects ($ this ->once ())->method ('getData ' )->willReturn ($ methodData );
157
-
158
- $ paymentMock = $ this ->getMock (
159
- 'Magento\Quote\Model\Quote\Payment ' ,
160
- ['importData ' , 'getMethod ' , 'getMethodInstance ' , 'getId ' ],
161
- [],
162
- '' ,
163
- false
164
- );
165
- $ paymentMock ->expects ($ this ->once ())->method ('importData ' )->with ($ methodData )->willReturnSelf ();
166
- $ paymentMock ->expects ($ this ->once ())->method ('getMethod ' )->willReturn ($ paymentMethod );
167
-
168
- $ shippingAddressMock = $ this ->getMock (
169
- 'Magento\Quote\Model\Quote\Address ' ,
170
- ['getCountryId ' , 'setPaymentMethod ' ],
171
- [],
172
- '' ,
173
- false
174
- );
175
- $ shippingAddressMock ->expects ($ this ->once ())->method ('getCountryId ' )->willReturn (100 );
176
- $ shippingAddressMock ->expects ($ this ->once ())
177
- ->method ('setPaymentMethod ' )
178
- ->with ($ paymentMethod )
179
- ->willReturnSelf ();
180
-
181
- $ quoteMock ->expects ($ this ->exactly (2 ))->method ('getPayment ' )->willReturn ($ paymentMock );
182
- $ quoteMock ->expects ($ this ->exactly (2 ))->method ('isVirtual ' )->willReturn (false );
183
- $ quoteMock ->expects ($ this ->exactly (4 ))->method ('getShippingAddress ' )->willReturn ($ shippingAddressMock );
184
-
185
- $ methodInstance = $ this ->getMock ('\Magento\Payment\Model\Checks\PaymentMethodChecksInterface ' );
186
- $ paymentMock ->expects ($ this ->once ())->method ('getMethodInstance ' )->willReturn ($ methodInstance );
187
-
188
- $ this ->zeroTotalMock ->expects ($ this ->once ())
189
- ->method ('isApplicable ' )
190
- ->with ($ methodInstance , $ quoteMock )
191
- ->willReturn (true );
192
-
193
- $ quoteMock ->expects ($ this ->once ())->method ('setTotalsCollectedFlag ' )->with (false )->willReturnSelf ();
194
- $ quoteMock ->expects ($ this ->once ())->method ('collectTotals ' )->willReturnSelf ();
195
- $ quoteMock ->expects ($ this ->once ())->method ('save ' )->willReturnSelf ();
196
-
197
- $ paymentMock ->expects ($ this ->once ())->method ('getId ' )->willReturn ($ paymentId );
198
- $ this ->assertEquals ($ paymentId , $ this ->model ->set ($ maskedCartId , $ methodMock ));
91
+ $ this ->paymentMethodManagementMock ->expects ($ this ->once ())->method ('set ' )->willReturn ($ paymentId );
92
+ $ this ->assertEquals ($ paymentId , $ this ->model ->set ($ this ->maskedCartId , $ this ->paymentMock ));
199
93
}
200
94
}
0 commit comments