Skip to content

Commit b0a73ef

Browse files
committed
WebApi Test case updated
1 parent ad80079 commit b0a73ef

File tree

1 file changed

+66
-42
lines changed

1 file changed

+66
-42
lines changed

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

Lines changed: 66 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
<?php
22
/**
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.
514
*/
615
declare(strict_types=1);
716

817
namespace Magento\GraphQl\Quote\Customer;
918

19+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
1020
use Magento\Customer\Api\AddressRepositoryInterface;
1121
use Magento\Customer\Api\CustomerRepositoryInterface;
22+
use Magento\Customer\Test\Fixture\Customer;
23+
use Magento\Customer\Test\Fixture\CustomerWithAddresses;
1224
use Magento\Framework\Api\SearchCriteriaBuilder;
1325
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1426
use Magento\Integration\Api\CustomerTokenServiceInterface;
1527
use Magento\Quote\Model\QuoteFactory;
1628
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1729
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;
1835
use Magento\TestFramework\Helper\Bootstrap;
1936
use Magento\TestFramework\TestCase\GraphQlAbstract;
2037

@@ -65,15 +82,15 @@ class SetShippingAddressOnCartTest extends GraphQlAbstract
6582

6683
protected function setUp(): void
6784
{
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);
7794
}
7895

7996
/**
@@ -457,43 +474,50 @@ public function testSetShippingAddressIfCustomerIsNotOwnerOfAddress()
457474
$this->graphQlMutation($query, [], '', $this->getHeaderMap('[email protected]'));
458475
}
459476

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+
]
467486
public function testSetShippingAddressToAnotherCustomerCart()
468487
{
488+
$maskedQuoteId = DataFixtureStorageManager::getStorage()->get('quoteIdMask')->getMaskedId();
469489
$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;
493490
$this->expectExceptionMessage(
494491
"The current user cannot perform operations on cart \"$maskedQuoteId\""
495492
);
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+
);
497521
}
498522

499523
/**

0 commit comments

Comments
 (0)