13
13
use Magento \User \Model \ResourceModel \User \CollectionFactory as UserCollectionFactory ;
14
14
use Magento \Authorization \Model \ResourceModel \Role \CollectionFactory as RoleCollectionFactory ;
15
15
use Magento \AdminAdobeIms \Logger \AdminAdobeImsLogger ;
16
+ use Magento \AdminAdobeIms \Service \ImsConfig ;
16
17
use Magento \Authorization \Test \Fixture \Role as RoleFixture ;
17
18
use Magento \TestFramework \Fixture \DataFixture ;
18
19
use Magento \TestFramework \Fixture \AppArea ;
@@ -57,6 +58,11 @@ class SaveImsUserTest extends TestCase
57
58
*/
58
59
private $ logger ;
59
60
61
+ /**
62
+ * @var ImsConfig
63
+ */
64
+ private $ adminImsConfig ;
65
+
60
66
/**
61
67
* @var Session
62
68
*/
@@ -78,16 +84,21 @@ protected function setUp(): void
78
84
$ this ->userCollectionFactory = $ this ->objectManager ->create (UserCollectionFactory::class);
79
85
$ this ->roleCollectionFactory = $ this ->objectManager ->create (RoleCollectionFactory::class);
80
86
$ this ->logger = $ this ->createMock (AdminAdobeImsLogger::class);
87
+ $ this ->adminImsConfig = $ this ->createMock (ImsConfig::class);
81
88
$ this ->authSession = $ this ->objectManager ->create (Session::class);
82
89
$ this ->saveImsUser = $ this ->objectManager ->create (
83
90
SaveImsUser::class,
84
91
[
85
92
'user ' => $ this ->user ,
86
93
'userCollectionFactory ' => $ this ->userCollectionFactory ,
87
94
'roleCollectionFactory ' => $ this ->roleCollectionFactory ,
88
- 'logger ' => $ this ->logger
95
+ 'logger ' => $ this ->logger ,
96
+ 'adminImsConfig ' => $ this ->adminImsConfig
89
97
]
90
98
);
99
+ $ this ->adminImsConfig ->expects ($ this ->any ())
100
+ ->method ('enabled ' )
101
+ ->willReturn (true );
91
102
}
92
103
93
104
/**
@@ -152,4 +163,23 @@ public function testExceptionWhenSaveImsUserFails(): void
152
163
153
164
$ this ->saveImsUser ->save ($ profile );
154
165
}
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
+ }
155
185
}
0 commit comments