1515use Magento \TestFramework \Fixture \DataFixture ;
1616use Magento \TestFramework \TestCase \WebapiAbstract ;
1717use Magento \TestFramework \Helper \Bootstrap ;
18- use Magento \Quote \Model \Quote ;
1918use Magento \Quote \Model \QuoteIdMaskFactory ;
2019use Magento \Checkout \Api \Data \ShippingInformationInterface ;
2120use Magento \Checkout \Api \Data \ShippingInformationInterfaceFactory ;
2221use Magento \Quote \Api \Data \AddressInterface ;
2322use Magento \Quote \Api \Data \AddressInterfaceFactory ;
23+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
2424
2525/**
2626 * Test GuestShippingInformationManagement API validation.
@@ -46,13 +46,19 @@ class GuestShippingInformationManagementValidationTest extends WebapiAbstract
4646 */
4747 private $ quoteIdMaskFactory ;
4848
49+ /**
50+ * @var DataFixtureStorageManager
51+ */
52+ private $ fixtures ;
53+
4954 protected function setUp (): void
5055 {
5156 parent ::setUp ();
5257 $ this ->shippingInformationFactory = Bootstrap::getObjectManager ()
5358 ->get (ShippingInformationInterfaceFactory::class);
5459 $ this ->addressFactory = Bootstrap::getObjectManager ()->get (AddressInterfaceFactory::class);
5560 $ this ->quoteIdMaskFactory = Bootstrap::getObjectManager ()->get (QuoteIdMaskFactory::class);
61+ $ this ->fixtures = DataFixtureStorageManager::getStorage ();
5662 }
5763
5864 #[
@@ -66,9 +72,9 @@ protected function setUp(): void
6672 */
6773 public function testSaveAddressInformationWithValidData ()
6874 {
69- $ quote = Bootstrap:: getObjectManager ()-> create (Quote::class );
70- $ quote -> load ( ' test_order_1 ' , ' reserved_order_id ' );
71- $ cartId = $ quote -> getId ( );
75+ $ cart = $ this -> fixtures -> get ( ' cart ' );
76+ $ cartId = $ cart -> getId ( );
77+ $ maskedCartId = $ this -> getMaskedCartId ( $ cartId );
7278 $ shippingAddress = $ this ->addressFactory ->create ();
7379 $ shippingAddress ->setData ([
7480 'firstname ' => 'John ' ,
@@ -102,12 +108,32 @@ public function testSaveAddressInformationWithValidData()
102108 $ shippingInformation ->setBillingAddress ($ billingAddress );
103109 $ shippingInformation ->setShippingMethodCode ('flatrate ' );
104110 $ shippingInformation ->setShippingCarrierCode ('flatrate ' );
105- $ result = $ this ->callSaveAddressInformation ($ cartId , $ shippingInformation );
111+ $ result = $ this ->callSaveAddressInformation ($ maskedCartId , $ shippingInformation );
106112 $ this ->assertNotEmpty ($ result );
107113 $ this ->assertArrayHasKey ('payment_methods ' , $ result );
108114 $ this ->assertArrayHasKey ('totals ' , $ result );
109115 }
110116
117+ /**
118+ * Get masked cart ID for the given quote
119+ *
120+ * @param string $cartId
121+ * @return string
122+ */
123+ private function getMaskedCartId (string $ cartId ): string
124+ {
125+ $ quoteIdMask = $ this ->quoteIdMaskFactory ->create ();
126+ $ quoteIdMask ->load ($ cartId , 'quote_id ' );
127+
128+ if (!$ quoteIdMask ->getMaskedId ()) {
129+ $ quoteIdMask ->setQuoteId ($ cartId );
130+ $ quoteIdMask ->setMaskedId (uniqid ('masked_ ' , true ));
131+ $ quoteIdMask ->save ();
132+ }
133+
134+ return $ quoteIdMask ->getMaskedId ();
135+ }
136+
111137 /**
112138 * Call the saveAddressInformation API
113139 *
0 commit comments