diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/ChangePassword.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/ChangePassword.php index e94db23ac1c2a..f4f651f683b8e 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/ChangePassword.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/ChangePassword.php @@ -13,7 +13,6 @@ use Magento\CustomerGraphQl\Model\Customer\CheckCustomerAccount; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Exception\GraphQlInputException; -use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; @@ -44,8 +43,8 @@ class ChangePassword implements ResolverInterface /** * @param CheckCustomerAccount $checkCustomerAccount - * @param CheckCustomerAccount $checkCustomerPassword - * @param CheckCustomerPassword $accountManagement + * @param CheckCustomerPassword $checkCustomerPassword + * @param AccountManagementInterface $accountManagement * @param CustomerDataProvider $customerDataProvider */ public function __construct( @@ -78,7 +77,6 @@ public function resolve( throw new GraphQlInputException(__('"newPassword" value should be specified')); } - /** @var ContextInterface $context */ $currentUserId = $context->getUserId(); $currentUserType = $context->getUserType(); $currentUserId = (int)$currentUserId; diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer.php index 29cde9edc6db3..c3c78a1004da6 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer.php @@ -11,7 +11,6 @@ use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\CustomerGraphQl\Model\Customer\CustomerDataProvider; use Magento\Framework\GraphQl\Config\Element\Field; -use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; use Magento\Framework\GraphQl\Query\ResolverInterface; /** @@ -51,7 +50,6 @@ public function resolve( array $value = null, array $args = null ) { - /** @var ContextInterface $context */ $currentUserId = $context->getUserId(); $currentUserType = $context->getUserType(); diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/IsSubscribed.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/IsSubscribed.php index bee116eec4afc..ff958d3733788 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/IsSubscribed.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/IsSubscribed.php @@ -10,7 +10,6 @@ use Magento\CustomerGraphQl\Model\Customer\CheckCustomerAccount; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Framework\GraphQl\Config\Element\Field; -use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Newsletter\Model\SubscriberFactory; @@ -51,7 +50,6 @@ public function resolve( array $value = null, array $args = null ) { - /** @var ContextInterface $context */ $currentUserId = $context->getUserId(); $currentUserType = $context->getUserType(); diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/UpdateCustomer.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/UpdateCustomer.php index 339f855b2f0c6..5dc857f3f178c 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/UpdateCustomer.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/UpdateCustomer.php @@ -14,7 +14,6 @@ use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\CustomerGraphQl\Model\Customer\CustomerDataProvider; use Magento\Framework\GraphQl\Config\Element\Field; -use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; use Magento\Framework\GraphQl\Query\ResolverInterface; /** @@ -74,7 +73,6 @@ public function resolve( throw new GraphQlInputException(__('"input" value should be specified')); } - /** @var ContextInterface $context */ $currentUserId = $context->getUserId(); $currentUserType = $context->getUserType(); diff --git a/app/code/Magento/QuoteGraphQl/Model/Authorization/IsCartMutationAllowedForCurrentUser.php b/app/code/Magento/QuoteGraphQl/Model/Authorization/IsCartMutationAllowedForCurrentUser.php deleted file mode 100644 index 2dec8c278800b..0000000000000 --- a/app/code/Magento/QuoteGraphQl/Model/Authorization/IsCartMutationAllowedForCurrentUser.php +++ /dev/null @@ -1,67 +0,0 @@ -userContext = $userContext; - $this->cartRepository = $cartRepository; - } - - /** - * Check that the shopping cart operations are allowed for current user - * - * @param int $quoteId - * @return bool - * @throws GraphQlNoSuchEntityException - */ - public function execute(int $quoteId): bool - { - try { - $quote = $this->cartRepository->get($quoteId); - } catch (NoSuchEntityException $exception) { - throw new GraphQlNoSuchEntityException(__($exception->getMessage())); - } - - $customerId = $quote->getCustomerId(); - - /* Guest cart, allow operations */ - if (!$customerId) { - return true; - } - - /* If the quote belongs to the current customer allow operations */ - return $customerId == $this->userContext->getUserId(); - } -} diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/AddProductsToCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/AddProductsToCart.php index daec9411307f8..96259f2264943 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/AddProductsToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/AddProductsToCart.php @@ -7,71 +7,47 @@ namespace Magento\QuoteGraphQl\Model\Cart; -use Magento\Framework\Exception\NoSuchEntityException; -use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; use Magento\Framework\GraphQl\Exception\GraphQlInputException; -use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; use Magento\Framework\Message\AbstractMessage; use Magento\Quote\Api\CartRepositoryInterface; -use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface; use Magento\Quote\Model\Quote; -use Magento\QuoteGraphQl\Model\Authorization\IsCartMutationAllowedForCurrentUser; /** * Add products to cart */ class AddProductsToCart { - /** - * @var MaskedQuoteIdToQuoteIdInterface - */ - private $maskedQuoteIdToQuoteId; - /** * @var CartRepositoryInterface */ private $cartRepository; - /** - * @var IsCartMutationAllowedForCurrentUser - */ - private $isCartMutationAllowedForCurrentUser; - /** * @var AddSimpleProductToCart */ private $addProductToCart; /** - * @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId * @param CartRepositoryInterface $cartRepository - * @param IsCartMutationAllowedForCurrentUser $isCartMutationAllowedForCurrentUser * @param AddSimpleProductToCart $addProductToCart */ public function __construct( - MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId, CartRepositoryInterface $cartRepository, - IsCartMutationAllowedForCurrentUser $isCartMutationAllowedForCurrentUser, AddSimpleProductToCart $addProductToCart ) { - $this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId; $this->cartRepository = $cartRepository; - $this->isCartMutationAllowedForCurrentUser = $isCartMutationAllowedForCurrentUser; $this->addProductToCart = $addProductToCart; } /** * Add products to cart * - * @param string $cartHash + * @param Quote $cart * @param array $cartItems - * @return Quote * @throws GraphQlInputException */ - public function execute(string $cartHash, array $cartItems): Quote + public function execute(Quote $cart, array $cartItems): void { - $cart = $this->getCart($cartHash); - foreach ($cartItems as $cartItemData) { $this->addProductToCart->execute($cart, $cartItemData); } @@ -83,39 +59,6 @@ public function execute(string $cartHash, array $cartItems): Quote } $this->cartRepository->save($cart); - return $cart; - } - - /** - * Get cart - * - * @param string $cartHash - * @return Quote - * @throws GraphQlNoSuchEntityException - * @throws GraphQlAuthorizationException - */ - private function getCart(string $cartHash): Quote - { - try { - $cartId = $this->maskedQuoteIdToQuoteId->execute($cartHash); - $cart = $this->cartRepository->get($cartId); - } catch (NoSuchEntityException $e) { - throw new GraphQlNoSuchEntityException( - __('Could not find a cart with ID "%masked_cart_id"', ['masked_cart_id' => $cartHash]) - ); - } - - if (false === $this->isCartMutationAllowedForCurrentUser->execute($cartId)) { - throw new GraphQlAuthorizationException( - __( - 'The current user cannot perform operations on cart "%masked_cart_id"', - ['masked_cart_id' => $cartHash] - ) - ); - } - - /** @var Quote $cart */ - return $cart; } /** diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/GetCartForUser.php b/app/code/Magento/QuoteGraphQl/Model/Cart/GetCartForUser.php new file mode 100644 index 0000000000000..9c50d4b85578b --- /dev/null +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/GetCartForUser.php @@ -0,0 +1,89 @@ +maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId; + $this->cartRepository = $cartRepository; + } + + /** + * Get cart for user + * + * @param string $cartHash + * @param int|null $userId + * @return Quote + * @throws GraphQlAuthenticationException + * @throws GraphQlNoSuchEntityException + */ + public function execute(string $cartHash, ?int $userId): Quote + { + try { + $cartId = $this->maskedQuoteIdToQuoteId->execute($cartHash); + } catch (NoSuchEntityException $exception) { + throw new GraphQlNoSuchEntityException( + __('Could not find a cart with ID "%masked_cart_id"', ['masked_cart_id' => $cartHash]) + ); + } + + try { + /** @var Quote $cart */ + $cart = $this->cartRepository->get($cartId); + } catch (NoSuchEntityException $e) { + throw new GraphQlNoSuchEntityException( + __('Could not find a cart with ID "%masked_cart_id"', ['masked_cart_id' => $cartHash]) + ); + } + + $customerId = (int)$cart->getCustomerId(); + + /* Guest cart, allow operations */ + if (!$customerId) { + return $cart; + } + + if ($customerId !== $userId) { + throw new GraphQlAuthenticationException( + __( + 'The current user cannot perform operations on cart "%masked_cart_id"', + ['masked_cart_id' => $cartHash] + ) + ); + } + return $cart; + } +} diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/AddSimpleProductsToCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/AddSimpleProductsToCart.php index 31a0b3d02e44a..f4335b262c854 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/AddSimpleProductsToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/AddSimpleProductsToCart.php @@ -14,6 +14,7 @@ use Magento\Framework\Stdlib\ArrayManager; use Magento\QuoteGraphQl\Model\Cart\AddProductsToCart; use Magento\QuoteGraphQl\Model\Cart\ExtractDataFromCart; +use Magento\QuoteGraphQl\Model\Cart\GetCartForUser; /** * Add simple products to cart GraphQl resolver @@ -26,6 +27,11 @@ class AddSimpleProductsToCart implements ResolverInterface */ private $arrayManager; + /** + * @var GetCartForUser + */ + private $getCartForUser; + /** * @var AddProductsToCart */ @@ -38,15 +44,18 @@ class AddSimpleProductsToCart implements ResolverInterface /** * @param ArrayManager $arrayManager + * @param GetCartForUser $getCartForUser * @param AddProductsToCart $addProductsToCart * @param ExtractDataFromCart $extractDataFromCart */ public function __construct( ArrayManager $arrayManager, + GetCartForUser $getCartForUser, AddProductsToCart $addProductsToCart, ExtractDataFromCart $extractDataFromCart ) { $this->arrayManager = $arrayManager; + $this->getCartForUser = $getCartForUser; $this->addProductsToCart = $addProductsToCart; $this->extractDataFromCart = $extractDataFromCart; } @@ -67,7 +76,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value throw new GraphQlInputException(__('Missing key "cartItems" in cart data')); } - $cart = $this->addProductsToCart->execute((string)$cartHash, $cartItems); + $currentUserId = $context->getUserId(); + $cart = $this->getCartForUser->execute((string)$cartHash, $currentUserId); + + $this->addProductsToCart->execute($cart, $cartItems); $cartData = $this->extractDataFromCart->execute($cart); return [ diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/ApplyCouponToCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/ApplyCouponToCart.php index ac5cb38326bc0..88f26fe4ea818 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/ApplyCouponToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/ApplyCouponToCart.php @@ -8,16 +8,15 @@ namespace Magento\QuoteGraphQl\Model\Resolver; use Magento\Framework\Exception\CouldNotSaveException; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\GraphQl\Config\Element\Field; -use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Quote\Api\CouponManagementInterface; -use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface; -use Magento\QuoteGraphQl\Model\Authorization\IsCartMutationAllowedForCurrentUser; +use Magento\QuoteGraphQl\Model\Cart\GetCartForUser; /** * @inheritdoc @@ -25,33 +24,25 @@ class ApplyCouponToCart implements ResolverInterface { /** - * @var CouponManagementInterface + * @var GetCartForUser */ - private $couponManagement; + private $getCartForUser; /** - * @var MaskedQuoteIdToQuoteIdInterface - */ - private $maskedQuoteIdToQuoteId; - - /** - * @var IsCartMutationAllowedForCurrentUser + * @var CouponManagementInterface */ - private $isCartMutationAllowedForCurrentUser; + private $couponManagement; /** + * @param GetCartForUser $getCartForUser * @param CouponManagementInterface $couponManagement - * @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToId - * @param IsCartMutationAllowedForCurrentUser $isCartMutationAllowedForCurrentUser */ public function __construct( - CouponManagementInterface $couponManagement, - MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToId, - IsCartMutationAllowedForCurrentUser $isCartMutationAllowedForCurrentUser + GetCartForUser $getCartForUser, + CouponManagementInterface $couponManagement ) { + $this->getCartForUser = $getCartForUser; $this->couponManagement = $couponManagement; - $this->maskedQuoteIdToQuoteId = $maskedQuoteIdToId; - $this->isCartMutationAllowedForCurrentUser = $isCartMutationAllowedForCurrentUser; } /** @@ -69,22 +60,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value } $couponCode = $args['input']['coupon_code']; - try { - $cartId = $this->maskedQuoteIdToQuoteId->execute($maskedCartId); - } catch (NoSuchEntityException $exception) { - throw new GraphQlNoSuchEntityException( - __('Could not find a cart with ID "%masked_cart_id"', ['masked_cart_id' => $maskedCartId]) - ); - } - if (false === $this->isCartMutationAllowedForCurrentUser->execute($cartId)) { - throw new GraphQlAuthorizationException( - __( - 'The current user cannot perform operations on cart "%masked_cart_id"', - ['masked_cart_id' => $maskedCartId] - ) - ); - } + $currentUserId = $context->getUserId(); + $cart = $this->getCartForUser->execute($maskedCartId, $currentUserId); + $cartId = $cart->getId(); /* Check current cart does not have coupon code applied */ $appliedCouponCode = $this->couponManagement->get($cartId); @@ -99,7 +78,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value } catch (NoSuchEntityException $exception) { throw new GraphQlNoSuchEntityException(__($exception->getMessage())); } catch (CouldNotSaveException $exception) { - throw new GraphQlInputException(__($exception->getMessage())); + throw new LocalizedException(__($exception->getMessage())); } $data['cart']['applied_coupon'] = [ diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/CreateEmptyCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/CreateEmptyCart.php index 1ccc2fda58e56..06123abe615e6 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/CreateEmptyCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/CreateEmptyCart.php @@ -7,7 +7,6 @@ namespace Magento\QuoteGraphQl\Model\Resolver; -use Magento\Authorization\Model\UserContextInterface; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; @@ -25,6 +24,7 @@ class CreateEmptyCart implements ResolverInterface * @var CartManagementInterface */ private $cartManagement; + /** * @var GuestCartManagementInterface */ @@ -35,11 +35,6 @@ class CreateEmptyCart implements ResolverInterface */ private $quoteIdToMaskedId; - /** - * @var UserContextInterface - */ - private $userContext; - /** * @var QuoteIdMaskFactory */ @@ -48,20 +43,17 @@ class CreateEmptyCart implements ResolverInterface /** * @param CartManagementInterface $cartManagement * @param GuestCartManagementInterface $guestCartManagement - * @param UserContextInterface $userContext * @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( CartManagementInterface $cartManagement, GuestCartManagementInterface $guestCartManagement, - UserContextInterface $userContext, QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId, QuoteIdMaskFactory $quoteIdMaskFactory ) { $this->cartManagement = $cartManagement; $this->guestCartManagement = $guestCartManagement; - $this->userContext = $userContext; $this->quoteIdToMaskedId = $quoteIdToMaskedId; $this->quoteIdMaskFactory = $quoteIdMaskFactory; } @@ -71,7 +63,7 @@ public function __construct( */ public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { - $customerId = $this->userContext->getUserId(); + $customerId = $context->getUserId(); if (0 !== $customerId && null !== $customerId) { $quoteId = $this->cartManagement->createEmptyCartForCustomer($customerId); diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveCouponFromCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveCouponFromCart.php index 40175cc589954..c21d869ddac7d 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveCouponFromCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveCouponFromCart.php @@ -8,16 +8,15 @@ namespace Magento\QuoteGraphQl\Model\Resolver; use Magento\Framework\Exception\CouldNotDeleteException; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\GraphQl\Config\Element\Field; -use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Quote\Api\CouponManagementInterface; -use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface; -use Magento\QuoteGraphQl\Model\Authorization\IsCartMutationAllowedForCurrentUser; +use Magento\QuoteGraphQl\Model\Cart\GetCartForUser; /** * @inheritdoc @@ -25,9 +24,9 @@ class RemoveCouponFromCart implements ResolverInterface { /** - * @var MaskedQuoteIdToQuoteIdInterface + * @var GetCartForUser */ - private $maskedQuoteIdToId; + private $getCartForUser; /** * @var CouponManagementInterface @@ -35,23 +34,15 @@ class RemoveCouponFromCart implements ResolverInterface private $couponManagement; /** - * @var IsCartMutationAllowedForCurrentUser - */ - private $isCartMutationAllowedForCurrentUser; - - /** + * @param GetCartForUser $getCartForUser * @param CouponManagementInterface $couponManagement - * @param IsCartMutationAllowedForCurrentUser $isCartMutationAllowedForCurrentUser - * @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToId */ public function __construct( - CouponManagementInterface $couponManagement, - IsCartMutationAllowedForCurrentUser $isCartMutationAllowedForCurrentUser, - MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToId + GetCartForUser $getCartForUser, + CouponManagementInterface $couponManagement ) { + $this->getCartForUser = $getCartForUser; $this->couponManagement = $couponManagement; - $this->isCartMutationAllowedForCurrentUser = $isCartMutationAllowedForCurrentUser; - $this->maskedQuoteIdToId = $maskedQuoteIdToId; } /** @@ -64,29 +55,16 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value } $maskedCartId = $args['input']['cart_id']; - try { - $cartId = $this->maskedQuoteIdToId->execute($maskedCartId); - } catch (NoSuchEntityException $exception) { - throw new GraphQlNoSuchEntityException( - __('Could not find a cart with ID "%masked_cart_id"', ['masked_cart_id' => $maskedCartId]) - ); - } - - if (false === $this->isCartMutationAllowedForCurrentUser->execute($cartId)) { - throw new GraphQlAuthorizationException( - __( - 'The current user cannot perform operations on cart "%masked_cart_id"', - ['masked_cart_id' => $maskedCartId] - ) - ); - } + $currentUserId = $context->getUserId(); + $cart = $this->getCartForUser->execute($maskedCartId, $currentUserId); + $cartId = $cart->getId(); try { $this->couponManagement->remove($cartId); } catch (NoSuchEntityException $exception) { throw new GraphQlNoSuchEntityException(__($exception->getMessage())); } catch (CouldNotDeleteException $exception) { - throw new GraphQlInputException(__($exception->getMessage())); + throw new LocalizedException(__($exception->getMessage())); } $data['cart']['applied_coupon'] = [ diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CustomerAuthenticationTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/AddressesTest.php similarity index 84% rename from dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CustomerAuthenticationTest.php rename to dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/AddressesTest.php index 88ce7e91d94bc..9b7e3f28327da 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CustomerAuthenticationTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/AddressesTest.php @@ -14,16 +14,13 @@ use Magento\TestFramework\TestCase\GraphQlAbstract; use Magento\Integration\Api\CustomerTokenServiceInterface; -class CustomerAuthenticationTest extends GraphQlAbstract +class AddressesTest extends GraphQlAbstract { /** - * Verify customers with valid credentials with a customer bearer token - * * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testRegisteredCustomerWithValidCredentials() + public function testGetCustomerWithAddresses() { $query = <<assertCustomerAddressesFields($customer, $response); } - /** - * Verify customer with valid credentials but without the bearer token - * - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - public function testCustomerWithValidCredentialsWithoutToken() - { - $query - = <<expectException(\Exception::class); - $this->expectExceptionMessage('GraphQL response contains errors: Current customer' . ' ' . - 'does not have access to the resource "customer"'); - $this->graphQlQuery($query); - } - /** * Verify the all the whitelisted fields for a Customer Object * diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CustomerChangePasswordTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CustomerChangePasswordTest.php index ede719bb569ba..f245181815217 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CustomerChangePasswordTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CustomerChangePasswordTest.php @@ -41,7 +41,7 @@ protected function setUp() /** * @magentoApiDataFixture Magento/Customer/_files/customer.php */ - public function testCustomerChangeValidPassword() + public function testChangePassword() { $customerEmail = 'customer@example.com'; $oldCustomerPassword = 'password'; @@ -62,14 +62,13 @@ public function testCustomerChangeValidPassword() } } - public function testGuestUserCannotChangePassword() + /** + * @expectedException \Exception + * @expectedExceptionMessage The current customer isn't authorized. + */ + public function testChangePasswordIfUserIsNotAuthorizedTest() { $query = $this->getChangePassQuery('currentpassword', 'newpassword'); - $this->expectException(\Exception::class); - $this->expectExceptionMessage( - 'GraphQL response contains errors: Current customer' . ' ' . - 'does not have access to the resource "customer"' - ); $this->graphQlQuery($query); } @@ -94,10 +93,11 @@ public function testChangeWeakPassword() /** * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @expectedException \Exception + * @expectedExceptionMessage The password doesn't match this account. Verify the password and try again. */ - public function testCannotChangeWithIncorrectPassword() + public function testChangePasswordIfPasswordIsInvalid() { - $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/190'); $customerEmail = 'customer@example.com'; $oldCustomerPassword = 'password'; $newCustomerPassword = 'anotherPassword1'; @@ -105,13 +105,7 @@ public function testCannotChangeWithIncorrectPassword() $query = $this->getChangePassQuery($incorrectPassword, $newCustomerPassword); - // acquire authentication with correct password $headerMap = $this->getCustomerAuthHeaders($customerEmail, $oldCustomerPassword); - - $this->expectException(\Exception::class); - $this->expectExceptionMessageRegExp('/The password doesn\'t match this account. Verify the password.*/'); - - // but try to change with incorrect 'old' password $this->graphQlQuery($query, [], '', $headerMap); } diff --git a/lib/internal/Magento/Framework/GraphQl/Query/ResolverInterface.php b/lib/internal/Magento/Framework/GraphQl/Query/ResolverInterface.php index 295113a98e465..f0450dce7f5f0 100644 --- a/lib/internal/Magento/Framework/GraphQl/Query/ResolverInterface.php +++ b/lib/internal/Magento/Framework/GraphQl/Query/ResolverInterface.php @@ -20,7 +20,7 @@ interface ResolverInterface * Fetches the data from persistence models and format it according to the GraphQL schema. * * @param \Magento\Framework\GraphQl\Config\Element\Field $field - * @param $context + * @param \Magento\Framework\GraphQl\Query\Resolver\ContextInterface $context * @param ResolveInfo $info * @param array|null $value * @param array|null $args