10
10
11
11
use Magento \Downloadable \Test \Fixture \DownloadableProduct ;
12
12
use Magento \Framework \Webapi \Rest \Request ;
13
- use Magento \Integration \Api \AdminTokenServiceInterface ;
14
- use Magento \TestFramework \Helper \Bootstrap ;
15
13
use Magento \TestFramework \TestCase \WebapiAbstract ;
16
14
use Magento \TestFramework \Fixture \DataFixture ;
17
15
use Magento \TestFramework \Fixture \DataFixtureStorage ;
18
16
use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
19
- use Magento \User \Test \Fixture \User ;
20
17
21
18
/**
22
19
* Test to verify REST-API updating product stock_item does not delete downloadable_product_links
@@ -32,11 +29,6 @@ class StockItemUpdatePreservesLinksTest extends WebapiAbstract
32
29
*/
33
30
private $ fixtures ;
34
31
35
- /**
36
- * @var AdminTokenServiceInterface
37
- */
38
- private $ adminTokenService ;
39
-
40
32
/**
41
33
* @inheritDoc
42
34
*/
@@ -45,14 +37,12 @@ protected function setUp(): void
45
37
parent ::setUp ();
46
38
$ this ->_markTestAsRestOnly ();
47
39
$ this ->fixtures = DataFixtureStorageManager::getStorage ();
48
- $ this ->adminTokenService = Bootstrap::getObjectManager ()->get (AdminTokenServiceInterface::class);
49
40
}
50
41
51
42
/**
52
43
* Test the complete workflow from Steps 1-16
53
44
* Verify that REST-API updating product stock_item does not delete downloadable_product_links
54
45
*/
55
- #[DataFixture(User::class, ['role_id ' => 1 ], 'admin_user ' )]
56
46
#[DataFixture(DownloadableProduct::class, [
57
47
'sku ' => 'downloadable-product ' ,
58
48
'name ' => 'Downloadable Product Test ' ,
@@ -91,9 +81,6 @@ protected function setUp(): void
91
81
], 'downloadable_product ' )]
92
82
public function testStockItemUpdatePreservesDownloadableLinks ()
93
83
{
94
- // Steps 1-7: Generate admin access token using AdminTokenService directly
95
- $ adminToken = $ this ->generateAdminAccessToken ();
96
-
97
84
// Get the product SKU from the fixture
98
85
$ product = $ this ->fixtures ->get ('downloadable_product ' );
99
86
$ productSku = $ product ->getSku ();
@@ -104,7 +91,7 @@ public function testStockItemUpdatePreservesDownloadableLinks()
104
91
$ originalLinks = $ originalProduct ['extension_attributes ' ]['downloadable_product_links ' ];
105
92
106
93
// Steps 8-14: Update product stock_item via catalogProductRepositoryV1 PUT endpoint
107
- $ updatedProduct = $ this ->updateProductStockItem ($ adminToken , $ productSku );
94
+ $ updatedProduct = $ this ->updateProductStockItem ($ productSku );
108
95
109
96
// Verify the API call was successful (Step 14: Server response Code=200)
110
97
$ this ->assertNotEmpty ($ updatedProduct , 'API response should not be empty ' );
@@ -116,35 +103,20 @@ public function testStockItemUpdatePreservesDownloadableLinks()
116
103
$ this ->verifyDownloadableLinksPreserved ($ originalLinks , $ productSku );
117
104
}
118
105
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
-
138
106
/**
139
107
* Update Product Stock Item
140
108
*/
141
- private function updateProductStockItem (string $ adminToken , string $ productSku ): array
109
+ private function updateProductStockItem (string $ productSku ): array
142
110
{
143
111
$ serviceInfo = [
144
112
'rest ' => [
145
113
'resourcePath ' => self ::PRODUCT_RESOURCE_PATH . '/ ' . $ productSku ,
146
114
'httpMethod ' => Request::HTTP_METHOD_PUT ,
147
- 'token ' => $ adminToken ,
115
+ ],
116
+ 'soap ' => [
117
+ 'service ' => 'catalogProductRepositoryV1 ' ,
118
+ 'serviceVersion ' => 'V1 ' ,
119
+ 'operation ' => 'catalogProductRepositoryV1Save ' ,
148
120
],
149
121
];
150
122
@@ -225,8 +197,13 @@ private function getProductBySku(string $sku): array
225
197
'resourcePath ' => self ::PRODUCT_RESOURCE_PATH . '/ ' . $ sku ,
226
198
'httpMethod ' => Request::HTTP_METHOD_GET ,
227
199
],
200
+ 'soap ' => [
201
+ 'service ' => 'catalogProductRepositoryV1 ' ,
202
+ 'serviceVersion ' => 'V1 ' ,
203
+ 'operation ' => 'catalogProductRepositoryV1Get ' ,
204
+ ],
228
205
];
229
206
230
- return $ this ->_webApiCall ($ serviceInfo , []);
207
+ return $ this ->_webApiCall ($ serviceInfo , [' sku ' => $ sku ]);
231
208
}
232
209
}
0 commit comments