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