1111use Magento \Framework \Webapi \Rest \Request ;
1212use Magento \TestFramework \Helper \Bootstrap ;
1313use Magento \TestFramework \TestCase \WebapiAbstract ;
14+ use Magento \TestFramework \Fixture \DataFixture ;
15+ use Magento \TestFramework \Fixture \DataFixtureStorage ;
16+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
17+ use Magento \User \Test \Fixture \User ;
1418
1519/**
1620 * Test to verify REST-API updating product stock_item does not delete downloadable_product_links
@@ -23,22 +27,27 @@ class StockItemUpdatePreservesLinksTest extends WebapiAbstract
2327 private const PRODUCT_RESOURCE_PATH = '/V1/products ' ;
2428 private const TEST_PRODUCT_SKU = 'downloadable-product ' ;
2529
30+ /**
31+ * @var DataFixtureStorage
32+ */
33+ private $ fixtures ;
34+
2635 /**
2736 * @inheritDoc
2837 */
2938 protected function setUp (): void
3039 {
3140 parent ::setUp ();
3241 $ this ->_markTestAsRestOnly ();
42+ $ this ->fixtures = DataFixtureStorageManager::getStorage ();
3343 }
3444
3545 /**
3646 * Test the complete workflow from Steps 1-16
3747 * Verify that REST-API updating product stock_item does not delete downloadable_product_links
38- *
39- * @magentoApiDataFixture Magento/Webapi/_files/webapi_user.php
40- * @magentoApiDataFixture Magento/Downloadable/_files/downloadable_product_with_files_and_sample_url.php
4148 */
49+ #[DataFixture(User::class, ['role_id ' => 1 ], 'admin_user ' )]
50+ #[DataFixture('Magento/Downloadable/_files/downloadable_product_with_files_and_sample_url.php ' )]
4251 public function testStockItemUpdatePreservesDownloadableLinks ()
4352 {
4453 // Steps 1-7: Generate admin access token
@@ -74,8 +83,9 @@ private function generateAdminAccessToken(): string
7483 ],
7584 ];
7685
86+ $ adminUser = $ this ->fixtures ->get ('admin_user ' );
7787 $ requestData = [
78- 'username ' => ' webapi_user ' ,
88+ 'username ' => $ adminUser -> getUsername () ,
7989 'password ' => \Magento \TestFramework \Bootstrap::ADMIN_PASSWORD ,
8090 ];
8191
@@ -181,49 +191,4 @@ private function getProductBySku(string $sku): array
181191
182192 return $ this ->_webApiCall ($ serviceInfo , []);
183193 }
184-
185- /**
186- * Test Steps 1-7: Admin Token Generation
187- *
188- * @magentoApiDataFixture Magento/Webapi/_files/webapi_user.php
189- */
190- public function testSteps1Through7AdminTokenGeneration ()
191- {
192- $ token = $ this ->generateAdminAccessToken ();
193- $ this ->assertNotEmpty ($ token , 'Steps 1-7: Admin token should be generated successfully ' );
194- }
195-
196- /**
197- * Test Steps 8-14: Product Stock Item Update
198- *
199- * @magentoApiDataFixture Magento/Webapi/_files/webapi_user.php
200- * @magentoApiDataFixture Magento/Downloadable/_files/downloadable_product_with_files_and_sample_url.php
201- */
202- public function testSteps8Through14ProductStockItemUpdate ()
203- {
204- $ token = $ this ->generateAdminAccessToken ();
205- $ updatedProduct = $ this ->updateProductStockItem ($ token );
206-
207- $ this ->assertNotEmpty ($ updatedProduct , 'Steps 8-14: Product should be updated successfully ' );
208- $ this ->assertEquals ('99.99 ' , $ updatedProduct ['price ' ], 'Steps 8-14: Product price should be updated to 99.99 ' );
209- $ this ->assertEquals ('1 ' , $ updatedProduct ['status ' ], 'Steps 8-14: Product status should be enabled ' );
210- }
211-
212- /**
213- * Test Steps 15-16: Downloadable Links Preservation
214- *
215- * @magentoApiDataFixture Magento/Webapi/_files/webapi_user.php
216- * @magentoApiDataFixture Magento/Downloadable/_files/downloadable_product_with_files_and_sample_url.php
217- */
218- public function testSteps15Through16DownloadableLinksPreservation ()
219- {
220- $ originalProduct = $ this ->getProductBySku (self ::TEST_PRODUCT_SKU );
221- $ this ->verifyProductHasDownloadableLinks ($ originalProduct , 'Original product should have downloadable links ' );
222- $ originalLinks = $ originalProduct ['extension_attributes ' ]['downloadable_product_links ' ];
223-
224- $ token = $ this ->generateAdminAccessToken ();
225- $ this ->updateProductStockItem ($ token );
226-
227- $ this ->verifyDownloadableLinksPreserved ($ originalLinks );
228- }
229194}
0 commit comments