88namespace Magento \PaypalGraphQl \Model \Resolver \Customer ;
99
1010use Magento \Framework \App \ProductMetadataInterface ;
11- use Magento \Framework \App \Request \Http ;
1211use Magento \Framework \DataObject ;
1312use Magento \Framework \Math \Random ;
1413use Magento \Framework \Serialize \SerializerInterface ;
15- use Magento \GraphQl \Controller \GraphQl ;
1614use Magento \GraphQl \Quote \GetMaskedQuoteIdByReservedOrderId ;
15+ use Magento \GraphQl \Service \GraphQlRequest ;
16+ use Magento \Integration \Model \Oauth \Token ;
1717use Magento \Paypal \Model \Payflow \Request ;
1818use Magento \Paypal \Model \Payflow \Service \Gateway ;
1919use Magento \Quote \Model \QuoteIdToMaskedQuoteId ;
2222use Magento \TestFramework \ObjectManager ;
2323use PHPUnit \Framework \MockObject \MockObject ;
2424use PHPUnit \Framework \TestCase ;
25+ use Magento \Paypal \Model \Payflow \RequestFactory ;
2526
2627/**
2728 * End to end place order test using payflow_link via graphql endpoint for registered customer
3132 */
3233class PlaceOrderWithPayflowLinkTest extends TestCase
3334{
34- /**
35- * @var Http
36- */
37- private $ request ;
35+ /** @var GraphQlRequest */
36+ private $ graphQlRequest ;
3837
39- /**
40- * @var SerializerInterface
41- */
38+ /** @var SerializerInterface */
4239 private $ json ;
4340
44- /**
45- * @var QuoteIdToMaskedQuoteId
46- */
41+ /** @var QuoteIdToMaskedQuoteId */
4742 private $ quoteIdToMaskedId ;
4843
49- /** @var GetMaskedQuoteIdByReservedOrderId */
44+ /** @var GetMaskedQuoteIdByReservedOrderId */
5045 private $ getMaskedQuoteIdByReservedOrderId ;
5146
52- /** @var ObjectManager */
53- protected $ objectManager ;
54-
55- /** @var GraphQl */
56- protected $ graphqlController ;
47+ /** @var ObjectManager */
48+ private $ objectManager ;
5749
58- /** @var Gateway|MockObject */
50+ /** @var Gateway|MockObject */
5951 private $ gateway ;
6052
61- /** @var Random|MockObject */
53+ /** @var Random|MockObject */
6254 private $ mathRandom ;
6355
64- /** @var Request|MockObject */
56+ /** @var Request|MockObject */
6557 private $ payflowRequest ;
6658
6759 protected function setUp ()
6860 {
6961 parent ::setUp ();
7062
7163 $ this ->objectManager = Bootstrap::getObjectManager ();
72- $ this ->request = $ this ->objectManager ->create (Http::class);
7364 $ this ->json = $ this ->objectManager ->get (SerializerInterface::class);
7465 $ this ->getMaskedQuoteIdByReservedOrderId = $ this ->objectManager ->get (GetMaskedQuoteIdByReservedOrderId::class);
7566 $ this ->quoteIdToMaskedId = $ this ->objectManager ->get (QuoteIdToMaskedQuoteId::class);
76-
77- $ this ->graphqlController = $ this ->objectManager ->get (GraphQl::class);
67+ $ this ->graphQlRequest = $ this ->objectManager ->create (GraphQlRequest::class);
7868
7969 $ this ->mathRandom = $ this ->getMockBuilder (Random::class)
8070 ->getMock ();
@@ -83,12 +73,12 @@ protected function setUp()
8373 ->setMethods (['postRequest ' ])
8474 ->getMock ();
8575
86- $ requestFactory = $ this ->getMockBuilder (\ Magento \ Paypal \ Model \ Payflow \ RequestFactory::class)
76+ $ requestFactory = $ this ->getMockBuilder (RequestFactory::class)
8777 ->setMethods (['create ' ])
8878 ->disableOriginalConstructor ()
8979 ->getMock ();
9080
91- $ this ->payflowRequest = $ this ->getMockBuilder (\ Magento \ Paypal \ Model \ Payflow \ Request::class)
81+ $ this ->payflowRequest = $ this ->getMockBuilder (Request::class)
9282 ->disableOriginalConstructor ()
9383 ->getMock ();
9484 $ requestFactory ->expects ($ this ->any ())->method ('create ' )->will ($ this ->returnValue ($ this ->payflowRequest ));
@@ -110,7 +100,6 @@ protected function setUp()
110100 * @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
111101 * @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
112102 * @return void
113- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
114103 */
115104 public function testResolvePlaceOrderWithPayflowLinkForCustomer (): void
116105 {
@@ -150,22 +139,6 @@ public function testResolvePlaceOrderWithPayflowLinkForCustomer(): void
150139}
151140QUERY ;
152141
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-
169142 $ productMetadata = ObjectManager::getInstance ()->get (ProductMetadataInterface::class);
170143 $ button = 'Magento_Cart_ ' . $ productMetadata ->getEdition ();
171144
@@ -197,24 +170,29 @@ public function testResolvePlaceOrderWithPayflowLinkForCustomer(): void
197170 $ this ->returnSelf ()
198171 ],
199172 ['USER1 ' , 1 , $ this ->returnSelf ()],
200- ['USER2 ' , '4b102efb018ad34bacea669f401fc8cb ' , $ this ->returnSelf ()]
173+ ['USER2 ' , 'USER2SilentPostHash ' , $ this ->returnSelf ()]
201174 );
202175
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 ();
205179
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 ());
206187 $ this ->assertArrayNotHasKey ('errors ' , $ responseData );
207188 $ this ->assertArrayHasKey ('data ' , $ responseData );
208-
209189 $ this ->assertEquals (
210190 $ paymentMethod ,
211191 $ responseData ['data ' ]['setPaymentMethodOnCart ' ]['cart ' ]['selected_payment_method ' ]['code ' ]
212192 );
213-
214193 $ this ->assertTrue (
215194 isset ($ responseData ['data ' ]['placeOrder ' ]['order ' ]['order_id ' ])
216195 );
217-
218196 $ this ->assertEquals (
219197 'test_quote ' ,
220198 $ responseData ['data ' ]['placeOrder ' ]['order ' ]['order_id ' ]
0 commit comments