Skip to content

Commit 44b99de

Browse files
committed
GraphQL-571: [Checkout Coverage] Place order for guest
1 parent 58fa5d4 commit 44b99de

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/SetGuestEmailOnCart.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,24 @@ class SetGuestEmailOnCart implements ResolverInterface
3232
*/
3333
private $getCartForUser;
3434

35+
/**
36+
* @var EmailAddressValidator
37+
*/
38+
private $emailValidator;
39+
3540
/**
3641
* @param GetCartForUser $getCartForUser
3742
* @param CartRepositoryInterface $cartRepository
43+
* @param EmailAddressValidator $emailValidator
3844
*/
3945
public function __construct(
4046
GetCartForUser $getCartForUser,
41-
CartRepositoryInterface $cartRepository
47+
CartRepositoryInterface $cartRepository,
48+
EmailAddressValidator $emailValidator
4249
) {
4350
$this->getCartForUser = $getCartForUser;
4451
$this->cartRepository = $cartRepository;
52+
$this->emailValidator = $emailValidator;
4553
}
4654

4755
/**
@@ -58,11 +66,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
5866
throw new GraphQlInputException(__('Required parameter "email" is missing'));
5967
}
6068

61-
$guestEmail = $args['input']['email'];
62-
63-
if (!\Zend_Validate::is($guestEmail, EmailAddressValidator::class)) {
69+
if (false === $this->emailValidator->isValid($args['input']['email'])) {
6470
throw new GraphQlInputException(__('Invalid email format'));
6571
}
72+
$email = $args['input']['email'];
6673

6774
$currentUserId = $context->getUserId();
6875

@@ -71,7 +78,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7178
}
7279

7380
$cart = $this->getCartForUser->execute($maskedCartId, $currentUserId);
74-
$cart->setCustomerEmail($guestEmail);
81+
$cart->setCustomerEmail($email);
7582

7683
try {
7784
$this->cartRepository->save($cart);

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetGuestEmailOnCartTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private function getQuery(string $maskedQuoteId, string $email): string
8383
email: "$email"
8484
}) {
8585
cart {
86-
guest_email
86+
email
8787
}
8888
}
8989
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetGuestEmailOnCartTest.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testSetGuestEmailOnCart()
4040

4141
$this->assertArrayHasKey('setGuestEmailOnCart', $response);
4242
$this->assertArrayHasKey('cart', $response['setGuestEmailOnCart']);
43-
$this->assertEquals($email, $response['setGuestEmailOnCart']['cart']['guest_email']);
43+
$this->assertEquals($email, $response['setGuestEmailOnCart']['cart']['email']);
4444
}
4545

4646
/**
@@ -65,16 +65,14 @@ public function testSetGuestEmailOnCustomerCart()
6565
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
6666
*
6767
* @dataProvider incorrectEmailDataProvider
68-
* @param string $maskedQuoteId
6968
* @param string $email
7069
* @param string $exceptionMessage
7170
*/
7271
public function testSetGuestEmailOnCartWithIncorrectEmail(
73-
string $maskedQuoteId,
7472
string $email,
7573
string $exceptionMessage
7674
) {
77-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($maskedQuoteId);
75+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
7876

7977
$query = $this->getQuery($maskedQuoteId, $email);
8078
$this->expectExceptionMessage($exceptionMessage);
@@ -87,8 +85,8 @@ public function testSetGuestEmailOnCartWithIncorrectEmail(
8785
public function incorrectEmailDataProvider(): array
8886
{
8987
return [
90-
'wrong_email' => ['test_quote', 'some', 'Invalid email format'],
91-
'no_email' => ['test_quote', '', 'Required parameter "email" is missing'],
88+
'wrong_email' => ['some', 'Invalid email format'],
89+
'no_email' => ['', 'Required parameter "email" is missing'],
9290
];
9391
}
9492

@@ -134,7 +132,7 @@ private function getQuery(string $maskedQuoteId, string $email): string
134132
email: "$email"
135133
}) {
136134
cart {
137-
guest_email
135+
email
138136
}
139137
}
140138
}

0 commit comments

Comments
 (0)