|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| - * Copyright © Magento, Inc. All rights reserved. |
4 |
| - * See COPYING.txt for license details. |
| 3 | + * Copyright 2025 Adobe |
| 4 | + * All Rights Reserved. |
| 5 | + * |
| 6 | + * NOTICE: All information contained herein is, and remains |
| 7 | + * the property of Adobe and its suppliers, if any. The intellectual |
| 8 | + * and technical concepts contained herein are proprietary to Adobe |
| 9 | + * and its suppliers and are protected by all applicable intellectual |
| 10 | + * property laws, including trade secret and copyright laws. |
| 11 | + * Dissemination of this information or reproduction of this material |
| 12 | + * is strictly forbidden unless prior written permission is obtained |
| 13 | + * from Adobe. |
5 | 14 | */
|
6 | 15 | declare(strict_types=1);
|
7 | 16 |
|
8 | 17 | namespace Magento\GraphQl\Quote\Customer;
|
9 | 18 |
|
| 19 | +use Magento\Catalog\Test\Fixture\Product as ProductFixture; |
10 | 20 | use Magento\Customer\Api\AddressRepositoryInterface;
|
11 | 21 | use Magento\Customer\Api\CustomerRepositoryInterface;
|
| 22 | +use Magento\Customer\Test\Fixture\Customer; |
| 23 | +use Magento\Customer\Test\Fixture\CustomerWithAddresses; |
12 | 24 | use Magento\Framework\Api\SearchCriteriaBuilder;
|
13 | 25 | use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
14 | 26 | use Magento\Integration\Api\CustomerTokenServiceInterface;
|
15 | 27 | use Magento\Quote\Model\QuoteFactory;
|
16 | 28 | use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
|
17 | 29 | use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
|
| 30 | +use Magento\Quote\Test\Fixture\AddProductToCart; |
| 31 | +use Magento\Quote\Test\Fixture\CustomerCart as CustomerCartFixture; |
| 32 | +use Magento\Quote\Test\Fixture\QuoteIdMask; |
| 33 | +use Magento\TestFramework\Fixture\DataFixture; |
| 34 | +use Magento\TestFramework\Fixture\DataFixtureStorageManager; |
18 | 35 | use Magento\TestFramework\Helper\Bootstrap;
|
19 | 36 | use Magento\TestFramework\TestCase\GraphQlAbstract;
|
20 | 37 |
|
@@ -65,15 +82,15 @@ class SetShippingAddressOnCartTest extends GraphQlAbstract
|
65 | 82 |
|
66 | 83 | protected function setUp(): void
|
67 | 84 | {
|
68 |
| - $objectManager = Bootstrap::getObjectManager(); |
69 |
| - $this->quoteResource = $objectManager->get(QuoteResource::class); |
70 |
| - $this->quoteFactory = $objectManager->get(QuoteFactory::class); |
71 |
| - $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); |
72 |
| - $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); |
73 |
| - $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); |
74 |
| - $this->customerAddressRepository = $objectManager->get(AddressRepositoryInterface::class); |
75 |
| - $this->searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class); |
76 |
| - $this->customerRepository = $objectManager->get(CustomerRepositoryInterface::class); |
| 85 | + $this->quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class); |
| 86 | + $this->quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class); |
| 87 | + $this->quoteIdToMaskedId = Bootstrap::getObjectManager()->get(QuoteIdToMaskedQuoteIdInterface::class); |
| 88 | + $this->getMaskedQuoteIdByReservedOrderId = Bootstrap::getObjectManager() |
| 89 | + ->get(GetMaskedQuoteIdByReservedOrderId::class); |
| 90 | + $this->customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class); |
| 91 | + $this->customerAddressRepository = Bootstrap::getObjectManager()->get(AddressRepositoryInterface::class); |
| 92 | + $this->searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class); |
| 93 | + $this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class); |
77 | 94 | }
|
78 | 95 |
|
79 | 96 | /**
|
@@ -457,43 +474,50 @@ public function testSetShippingAddressIfCustomerIsNotOwnerOfAddress()
|
457 | 474 | $this-> graphQlMutation( $query, [], '', $this-> getHeaderMap( '[email protected]'));
|
458 | 475 | }
|
459 | 476 |
|
460 |
| - /** |
461 |
| - * _security |
462 |
| - * @magentoApiDataFixture Magento/Customer/_files/three_customers.php |
463 |
| - * @magentoApiDataFixture Magento/Customer/_files/customer_address.php |
464 |
| - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php |
465 |
| - * |
466 |
| - */ |
| 477 | + #[ |
| 478 | + DataFixture(CustomerWithAddresses::class, as: 'customer'), |
| 479 | + DataFixture(Customer::class, as: 'customer2'), |
| 480 | + DataFixture(Customer::class, as: 'customer3'), |
| 481 | + DataFixture(ProductFixture::class, ['sku' => 'simple'], as: 'product'), |
| 482 | + DataFixture(CustomerCartFixture::class, ['customer_id' => '$customer.id$'], as: 'cart'), |
| 483 | + DataFixture(QuoteIdMask::class, ['cart_id' => '$cart.id$'], 'quoteIdMask'), |
| 484 | + DataFixture(AddProductToCart::class, ['cart_id' => '$cart.id$', 'product_id' => '$product.id$']) |
| 485 | + ] |
467 | 486 | public function testSetShippingAddressToAnotherCustomerCart()
|
468 | 487 | {
|
| 488 | + $maskedQuoteId = DataFixtureStorageManager::getStorage()->get('quoteIdMask')->getMaskedId(); |
469 | 489 | $this->expectException(\Exception::class);
|
470 |
| - |
471 |
| - $maskedQuoteId = $this->assignQuoteToCustomer('test_order_with_simple_product_without_address', 1); |
472 |
| - |
473 |
| - $query = <<<QUERY |
474 |
| -mutation { |
475 |
| - setShippingAddressesOnCart( |
476 |
| - input: { |
477 |
| - cart_id: "$maskedQuoteId" |
478 |
| - shipping_addresses: [ |
479 |
| - { |
480 |
| - customer_address_id: 1 |
481 |
| - } |
482 |
| - ] |
483 |
| - } |
484 |
| - ) { |
485 |
| - cart { |
486 |
| - shipping_addresses { |
487 |
| - postcode |
488 |
| - } |
489 |
| - } |
490 |
| - } |
491 |
| -} |
492 |
| -QUERY; |
493 | 490 | $this->expectExceptionMessage(
|
494 | 491 | "The current user cannot perform operations on cart \"$maskedQuoteId\""
|
495 | 492 | );
|
496 |
| - $this-> graphQlMutation( $query, [], '', $this-> getHeaderMap( '[email protected]')); |
| 493 | + |
| 494 | + $query = <<<MUTATION |
| 495 | + mutation { |
| 496 | + setShippingAddressesOnCart( |
| 497 | + input: { |
| 498 | + cart_id: "$maskedQuoteId" |
| 499 | + shipping_addresses: [ |
| 500 | + { |
| 501 | + customer_address_id: 1 |
| 502 | + } |
| 503 | + ] |
| 504 | + } |
| 505 | + ) { |
| 506 | + cart { |
| 507 | + shipping_addresses { |
| 508 | + postcode |
| 509 | + } |
| 510 | + } |
| 511 | + } |
| 512 | + } |
| 513 | + MUTATION; |
| 514 | + |
| 515 | + $this->graphQlMutation( |
| 516 | + $query, |
| 517 | + [], |
| 518 | + '', |
| 519 | + $this->getHeaderMap(DataFixtureStorageManager::getStorage()->get('customer2')->getEmail()) |
| 520 | + ); |
497 | 521 | }
|
498 | 522 |
|
499 | 523 | /**
|
|
0 commit comments