1313use Magento \User \Model \ResourceModel \User \CollectionFactory as UserCollectionFactory ;
1414use Magento \Authorization \Model \ResourceModel \Role \CollectionFactory as RoleCollectionFactory ;
1515use Magento \AdminAdobeIms \Logger \AdminAdobeImsLogger ;
16+ use Magento \AdminAdobeIms \Service \ImsConfig ;
1617use Magento \Authorization \Test \Fixture \Role as RoleFixture ;
1718use Magento \TestFramework \Fixture \DataFixture ;
1819use Magento \TestFramework \Fixture \AppArea ;
@@ -57,6 +58,11 @@ class SaveImsUserTest extends TestCase
5758 */
5859 private $ logger ;
5960
61+ /**
62+ * @var ImsConfig
63+ */
64+ private $ adminImsConfig ;
65+
6066 /**
6167 * @var Session
6268 */
@@ -78,16 +84,21 @@ protected function setUp(): void
7884 $ this ->userCollectionFactory = $ this ->objectManager ->create (UserCollectionFactory::class);
7985 $ this ->roleCollectionFactory = $ this ->objectManager ->create (RoleCollectionFactory::class);
8086 $ this ->logger = $ this ->createMock (AdminAdobeImsLogger::class);
87+ $ this ->adminImsConfig = $ this ->createMock (ImsConfig::class);
8188 $ this ->authSession = $ this ->objectManager ->create (Session::class);
8289 $ this ->saveImsUser = $ this ->objectManager ->create (
8390 SaveImsUser::class,
8491 [
8592 'user ' => $ this ->user ,
8693 'userCollectionFactory ' => $ this ->userCollectionFactory ,
8794 'roleCollectionFactory ' => $ this ->roleCollectionFactory ,
88- 'logger ' => $ this ->logger
95+ 'logger ' => $ this ->logger ,
96+ 'adminImsConfig ' => $ this ->adminImsConfig
8997 ]
9098 );
99+ $ this ->adminImsConfig ->expects ($ this ->any ())
100+ ->method ('enabled ' )
101+ ->willReturn (true );
91102 }
92103
93104 /**
@@ -152,4 +163,23 @@ public function testExceptionWhenSaveImsUserFails(): void
152163
153164 $ this ->saveImsUser ->save ($ profile );
154165 }
166+
167+ /**
168+ * Handle Exception when $profile array doesn't have email
169+ *
170+ * @return void
171+ * @throws CouldNotSaveException
172+ */
173+ #[
174+ AppArea(Area::AREA_ADMINHTML ),
175+ DataFixture(RoleFixture::class, ['role_name ' => self ::ADMIN_IMS_ROLE ]),
176+ ]
177+ public function testExceptionWhenProfileEmailNotFound (): void
178+ {
179+ $ profile = ['email ' => '' ];
180+ $ this ->expectException (CouldNotSaveException::class);
181+ $ this ->expectExceptionMessage ('Could not save ims user. ' );
182+
183+ $ this ->saveImsUser ->save ($ profile );
184+ }
155185}
0 commit comments