5
5
*/
6
6
namespace Magento \Paypal \Controller ;
7
7
8
+ use Magento \Checkout \Model \Session ;
9
+ use Magento \Framework \Session \Generic as GenericSession ;
10
+ use Magento \Paypal \Model \Api \Nvp ;
11
+ use Magento \Paypal \Model \Api \Type \Factory as ApiFactory ;
12
+ use Magento \Paypal \Model \Session as PaypalSession ;
13
+ use Magento \Quote \Model \Quote ;
14
+ use Magento \TestFramework \Helper \Bootstrap ;
15
+
16
+ /**
17
+ * Tests of Paypal Express actions.
18
+ *
19
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
20
+ */
8
21
class ExpressTest extends \Magento \TestFramework \TestCase \AbstractController
9
22
{
10
23
/**
@@ -13,10 +26,10 @@ class ExpressTest extends \Magento\TestFramework\TestCase\AbstractController
13
26
*/
14
27
public function testReviewAction ()
15
28
{
16
- $ quote = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->create (' Magento\ Quote\Model\Quote ' );
29
+ $ quote = Bootstrap::getObjectManager ()->create (Quote::class );
17
30
$ quote ->load ('test01 ' , 'reserved_order_id ' );
18
- \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->get (
19
- ' Magento\Checkout\Model\ Session'
31
+ Bootstrap::getObjectManager ()->get (
32
+ Session::class
20
33
)->setQuoteId (
21
34
$ quote ->getId ()
22
35
);
@@ -30,16 +43,16 @@ public function testReviewAction()
30
43
}
31
44
32
45
/**
33
- * @magentoDataFixture Magento/Paypal/_files/quote_payment_express.php
46
+ * @magentoDataFixture Magento/Paypal/_files/quote_payment_express.php
34
47
* @magentoConfigFixture current_store paypal/general/business_account merchant_2012050718_biz@example.com
35
48
*/
36
49
public function testCancelAction ()
37
50
{
38
- $ quote = $ this ->_objectManager ->create (' Magento\ Quote\Model\Quote ' );
51
+ $ quote = $ this ->_objectManager ->create (Quote::class );
39
52
$ quote ->load ('100000002 ' , 'reserved_order_id ' );
40
- $ order = $ this ->_objectManager ->create (' Magento\Sales\Model\Order ' );
53
+ $ order = $ this ->_objectManager ->create (\ Magento \Sales \Model \Order::class );
41
54
$ order ->load ('100000002 ' , 'increment_id ' );
42
- $ session = $ this ->_objectManager ->get (' Magento\Checkout\Model\ Session' );
55
+ $ session = $ this ->_objectManager ->get (Session::class );
43
56
$ session ->setLoadInactive (true );
44
57
$ session ->setLastRealOrderId (
45
58
$ order ->getRealOrderId ()
@@ -50,8 +63,8 @@ public function testCancelAction()
50
63
)->setQuoteId (
51
64
$ order ->getQuoteId ()
52
65
);
53
- /** @var $paypalSession \Magento\Framework\Session\Generic */
54
- $ paypalSession = $ this ->_objectManager ->get (' Magento\Paypal\Model\Session ' );
66
+ /** @var GenericSession $paypalSession */
67
+ $ paypalSession = $ this ->_objectManager ->get (PaypalSession::class );
55
68
$ paypalSession ->setExpressCheckoutToken ('token ' );
56
69
57
70
$ this ->dispatch ('paypal/express/cancel ' );
@@ -79,18 +92,18 @@ public function testStartActionCustomerToQuote()
79
92
80
93
/** Preconditions */
81
94
/** @var \Magento\Customer\Model\Session $customerSession */
82
- $ customerSession = $ this ->_objectManager ->get (' Magento\Customer\Model\Session ' );
95
+ $ customerSession = $ this ->_objectManager ->get (\ Magento \Customer \Model \Session::class );
83
96
/** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
84
- $ customerRepository = $ this ->_objectManager ->get (' Magento\Customer\Api\CustomerRepositoryInterface ' );
97
+ $ customerRepository = $ this ->_objectManager ->get (\ Magento \Customer \Api \CustomerRepositoryInterface::class );
85
98
$ customerData = $ customerRepository ->getById ($ fixtureCustomerId );
86
99
$ customerSession ->setCustomerDataObject ($ customerData );
87
100
88
- /** @var \Magento\Quote\Model\ Quote $quote */
89
- $ quote = $ this ->_objectManager ->create (' Magento\ Quote\Model\Quote ' );
101
+ /** @var Quote $quote */
102
+ $ quote = $ this ->_objectManager ->create (Quote::class );
90
103
$ quote ->load ($ fixtureQuoteReserveId , 'reserved_order_id ' );
91
104
92
- /** @var \Magento\Checkout\Model\ Session $checkoutSession */
93
- $ checkoutSession = $ this ->_objectManager ->get (' Magento\Checkout\Model\ Session' );
105
+ /** @var Session $checkoutSession */
106
+ $ checkoutSession = $ this ->_objectManager ->get (Session::class );
94
107
$ checkoutSession ->setQuoteId ($ quote ->getId ());
95
108
96
109
/** Preconditions check */
@@ -109,8 +122,8 @@ public function testStartActionCustomerToQuote()
109
122
$ this ->dispatch ('paypal/express/start ' );
110
123
111
124
/** Check if customer data was copied to quote correctly */
112
- /** @var \Magento\Quote\Model\ Quote $updatedQuote */
113
- $ updatedQuote = $ this ->_objectManager ->create (' Magento\ Quote\Model\Quote ' );
125
+ /** @var Quote $updatedQuote */
126
+ $ updatedQuote = $ this ->_objectManager ->create (Quote::class );
114
127
$ updatedQuote ->load ($ fixtureQuoteReserveId , 'reserved_order_id ' );
115
128
$ this ->assertEquals (
116
129
$ fixtureCustomerEmail ,
@@ -123,4 +136,118 @@ public function testStartActionCustomerToQuote()
123
136
"Customer first name in quote is invalid. "
124
137
);
125
138
}
139
+
140
+ /**
141
+ * Test return action with configurable product.
142
+ *
143
+ * @magentoDataFixture Magento/Paypal/_files/quote_express_configurable.php
144
+ * @magentoDbIsolation enabled
145
+ * @magentoAppIsolation enabled
146
+ */
147
+ public function testReturnAction ()
148
+ {
149
+ /** @var Quote $quote */
150
+ $ quote = $ this ->_objectManager ->create (Quote::class);
151
+ $ quote ->load ('test_cart_with_configurable ' , 'reserved_order_id ' );
152
+
153
+ $ payment = $ quote ->getPayment ();
154
+ $ payment ->setMethod (\Magento \Paypal \Model \Config::METHOD_WPP_EXPRESS )
155
+ ->setAdditionalInformation (\Magento \Paypal \Model \Express \Checkout::PAYMENT_INFO_TRANSPORT_PAYER_ID , 123 );
156
+
157
+ $ quote ->save ();
158
+
159
+ $ this ->_objectManager ->removeSharedInstance (Session::class);
160
+ $ session = $ this ->_objectManager ->get (Session::class);
161
+ $ session ->setQuoteId ($ quote ->getId ());
162
+
163
+ $ nvpMethods = [
164
+ 'setToken ' ,
165
+ 'setPayerId ' ,
166
+ 'setAmount ' ,
167
+ 'setPaymentAction ' ,
168
+ 'setNotifyUrl ' ,
169
+ 'setInvNum ' ,
170
+ 'setCurrencyCode ' ,
171
+ 'setPaypalCart ' ,
172
+ 'setIsLineItemsEnabled ' ,
173
+ 'setAddress ' ,
174
+ 'setBillingAddress ' ,
175
+ 'callDoExpressCheckoutPayment ' ,
176
+ 'callGetExpressCheckoutDetails ' ,
177
+ ];
178
+
179
+ $ nvpMock = $ this ->getMockBuilder (Nvp::class)
180
+ ->setMethods ($ nvpMethods )
181
+ ->disableOriginalConstructor ()
182
+ ->getMock ();
183
+
184
+ foreach ($ nvpMethods as $ method ) {
185
+ $ nvpMock ->method ($ method )
186
+ ->willReturnSelf ();
187
+ }
188
+
189
+ $ exportedBillingAddress = $ this ->getExportedAddressFixture ($ quote ->getBillingAddress ()->toArray ());
190
+ $ nvpMock ->setData ('exported_billing_address ' , $ exportedBillingAddress );
191
+
192
+ $ apiFactoryMock = $ this ->getMockBuilder (ApiFactory::class)
193
+ ->disableOriginalConstructor ()
194
+ ->setMethods (['create ' ])
195
+ ->getMock ();
196
+
197
+ $ apiFactoryMock ->method ('create ' )
198
+ ->with (Nvp::class)
199
+ ->willReturn ($ nvpMock );
200
+
201
+ $ this ->_objectManager ->addSharedInstance ($ apiFactoryMock , ApiFactory::class);
202
+
203
+ $ sessionMock = $ this ->getMockBuilder (GenericSession::class)
204
+ ->setMethods (['getExpressCheckoutToken ' ])
205
+ ->setConstructorArgs (
206
+ [
207
+ $ this ->_objectManager ->get (\Magento \Framework \App \Request \Http::class),
208
+ $ this ->_objectManager ->get (\Magento \Framework \Session \SidResolverInterface::class),
209
+ $ this ->_objectManager ->get (\Magento \Framework \Session \Config \ConfigInterface::class),
210
+ $ this ->_objectManager ->get (\Magento \Framework \Session \SaveHandlerInterface::class),
211
+ $ this ->_objectManager ->get (\Magento \Framework \Session \ValidatorInterface::class),
212
+ $ this ->_objectManager ->get (\Magento \Framework \Session \StorageInterface::class),
213
+ $ this ->_objectManager ->get (\Magento \Framework \Stdlib \CookieManagerInterface::class),
214
+ $ this ->_objectManager ->get (\Magento \Framework \Stdlib \Cookie \CookieMetadataFactory::class),
215
+ $ this ->_objectManager ->get (\Magento \Framework \App \State::class),
216
+ ]
217
+ )
218
+ ->getMock ();
219
+
220
+ $ sessionMock ->method ('getExpressCheckoutToken ' )
221
+ ->willReturn (true );
222
+
223
+ $ this ->_objectManager ->addSharedInstance ($ sessionMock , PaypalSession::class);
224
+
225
+ $ this ->dispatch ('paypal/express/returnAction ' );
226
+ $ this ->assertRedirect ($ this ->stringContains ('checkout/onepage/success ' ));
227
+
228
+ $ this ->_objectManager ->removeSharedInstance (ApiFactory::class);
229
+ $ this ->_objectManager ->removeSharedInstance (PaypalSession::class);
230
+ }
231
+
232
+ /**
233
+ * Prepare fixture for exported address.
234
+ *
235
+ * @param array $addressData
236
+ * @return \Magento\Framework\DataObject
237
+ */
238
+ private function getExportedAddressFixture (array $ addressData )
239
+ {
240
+ $ addressDataKeys = ['firstname ' , 'lastname ' , 'street ' , 'city ' , 'telephone ' ];
241
+ $ result = [];
242
+ foreach ($ addressDataKeys as $ key ) {
243
+ if (isset ($ addressData [$ key ])) {
244
+ $ result [$ key ] = 'exported ' . $ addressData [$ key ];
245
+ }
246
+ }
247
+ $ fixture = new \Magento \Framework \DataObject ($ result );
248
+ $ fixture ->setExportedKeys ($ addressDataKeys );
249
+ $ fixture ->setData ('note ' , 'note ' );
250
+
251
+ return $ fixture ;
252
+ }
126
253
}
0 commit comments