1010
1111use Magento \Downloadable \Test \Fixture \DownloadableProduct ;
1212use Magento \Framework \Webapi \Rest \Request ;
13- use Magento \Integration \Api \AdminTokenServiceInterface ;
14- use Magento \TestFramework \Helper \Bootstrap ;
1513use Magento \TestFramework \TestCase \WebapiAbstract ;
1614use Magento \TestFramework \Fixture \DataFixture ;
1715use Magento \TestFramework \Fixture \DataFixtureStorage ;
1816use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
19- use Magento \User \Test \Fixture \User ;
2017
2118/**
2219 * Test to verify REST-API updating product stock_item does not delete downloadable_product_links
@@ -32,11 +29,6 @@ class StockItemUpdatePreservesLinksTest extends WebapiAbstract
3229 */
3330 private $ fixtures ;
3431
35- /**
36- * @var AdminTokenServiceInterface
37- */
38- private $ adminTokenService ;
39-
4032 /**
4133 * @inheritDoc
4234 */
@@ -45,14 +37,12 @@ protected function setUp(): void
4537 parent ::setUp ();
4638 $ this ->_markTestAsRestOnly ();
4739 $ this ->fixtures = DataFixtureStorageManager::getStorage ();
48- $ this ->adminTokenService = Bootstrap::getObjectManager ()->get (AdminTokenServiceInterface::class);
4940 }
5041
5142 /**
5243 * Test the complete workflow from Steps 1-16
5344 * Verify that REST-API updating product stock_item does not delete downloadable_product_links
5445 */
55- #[DataFixture(User::class, ['role_id ' => 1 ], 'admin_user ' )]
5646 #[DataFixture(DownloadableProduct::class, [
5747 'sku ' => 'downloadable-product ' ,
5848 'name ' => 'Downloadable Product Test ' ,
@@ -91,9 +81,6 @@ protected function setUp(): void
9181 ], 'downloadable_product ' )]
9282 public function testStockItemUpdatePreservesDownloadableLinks ()
9383 {
94- // Steps 1-7: Generate admin access token using AdminTokenService directly
95- $ adminToken = $ this ->generateAdminAccessToken ();
96-
9784 // Get the product SKU from the fixture
9885 $ product = $ this ->fixtures ->get ('downloadable_product ' );
9986 $ productSku = $ product ->getSku ();
@@ -104,7 +91,7 @@ public function testStockItemUpdatePreservesDownloadableLinks()
10491 $ originalLinks = $ originalProduct ['extension_attributes ' ]['downloadable_product_links ' ];
10592
10693 // Steps 8-14: Update product stock_item via catalogProductRepositoryV1 PUT endpoint
107- $ updatedProduct = $ this ->updateProductStockItem ($ adminToken , $ productSku );
94+ $ updatedProduct = $ this ->updateProductStockItem ($ productSku );
10895
10996 // Verify the API call was successful (Step 14: Server response Code=200)
11097 $ this ->assertNotEmpty ($ updatedProduct , 'API response should not be empty ' );
@@ -116,35 +103,20 @@ public function testStockItemUpdatePreservesDownloadableLinks()
116103 $ this ->verifyDownloadableLinksPreserved ($ originalLinks , $ productSku );
117104 }
118105
119- /**
120- * Generate Admin Access Token using AdminTokenService directly
121- */
122- private function generateAdminAccessToken (): string
123- {
124- $ adminUser = $ this ->fixtures ->get ('admin_user ' );
125-
126- // Use AdminTokenService directly to bypass TwoFactorAuth issues
127- $ accessToken = $ this ->adminTokenService ->createAdminAccessToken (
128- $ adminUser ->getUsername (),
129- \Magento \TestFramework \Bootstrap::ADMIN_PASSWORD
130- );
131-
132- $ this ->assertNotEmpty ($ accessToken , 'Admin access token should be generated ' );
133- $ this ->assertIsString ($ accessToken , 'Access token should be a string ' );
134-
135- return $ accessToken ;
136- }
137-
138106 /**
139107 * Update Product Stock Item
140108 */
141- private function updateProductStockItem (string $ adminToken , string $ productSku ): array
109+ private function updateProductStockItem (string $ productSku ): array
142110 {
143111 $ serviceInfo = [
144112 'rest ' => [
145113 'resourcePath ' => self ::PRODUCT_RESOURCE_PATH . '/ ' . $ productSku ,
146114 'httpMethod ' => Request::HTTP_METHOD_PUT ,
147- 'token ' => $ adminToken ,
115+ ],
116+ 'soap ' => [
117+ 'service ' => 'catalogProductRepositoryV1 ' ,
118+ 'serviceVersion ' => 'V1 ' ,
119+ 'operation ' => 'catalogProductRepositoryV1Save ' ,
148120 ],
149121 ];
150122
@@ -225,8 +197,13 @@ private function getProductBySku(string $sku): array
225197 'resourcePath ' => self ::PRODUCT_RESOURCE_PATH . '/ ' . $ sku ,
226198 'httpMethod ' => Request::HTTP_METHOD_GET ,
227199 ],
200+ 'soap ' => [
201+ 'service ' => 'catalogProductRepositoryV1 ' ,
202+ 'serviceVersion ' => 'V1 ' ,
203+ 'operation ' => 'catalogProductRepositoryV1Get ' ,
204+ ],
228205 ];
229206
230- return $ this ->_webApiCall ($ serviceInfo , []);
207+ return $ this ->_webApiCall ($ serviceInfo , [' sku ' => $ sku ]);
231208 }
232209}
0 commit comments