1010
1111use Magento \Downloadable \Test \Fixture \DownloadableProduct ;
1212use Magento \Framework \Webapi \Rest \Request ;
13+ use Magento \Integration \Api \AdminTokenServiceInterface ;
1314use Magento \TestFramework \Helper \Bootstrap ;
1415use Magento \TestFramework \TestCase \WebapiAbstract ;
1516use Magento \TestFramework \Fixture \DataFixture ;
2425 */
2526class StockItemUpdatePreservesLinksTest extends WebapiAbstract
2627{
27- private const ADMIN_TOKEN_RESOURCE_PATH = '/V1/integration/admin/token ' ;
2828 private const PRODUCT_RESOURCE_PATH = '/V1/products ' ;
2929
3030 /**
3131 * @var DataFixtureStorage
3232 */
3333 private $ fixtures ;
3434
35+ /**
36+ * @var AdminTokenServiceInterface
37+ */
38+ private $ adminTokenService ;
39+
3540 /**
3641 * @inheritDoc
3742 */
@@ -40,6 +45,7 @@ protected function setUp(): void
4045 parent ::setUp ();
4146 $ this ->_markTestAsRestOnly ();
4247 $ this ->fixtures = DataFixtureStorageManager::getStorage ();
48+ $ this ->adminTokenService = Bootstrap::getObjectManager ()->get (AdminTokenServiceInterface::class);
4349 }
4450
4551 /**
@@ -85,7 +91,7 @@ protected function setUp(): void
8591 ], 'downloadable_product ' )]
8692 public function testStockItemUpdatePreservesDownloadableLinks ()
8793 {
88- // Steps 1-7: Generate admin access token
94+ // Steps 1-7: Generate admin access token using AdminTokenService directly
8995 $ adminToken = $ this ->generateAdminAccessToken ();
9096
9197 // Get the product SKU from the fixture
@@ -111,24 +117,17 @@ public function testStockItemUpdatePreservesDownloadableLinks()
111117 }
112118
113119 /**
114- * Generate Admin Access Token
120+ * Generate Admin Access Token using AdminTokenService directly
115121 */
116122 private function generateAdminAccessToken (): string
117123 {
118- $ serviceInfo = [
119- 'rest ' => [
120- 'resourcePath ' => self ::ADMIN_TOKEN_RESOURCE_PATH ,
121- 'httpMethod ' => Request::HTTP_METHOD_POST ,
122- ],
123- ];
124-
125124 $ 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+ );
132131
133132 $ this ->assertNotEmpty ($ accessToken , 'Admin access token should be generated ' );
134133 $ this ->assertIsString ($ accessToken , 'Access token should be a string ' );
0 commit comments