8
8
namespace Magento \PaypalGraphQl \Model \Resolver \Customer ;
9
9
10
10
use Magento \Framework \App \ProductMetadataInterface ;
11
- use Magento \Framework \App \Request \Http ;
12
11
use Magento \Framework \DataObject ;
13
12
use Magento \Framework \Math \Random ;
14
13
use Magento \Framework \Serialize \SerializerInterface ;
15
- use Magento \GraphQl \Controller \GraphQl ;
16
14
use Magento \GraphQl \Quote \GetMaskedQuoteIdByReservedOrderId ;
15
+ use Magento \GraphQl \Service \GraphQlRequest ;
16
+ use Magento \Integration \Model \Oauth \Token ;
17
17
use Magento \Paypal \Model \Payflow \Request ;
18
18
use Magento \Paypal \Model \Payflow \Service \Gateway ;
19
19
use Magento \Quote \Model \QuoteIdToMaskedQuoteId ;
22
22
use Magento \TestFramework \ObjectManager ;
23
23
use PHPUnit \Framework \MockObject \MockObject ;
24
24
use PHPUnit \Framework \TestCase ;
25
+ use Magento \Paypal \Model \Payflow \RequestFactory ;
25
26
26
27
/**
27
28
* End to end place order test using payflow_link via graphql endpoint for registered customer
31
32
*/
32
33
class PlaceOrderWithPayflowLinkTest extends TestCase
33
34
{
34
- /**
35
- * @var Http
36
- */
37
- private $ request ;
35
+ /** @var GraphQlRequest */
36
+ private $ graphQlRequest ;
38
37
39
- /**
40
- * @var SerializerInterface
41
- */
38
+ /** @var SerializerInterface */
42
39
private $ json ;
43
40
44
- /**
45
- * @var QuoteIdToMaskedQuoteId
46
- */
41
+ /** @var QuoteIdToMaskedQuoteId */
47
42
private $ quoteIdToMaskedId ;
48
43
49
- /** @var GetMaskedQuoteIdByReservedOrderId */
44
+ /** @var GetMaskedQuoteIdByReservedOrderId */
50
45
private $ getMaskedQuoteIdByReservedOrderId ;
51
46
52
- /** @var ObjectManager */
53
- protected $ objectManager ;
54
-
55
- /** @var GraphQl */
56
- protected $ graphqlController ;
47
+ /** @var ObjectManager */
48
+ private $ objectManager ;
57
49
58
- /** @var Gateway|MockObject */
50
+ /** @var Gateway|MockObject */
59
51
private $ gateway ;
60
52
61
- /** @var Random|MockObject */
53
+ /** @var Random|MockObject */
62
54
private $ mathRandom ;
63
55
64
- /** @var Request|MockObject */
56
+ /** @var Request|MockObject */
65
57
private $ payflowRequest ;
66
58
67
59
protected function setUp ()
68
60
{
69
61
parent ::setUp ();
70
62
71
63
$ this ->objectManager = Bootstrap::getObjectManager ();
72
- $ this ->request = $ this ->objectManager ->create (Http::class);
73
64
$ this ->json = $ this ->objectManager ->get (SerializerInterface::class);
74
65
$ this ->getMaskedQuoteIdByReservedOrderId = $ this ->objectManager ->get (GetMaskedQuoteIdByReservedOrderId::class);
75
66
$ this ->quoteIdToMaskedId = $ this ->objectManager ->get (QuoteIdToMaskedQuoteId::class);
76
-
77
- $ this ->graphqlController = $ this ->objectManager ->get (GraphQl::class);
67
+ $ this ->graphQlRequest = $ this ->objectManager ->create (GraphQlRequest::class);
78
68
79
69
$ this ->mathRandom = $ this ->getMockBuilder (Random::class)
80
70
->getMock ();
@@ -83,12 +73,12 @@ protected function setUp()
83
73
->setMethods (['postRequest ' ])
84
74
->getMock ();
85
75
86
- $ requestFactory = $ this ->getMockBuilder (\ Magento \ Paypal \ Model \ Payflow \ RequestFactory::class)
76
+ $ requestFactory = $ this ->getMockBuilder (RequestFactory::class)
87
77
->setMethods (['create ' ])
88
78
->disableOriginalConstructor ()
89
79
->getMock ();
90
80
91
- $ this ->payflowRequest = $ this ->getMockBuilder (\ Magento \ Paypal \ Model \ Payflow \ Request::class)
81
+ $ this ->payflowRequest = $ this ->getMockBuilder (Request::class)
92
82
->disableOriginalConstructor ()
93
83
->getMock ();
94
84
$ requestFactory ->expects ($ this ->any ())->method ('create ' )->will ($ this ->returnValue ($ this ->payflowRequest ));
@@ -110,7 +100,6 @@ protected function setUp()
110
100
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
111
101
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
112
102
* @return void
113
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
114
103
*/
115
104
public function testResolvePlaceOrderWithPayflowLinkForCustomer (): void
116
105
{
@@ -150,22 +139,6 @@ public function testResolvePlaceOrderWithPayflowLinkForCustomer(): void
150
139
}
151
140
QUERY ;
152
141
153
- $ postData = $ this ->json ->serialize (['query ' => $ query ]);
154
- $ this ->request ->setPathInfo ('/graphql ' );
155
- $ this ->request ->setMethod ('POST ' );
156
- $ this ->request ->setContent ($ postData );
157
-
158
- /** @var \Magento\Integration\Model\Oauth\Token $tokenModel */
159
- $ tokenModel = $ this ->objectManager ->create (\Magento \Integration \Model \Oauth \Token::class);
160
- $ customerToken = $ tokenModel ->createCustomerToken (1 )->getToken ();
161
- /** @var \Magento\Framework\Webapi\Request $webApiRequest */
162
- $ webApiRequest = $ this ->objectManager ->get (\Magento \Framework \Webapi \Request::class);
163
- $ webApiRequest ->getHeaders ()
164
- ->addHeaderLine ('Content-Type ' , 'application/json ' )
165
- ->addHeaderLine ('Accept ' , 'application/json ' )
166
- ->addHeaderLine ('Authorization ' , 'Bearer ' . $ customerToken );
167
- $ this ->request ->setHeaders ($ webApiRequest ->getHeaders ());
168
-
169
142
$ productMetadata = ObjectManager::getInstance ()->get (ProductMetadataInterface::class);
170
143
$ button = 'Magento_Cart_ ' . $ productMetadata ->getEdition ();
171
144
@@ -197,24 +170,29 @@ public function testResolvePlaceOrderWithPayflowLinkForCustomer(): void
197
170
$ this ->returnSelf ()
198
171
],
199
172
['USER1 ' , 1 , $ this ->returnSelf ()],
200
- ['USER2 ' , '4b102efb018ad34bacea669f401fc8cb ' , $ this ->returnSelf ()]
173
+ ['USER2 ' , 'USER2SilentPostHash ' , $ this ->returnSelf ()]
201
174
);
202
175
203
- $ response = $ this ->graphqlController ->dispatch ($ this ->request );
204
- $ responseData = $ this ->json ->unserialize ($ response ->getContent ());
176
+ /** @var Token $tokenModel */
177
+ $ tokenModel = $ this ->objectManager ->create (Token::class);
178
+ $ customerToken = $ tokenModel ->createCustomerToken (1 )->getToken ();
205
179
180
+ $ requestHeaders = [
181
+ 'Content-Type ' => 'application/json ' ,
182
+ 'Accept ' => 'application/json ' ,
183
+ 'Authorization ' => 'Bearer ' . $ customerToken
184
+ ];
185
+ $ response = $ this ->graphQlRequest ->send ($ query , [], '' , $ requestHeaders );
186
+ $ responseData = $ this ->json ->unserialize ($ response ->getContent ());
206
187
$ this ->assertArrayNotHasKey ('errors ' , $ responseData );
207
188
$ this ->assertArrayHasKey ('data ' , $ responseData );
208
-
209
189
$ this ->assertEquals (
210
190
$ paymentMethod ,
211
191
$ responseData ['data ' ]['setPaymentMethodOnCart ' ]['cart ' ]['selected_payment_method ' ]['code ' ]
212
192
);
213
-
214
193
$ this ->assertTrue (
215
194
isset ($ responseData ['data ' ]['placeOrder ' ]['order ' ]['order_id ' ])
216
195
);
217
-
218
196
$ this ->assertEquals (
219
197
'test_quote ' ,
220
198
$ responseData ['data ' ]['placeOrder ' ]['order ' ]['order_id ' ]
0 commit comments