1717use Magento \Store \Api \Data \StoreInterface ;
1818use Magento \TestFramework \Fixture \DataFixture ;
1919use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
20- use Magento \Quote \Api \CartManagementInterface ;
21- use Magento \Quote \Api \CartRepositoryInterface ;
2220use Magento \Checkout \Test \Fixture \SetBillingAddress ;
2321use Magento \Checkout \Test \Fixture \SetShippingAddress ;
2422use Magento \Checkout \Test \Fixture \SetDeliveryMethod ;
3230use Magento \Store \Test \Fixture \Store ;
3331use Magento \Catalog \Test \Fixture \Product ;
3432use Magento \Customer \Test \Fixture \Customer ;
33+ use Magento \Quote \Test \Fixture \CustomerCart ;
34+ use Magento \Quote \Test \Fixture \AddProductToCart ;
3535
3636/**
37- * Integration test for complete workflow:
37+ * Integration test for complete workflow using proper fixtures :
3838 * Create website, store, and store view with numeric names -> Place orders -> Create credit memo -> Verify grid display
3939 *
4040 * @magentoDbIsolation disabled
@@ -64,7 +64,7 @@ protected function setUp(): void
6464 }
6565
6666 /**
67- * Test complete workflow: Create store with numeric name -> Place order -> Create credit memo -> Verify grid
67+ * Test complete workflow using proper fixtures with scope parameter
6868 *
6969 * @return void
7070 */
@@ -92,67 +92,70 @@ protected function setUp(): void
9292 ),
9393 DataFixture(
9494 Product::class,
95- ['sku ' => 'simple ' , 'price ' => 10 , 'website_ids ' => [1 , '$test_website.id$ ' ]],
95+ ['sku ' => 'simple-product-numeric-store ' , 'price ' => 10 , 'website_ids ' => [1 , '$test_website.id$ ' ]],
9696 'product '
9797 ),
9898 DataFixture(
9999 Customer::class,
100- ['email ' => 'customer@123test.com ' , 'website_id ' => '$test_website.id$ ' ],
100+ [
101+ 'email ' => 'customer@123test.com ' ,
102+ 'website_id ' => '$test_website.id$ ' ,
103+ 'store_id ' => '$test_store.id$ ' ,
104+ 'addresses ' => [[]]
105+ ],
101106 'customer '
102107 ),
108+ DataFixture(
109+ CustomerCart::class,
110+ ['customer_id ' => '$customer.id$ ' ],
111+ as: 'quote ' ,
112+ scope: 'test_store '
113+ ),
114+ DataFixture(
115+ AddProductToCart::class,
116+ ['cart_id ' => '$quote.id$ ' , 'product_id ' => '$product.id$ ' , 'qty ' => 2 ]
117+ ),
118+ DataFixture(SetBillingAddress::class, ['cart_id ' => '$quote.id$ ' ]),
119+ DataFixture(SetShippingAddress::class, ['cart_id ' => '$quote.id$ ' ]),
120+ DataFixture(
121+ SetDeliveryMethod::class,
122+ ['cart_id ' => '$quote.id$ ' , 'carrier_code ' => 'flatrate ' , 'method_code ' => 'flatrate ' ]
123+ ),
124+ DataFixture(SetPaymentMethod::class, ['cart_id ' => '$quote.id$ ' ]),
125+ DataFixture(PlaceOrder::class, ['cart_id ' => '$quote.id$ ' ], 'order ' ),
126+ DataFixture(Invoice::class, ['order_id ' => '$order.id$ ' ]),
127+ DataFixture(
128+ Creditmemo::class,
129+ ['order_id ' => '$order.id$ ' , 'items ' => [['qty ' => 1 , 'product_id ' => '$product.id$ ' ]]],
130+ 'creditmemo '
131+ )
103132 ]
104- public function testCompleteWorkflowWithNumericStoreNames (): void
133+ public function testCompleteWorkflowWithNumericStoreNamesUsingFixtures (): void
105134 {
106- // Step 1: Get basic fixtures
135+ // Get fixtures
107136 $ fixtures = DataFixtureStorageManager::getStorage ();
108137 /** @var StoreInterface $store */
109138 $ store = $ fixtures ->get ('test_store ' );
110- $ customer = $ fixtures ->get ('customer ' );
111- $ product = $ fixtures ->get ('product ' );
112-
113- // Step 2: Create cart manually with correct store ID (CustomerCartFixture doesn't support store_id)
114- $ cartManagement = $ this ->objectManager ->get (CartManagementInterface::class);
115- $ cartRepository = $ this ->objectManager ->get (CartRepositoryInterface::class);
116-
117- $ cartId = $ cartManagement ->createEmptyCartForCustomer ($ customer ->getId ());
118- $ cart = $ cartRepository ->get ($ cartId );
119- $ cart ->setStoreId ($ store ->getId ());
120- $ cartRepository ->save ($ cart );
121-
122- // Add product to cart
123- $ cart ->addProduct ($ product , 2 );
124- $ cartRepository ->save ($ cart );
139+ /** @var OrderInterface $order */
140+ $ order = $ fixtures ->get ('order ' );
141+ /** @var CreditmemoInterface $creditmemo */
142+ $ creditmemo = $ fixtures ->get ('creditmemo ' );
125143
126- // Step 3: Use fixtures for checkout process
127- $ billingAddressFixture = $ this ->objectManager ->create (SetBillingAddress::class);
128- $ billingAddressFixture ->apply (['cart_id ' => $ cart ->getId ()]);
129-
130- $ shippingAddressFixture = $ this ->objectManager ->create (SetShippingAddress::class);
131- $ shippingAddressFixture ->apply (['cart_id ' => $ cart ->getId ()]);
132-
133- $ deliveryMethodFixture = $ this ->objectManager ->create (SetDeliveryMethod::class);
134- $ deliveryMethodFixture ->apply (
135- ['cart_id ' => $ cart ->getId (), 'carrier_code ' => 'flatrate ' , 'method_code ' => 'flatrate ' ]
144+ // Verify order is in the correct store
145+ $ this ->assertEquals (
146+ $ store ->getId (),
147+ $ order ->getStoreId (),
148+ 'Order should be placed in the test store '
136149 );
137150
138- $ paymentMethodFixture = $ this ->objectManager ->create (SetPaymentMethod::class);
139- $ paymentMethodFixture ->apply (['cart_id ' => $ cart ->getId ()]);
140-
141- $ placeOrderFixture = $ this ->objectManager ->create (PlaceOrder::class);
142- $ order = $ placeOrderFixture ->apply (['cart_id ' => $ cart ->getId ()]);
143-
144- $ invoiceFixture = $ this ->objectManager ->create (Invoice::class);
145- $ invoiceFixture ->apply (['order_id ' => $ order ->getId ()]);
146-
147- $ creditmemoFixture = $ this ->objectManager ->create (Creditmemo::class);
148- $ creditmemo = $ creditmemoFixture ->apply ([
149- 'order_id ' => $ order ->getId (),
150- 'items ' => [['qty ' => 1 , 'product_id ' => $ product ->getId ()]]
151- ]);
152-
153- $ this ->assertEquals ($ store ->getId (), $ creditmemo ->getStoreId (), 'Credit memo should be in test store ' );
151+ // Verify credit memo is in the correct store
152+ $ this ->assertEquals (
153+ $ store ->getId (),
154+ $ creditmemo ->getStoreId (),
155+ 'Credit memo should be in test store '
156+ );
154157
155- // Step 4: Verify credit memo displays in grid page
158+ // Verify credit memo displays correctly in grid
156159 $ this ->verifyCreditMemoGridDisplaysRecords ($ creditmemo , $ order , $ store );
157160 }
158161
@@ -171,29 +174,31 @@ private function verifyCreditMemoGridDisplaysRecords(
171174 ): void {
172175 // Test credit memo retrieval by order ID
173176 $ creditmemoByOrder = $ this ->getCreditmemosByFilter ('order_id ' , $ order ->getId ());
174- $ this ->assertCount (1 , $ creditmemoByOrder );
177+ $ this ->assertCount (1 , $ creditmemoByOrder, ' Should find exactly one credit memo for the order ' );
175178 $ foundCreditmemo = reset ($ creditmemoByOrder );
176179
177- //Assert that found credit memo matches expected values
180+ // Assert that found credit memo matches expected values
178181 $ this ->assertEquals ($ creditmemo ->getId (), $ foundCreditmemo ->getId ());
179182 $ this ->assertEquals ($ creditmemo ->getIncrementId (), $ foundCreditmemo ->getIncrementId ());
180183 $ this ->assertEquals ($ order ->getId (), $ foundCreditmemo ->getOrderId ());
181184 $ this ->assertEquals ($ order ->getStoreId (), $ foundCreditmemo ->getStoreId ());
182185
183- // Test credit memo retrieval by creditmemo ID (more efficient than filtering by store_id and looping)
186+ // Test credit memo retrieval by creditmemo ID
184187 $ creditmemoById = $ this ->getCreditmemosByFilter ('entity_id ' , $ creditmemo ->getId ());
185188 $ this ->assertCount (1 , $ creditmemoById , 'Credit memo should be found when filtering by ID ' );
186189
187190 $ foundCreditmemoById = reset ($ creditmemoById );
188191 $ this ->assertEquals ($ creditmemo ->getId (), $ foundCreditmemoById ->getId ());
189192 $ this ->assertEquals ($ order ->getStoreId (), $ foundCreditmemoById ->getStoreId ());
190193
191- // Explicitly verify the credit memo is created in "123test Store View"
194+ // Explicitly verify the credit memo is created in the correct store
192195 $ this ->assertEquals (
193196 $ store ->getId (),
194197 $ creditmemo ->getStoreId (),
195198 'Credit memo should be created in the test store '
196199 );
200+
201+ // Verify store name starts with numeric characters
197202 $ this ->assertEquals (
198203 '123test Store View ' ,
199204 $ store ->getName (),
@@ -218,7 +223,7 @@ private function verifyCreditMemoGridDisplaysRecords(
218223 }
219224 $ this ->assertTrue (
220225 $ foundInStoreFilter ,
221- 'Credit memo should be found when filtering grid by "123test Store View" '
226+ sprintf ( 'Credit memo should be found when filtering grid by "%s" ' , $ store -> getName ())
222227 );
223228 }
224229
0 commit comments