77
88namespace Magento \ConfigurableProduct \Api ;
99
10+ use Magento \Authorization \Test \Fixture \Role ;
1011use Magento \Catalog \Test \Fixture \Attribute as AttributeFixture ;
1112use Magento \Framework \Exception \NoSuchEntityException ;
12- use Magento \Framework \ Module \ Manager ;
13+ use Magento \Integration \ Api \ AdminTokenServiceInterface ;
1314use Magento \TestFramework \TestCase \WebapiAbstract ;
1415use Magento \Framework \Webapi \Rest \Request ;
1516use Magento \TestFramework \Helper \Bootstrap ;
1617use Magento \TestFramework \Fixture \Config ;
1718use Magento \TestFramework \Fixture \DataFixture ;
1819use Magento \TestFramework \Fixture \DataFixtureStorage ;
1920use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
21+ use Magento \User \Test \Fixture \User ;
2022
2123/**
2224 * Complete workflow test for configurable product creation via REST API
@@ -37,17 +39,19 @@ class CompleteConfigurableProductWorkflowTest extends WebapiAbstract
3739 */
3840 private DataFixtureStorage $ fixtures ;
3941
42+ /**
43+ * @var AdminTokenServiceInterface
44+ */
45+ private AdminTokenServiceInterface $ adminTokens ;
46+
4047 protected function setUp (): void
4148 {
4249 parent ::setUp ();
4350 $ this ->_markTestAsRestOnly ();
4451 $ this ->fixtures = Bootstrap::getObjectManager ()
4552 ->get (DataFixtureStorageManager::class)
4653 ->getStorage ();
47- $ this ->moduleManager = Bootstrap::getObjectManager ()->get (Manager::class);
48- if ($ this ->moduleManager ->isEnabled ('Magento_TwoFactorAuth ' )) {
49- $ this ->markTestSkipped ('Skipped, because this token obtaining logic is rewritten in TwoFactorAuth. ' );
50- }
54+ $ this ->adminTokens = Bootstrap::getObjectManager ()->get (AdminTokenServiceInterface::class);
5155 }
5256
5357 /**
@@ -63,6 +67,23 @@ protected function setUp(): void
6367 * @throws NoSuchEntityException
6468 */
6569 #[
70+ DataFixture(
71+ Role::class,
72+ ['role_name ' => 'Test Admin Role ' , 'resources ' => ['Magento_Backend::all ' ]],
73+ 'admin_role '
74+ ),
75+ DataFixture(
76+ User::class,
77+ [
78+ 'username ' => 'test_admin_user ' ,
79+ 'firstname ' => 'Test ' ,
80+ 'lastname ' => 'Admin ' ,
81+ 82+ 'password ' => \Magento \TestFramework \Bootstrap::ADMIN_PASSWORD ,
83+ 'role_id ' => '$admin_role.role_id$ '
84+ ],
85+ 'admin_user '
86+ ),
6687 DataFixture(
6788 AttributeFixture::class,
6889 [
@@ -162,6 +183,28 @@ public function testCompleteConfigurableProductWorkflow(): void
162183 *
163184 * @return void
164185 */
186+ #[
187+ DataFixture(
188+ Role::class,
189+ [
190+ 'role_name ' => 'Test Admin Role ' ,
191+ 'resources ' => ['Magento_Backend::all ' ]
192+ ],
193+ 'admin_role '
194+ ),
195+ DataFixture(
196+ User::class,
197+ [
198+ 'username ' => 'test_admin_user ' ,
199+ 'firstname ' => 'Test ' ,
200+ 'lastname ' => 'Admin ' ,
201+ 202+ 'password ' => \Magento \TestFramework \Bootstrap::ADMIN_PASSWORD ,
203+ 'role_id ' => '$admin_role.role_id$ '
204+ ],
205+ 'admin_user '
206+ )
207+ ]
165208 public function testLinkNonExistentChild (): void
166209 {
167210 $ this ->adminToken = $ this ->getAdminAccessToken ();
@@ -179,25 +222,17 @@ public function testLinkNonExistentChild(): void
179222 }
180223
181224 /**
182- * Get admin access token
225+ * Get admin access token using fixture-created user
183226 *
184227 * @return string
185228 */
186229 private function getAdminAccessToken (): string
187230 {
188- $ serviceInfo = [
189- 'rest ' => [
190- 'resourcePath ' => '/V1/integration/admin/token ' ,
191- 'httpMethod ' => Request::HTTP_METHOD_POST ,
192- ],
193- ];
231+ $ adminUser = $ this ->fixtures ->get ('admin_user ' );
194232
195- return $ this ->_webApiCall (
196- $ serviceInfo ,
197- [
198- 'username ' => \Magento \TestFramework \Bootstrap::ADMIN_NAME ,
199- 'password ' => \Magento \TestFramework \Bootstrap::ADMIN_PASSWORD
200- ]
233+ return $ this ->adminTokens ->createAdminAccessToken (
234+ $ adminUser ->getUsername (),
235+ \Magento \TestFramework \Bootstrap::ADMIN_PASSWORD
201236 );
202237 }
203238
0 commit comments