Skip to content

Commit 808831b

Browse files
committed
Merge remote-tracking branch 'performance/MC-15763-develop' into MC-15763-develop
2 parents a960744 + dab7659 commit 808831b

14 files changed

+713
-5
lines changed

app/code/Magento/Theme/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Disallow: /*SID=
7070
<move_inline_to_bottom>0</move_inline_to_bottom>
7171
</js>
7272
<css>
73-
<use_css_critical_path>1</use_css_critical_path>
73+
<use_css_critical_path>0</use_css_critical_path>
7474
</css>
7575
</dev>
7676
</default>

dev/tests/functional/tests/app/Magento/Customer/Test/Block/Account/AuthenticationPopup.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,6 @@ public function loginCustomer(Customer $customer)
7373
$this->fill($customer);
7474
$this->_rootElement->find($this->login)->click();
7575
$this->waitForElementNotVisible($this->loadingMask);
76+
sleep(10);
7677
}
7778
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AuthorizenetGraphQl\Model\Resolver\Customer;
9+
10+
use Magento\Framework\App\Request\Http;
11+
use Magento\Framework\Serialize\SerializerInterface;
12+
use Magento\GraphQl\Controller\GraphQl;
13+
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
14+
use Magento\Integration\Api\CustomerTokenServiceInterface;
15+
use Magento\Framework\Webapi\Request;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
use Magento\Framework\HTTP\ZendClient;
18+
use Magento\Framework\HTTP\ZendClientFactory;
19+
use Magento\TestFramework\ObjectManager;
20+
use PHPUnit\Framework\MockObject\Builder\InvocationMocker;
21+
use Magento\Payment\Gateway\Data\PaymentDataObjectFactory;
22+
use PHPUnit\Framework\MockObject\MockObject;
23+
use Magento\Quote\Model\Quote\PaymentFactory;
24+
use PHPUnit\Framework\TestCase;
25+
use Zend_Http_Response;
26+
27+
/**
28+
* Tests end to end Place Order process for customer via authorizeNet
29+
*
30+
* @magentoAppArea graphql
31+
* @magentoDbIsolation disabled
32+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
33+
*/
34+
class PlaceOrderWithAuthorizeNetTest extends TestCase
35+
{
36+
const CONTENT_TYPE = 'application/json';
37+
38+
/** @var ObjectManager */
39+
private $objectManager;
40+
41+
/** @var GetMaskedQuoteIdByReservedOrderId */
42+
private $getMaskedQuoteIdByReservedOrderId;
43+
44+
/** @var SerializerInterface */
45+
private $jsonSerializer;
46+
47+
/** @var Http */
48+
private $request;
49+
50+
/** @var ZendClient|MockObject|InvocationMocker */
51+
private $clientMock;
52+
53+
/** @var CustomerTokenServiceInterface */
54+
private $customerTokenService;
55+
56+
/** @var Zend_Http_Response */
57+
protected $responseMock;
58+
59+
/** @var PaymentFactory */
60+
private $paymentFactory;
61+
62+
protected function setUp() : void
63+
{
64+
$this->objectManager = Bootstrap::getObjectManager();
65+
$this->jsonSerializer = $this->objectManager->get(SerializerInterface::class);
66+
$this->request = $this->objectManager->get(Http::class);
67+
$this->getMaskedQuoteIdByReservedOrderId = $this->objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
68+
$this->customerTokenService = $this->objectManager->get(CustomerTokenServiceInterface::class);
69+
$this->clientMock = $this->createMock(ZendClient::class);
70+
$this->responseMock = $this->createMock(Zend_Http_Response::class);
71+
$this->clientMock->method('request')
72+
->willReturn($this->responseMock);
73+
$this->clientMock->method('setUri')
74+
->with('https://apitest.authorize.net/xml/v1/request.api');
75+
$clientFactoryMock = $this->createMock(ZendClientFactory::class);
76+
$clientFactoryMock->method('create')
77+
->willReturn($this->clientMock);
78+
/** @var PaymentDataObjectFactory $paymentFactory */
79+
$this->paymentFactory = $this->objectManager->get(PaymentDataObjectFactory::class);
80+
$this->objectManager->addSharedInstance($clientFactoryMock, ZendClientFactory::class);
81+
}
82+
83+
/**
84+
* @magentoConfigFixture default_store payment/authorizenet_acceptjs/active 1
85+
* @magentoConfigFixture default_store payment/authorizenet_acceptjs/environment sandbox
86+
* @magentoConfigFixture default_store payment/authorizenet_acceptjs/login someusername
87+
* @magentoConfigFixture default_store payment/authorizenet_acceptjs/trans_key somepassword
88+
* @magentoConfigFixture default_store payment/authorizenet_acceptjs/trans_signature_key abc
89+
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
90+
* @magentoDataFixture Magento/Customer/_files/customer.php
91+
* @magentoDataFixture Magento/AuthorizenetGraphQl/_files/simple_product_authorizenet.php
92+
* @magentoDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
93+
* @magentoDataFixture Magento/AuthorizenetGraphQl/_files/set_new_shipping_address_authorizenet.php
94+
* @magentoDataFixture Magento/AuthorizenetGraphQl/_files/set_new_billing_address_authorizenet.php
95+
* @magentoDataFixture Magento/AuthorizenetGraphQl/_files/add_simple_products_authorizenet.php
96+
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
97+
*/
98+
public function testDispatchToPlaceOrderWithRegisteredCustomer(): void
99+
{
100+
$paymentMethod = 'authorizenet_acceptjs';
101+
$cartId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
102+
$query
103+
= <<<QUERY
104+
mutation {
105+
setPaymentMethodOnCart(input: {
106+
cart_id: "$cartId"
107+
payment_method: {
108+
code: "$paymentMethod"
109+
additional_data:
110+
{authorizenet_acceptjs:
111+
{opaque_data_descriptor: "mydescriptor",
112+
opaque_data_value: "myvalue",
113+
cc_last_4: 1111}}
114+
}
115+
}) {
116+
cart {
117+
selected_payment_method {
118+
code
119+
}
120+
}
121+
}
122+
placeOrder(input: {cart_id: "$cartId"}) {
123+
order {
124+
order_id
125+
}
126+
}
127+
}
128+
QUERY;
129+
$postData = [
130+
'query' => $query,
131+
'variables' => null,
132+
'operationName' => null
133+
];
134+
$this->request->setPathInfo('/graphql');
135+
$this->request->setMethod('POST');
136+
$this->request->setContent($this->jsonSerializer->serialize($postData));
137+
$customerToken = $this->customerTokenService->createCustomerAccessToken('[email protected]', 'password');
138+
$bearerCustomerToken = 'Bearer ' . $customerToken;
139+
$webApiRequest = $this->objectManager->get(Request::class);
140+
$webApiRequest->getHeaders()->addHeaderLine('Content-Type', 'application/json')
141+
->addHeaderLine('Accept', 'application/json')
142+
->addHeaderLine('Authorization', $bearerCustomerToken);
143+
$this->request->setHeaders($webApiRequest->getHeaders());
144+
$graphql = $this->objectManager->get(\Magento\GraphQl\Controller\GraphQl::class);
145+
146+
// phpcs:ignore Magento2.Security.IncludeFile
147+
$expectedRequest = include __DIR__ . '/../../../_files/request_authorize_customer.php';
148+
// phpcs:ignore Magento2.Security.IncludeFile
149+
$authorizeResponse = include __DIR__ . '/../../../_files/response_authorize.php';
150+
151+
$this->clientMock->method('setRawData')
152+
->with(json_encode($expectedRequest), 'application/json');
153+
154+
$this->responseMock->method('getBody')->willReturn(json_encode($authorizeResponse));
155+
156+
$response = $graphql->dispatch($this->request);
157+
$responseData = $this->jsonSerializer->unserialize($response->getContent());
158+
159+
$this->assertArrayNotHasKey('errors', $responseData, 'Response has errors');
160+
$this->assertTrue(
161+
isset($responseData['data']['setPaymentMethodOnCart']['cart']['selected_payment_method']['code'])
162+
);
163+
$this->assertEquals(
164+
$paymentMethod,
165+
$responseData['data']['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']
166+
);
167+
168+
$this->assertTrue(
169+
isset($responseData['data']['placeOrder']['order']['order_id'])
170+
);
171+
172+
$this->assertEquals(
173+
'test_quote',
174+
$responseData['data']['placeOrder']['order']['order_id']
175+
);
176+
}
177+
178+
protected function tearDown()
179+
{
180+
$this->objectManager->removeSharedInstance(ZendClientFactory::class);
181+
parent::tearDown();
182+
}
183+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\GraphQl\Quote\Customer;
8+
namespace Magento\AuthorizenetGraphQl\Model\Resolver\Customer;
99

1010
use Magento\Framework\App\Request\Http;
1111
use Magento\Framework\Serialize\SerializerInterface;
1212
use Magento\Framework\Webapi\Request;
1313
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1414
use Magento\Integration\Api\CustomerTokenServiceInterface;
1515
use Magento\TestFramework\Helper\Bootstrap;
16+
use PHPUnit\Framework\TestCase;
1617

1718
/**
1819
* Tests SetPaymentMethod mutation for customer via authorizeNet payment
@@ -21,7 +22,7 @@
2122
* @magentoDbIsolation disabled
2223
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2324
*/
24-
class SetAuthorizenetPaymentMethodOnCustomerCartTest extends \PHPUnit\Framework\TestCase
25+
class SetAuthorizeNetPaymentMethodOnCartTest extends TestCase
2526
{
2627
const CONTENT_TYPE = 'application/json';
2728

0 commit comments

Comments
 (0)