10
10
11
11
use Magento \Downloadable \Test \Fixture \DownloadableProduct ;
12
12
use Magento \Framework \Webapi \Rest \Request ;
13
+ use Magento \Integration \Api \AdminTokenServiceInterface ;
13
14
use Magento \TestFramework \Helper \Bootstrap ;
14
15
use Magento \TestFramework \TestCase \WebapiAbstract ;
15
16
use Magento \TestFramework \Fixture \DataFixture ;
24
25
*/
25
26
class StockItemUpdatePreservesLinksTest extends WebapiAbstract
26
27
{
27
- private const ADMIN_TOKEN_RESOURCE_PATH = '/V1/integration/admin/token ' ;
28
28
private const PRODUCT_RESOURCE_PATH = '/V1/products ' ;
29
29
30
30
/**
31
31
* @var DataFixtureStorage
32
32
*/
33
33
private $ fixtures ;
34
34
35
+ /**
36
+ * @var AdminTokenServiceInterface
37
+ */
38
+ private $ adminTokenService ;
39
+
35
40
/**
36
41
* @inheritDoc
37
42
*/
@@ -40,6 +45,7 @@ protected function setUp(): void
40
45
parent ::setUp ();
41
46
$ this ->_markTestAsRestOnly ();
42
47
$ this ->fixtures = DataFixtureStorageManager::getStorage ();
48
+ $ this ->adminTokenService = Bootstrap::getObjectManager ()->get (AdminTokenServiceInterface::class);
43
49
}
44
50
45
51
/**
@@ -85,7 +91,7 @@ protected function setUp(): void
85
91
], 'downloadable_product ' )]
86
92
public function testStockItemUpdatePreservesDownloadableLinks ()
87
93
{
88
- // Steps 1-7: Generate admin access token
94
+ // Steps 1-7: Generate admin access token using AdminTokenService directly
89
95
$ adminToken = $ this ->generateAdminAccessToken ();
90
96
91
97
// Get the product SKU from the fixture
@@ -111,24 +117,17 @@ public function testStockItemUpdatePreservesDownloadableLinks()
111
117
}
112
118
113
119
/**
114
- * Generate Admin Access Token
120
+ * Generate Admin Access Token using AdminTokenService directly
115
121
*/
116
122
private function generateAdminAccessToken (): string
117
123
{
118
- $ serviceInfo = [
119
- 'rest ' => [
120
- 'resourcePath ' => self ::ADMIN_TOKEN_RESOURCE_PATH ,
121
- 'httpMethod ' => Request::HTTP_METHOD_POST ,
122
- ],
123
- ];
124
-
125
124
$ adminUser = $ this ->fixtures ->get ('admin_user ' );
126
- $ requestData = [
127
- ' username ' => $ adminUser -> getUsername (),
128
- ' password ' => \ Magento \ TestFramework \Bootstrap:: ADMIN_PASSWORD ,
129
- ];
130
-
131
- $ accessToken = $ this -> _webApiCall ( $ serviceInfo , $ requestData );
125
+
126
+ // Use AdminTokenService directly to bypass TwoFactorAuth issues
127
+ $ accessToken = $ this -> adminTokenService -> createAdminAccessToken (
128
+ $ adminUser -> getUsername (),
129
+ \ Magento \ TestFramework \Bootstrap:: ADMIN_PASSWORD
130
+ );
132
131
133
132
$ this ->assertNotEmpty ($ accessToken , 'Admin access token should be generated ' );
134
133
$ this ->assertIsString ($ accessToken , 'Access token should be a string ' );
0 commit comments