5
5
*/
6
6
declare (strict_types=1 );
7
7
8
- namespace Magento \AdobeIms \Test \Unit \Block \Adminhtml ;
8
+ namespace Magento \AdminAdobeIms \Test \Unit \Block \Adminhtml ;
9
9
10
- use Magento \AdobeIms \Block \Adminhtml \SignIn as SignInBlock ;
10
+ use Magento \AdminAdobeIms \Block \Adminhtml \SignIn as SignInBlock ;
11
+ use Magento \AdminAdobeIms \Model \Auth ;
12
+ use Magento \AdminAdobeIms \Service \ImsConfig ;
11
13
use Magento \AdobeImsApi \Api \ConfigInterface ;
12
14
use Magento \AdobeImsApi \Api \ConfigProviderInterface ;
13
15
use Magento \AdobeImsApi \Api \Data \UserProfileInterface ;
19
21
use Magento \Framework \Serialize \Serializer \JsonHexTag ;
20
22
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
21
23
use Magento \Framework \UrlInterface ;
24
+ use Magento \User \Model \User ;
22
25
use PHPUnit \Framework \MockObject \MockObject ;
23
26
use PHPUnit \Framework \TestCase ;
24
27
@@ -62,6 +65,16 @@ class SignInTest extends TestCase
62
65
*/
63
66
private $ signInBlock ;
64
67
68
+ /**
69
+ * @var ImsConfig|MockObject
70
+ */
71
+ private ImsConfig $ adminAdobeImsConfig ;
72
+
73
+ /**
74
+ * @var Auth|MockObject
75
+ */
76
+ private Auth $ auth ;
77
+
65
78
/**
66
79
* Prepare test objects.
67
80
*/
@@ -83,6 +96,8 @@ protected function setUp(): void
83
96
$ this ->userAuthorizedMock = $ this ->createMock (UserAuthorizedInterface::class);
84
97
$ this ->userProfileRepositoryMock = $ this ->createMock (UserProfileRepositoryInterface::class);
85
98
$ this ->jsonHexTag = $ this ->createMock (JsonHexTag::class);
99
+ $ this ->adminAdobeImsConfig = $ this ->createMock (ImsConfig::class);
100
+ $ this ->auth = $ this ->createMock (Auth::class);
86
101
87
102
$ objectManager = new ObjectManager ($ this );
88
103
$ this ->signInBlock = $ objectManager ->getObject (
@@ -93,7 +108,10 @@ protected function setUp(): void
93
108
'userContext ' => $ this ->userContextMock ,
94
109
'userAuthorized ' => $ this ->userAuthorizedMock ,
95
110
'userProfileRepository ' => $ this ->userProfileRepositoryMock ,
96
- 'json ' => $ this ->jsonHexTag
111
+ 'json ' => $ this ->jsonHexTag ,
112
+ [],
113
+ 'adminAdobeImsConfig ' => $ this ->adminAdobeImsConfig ,
114
+ 'auth ' => $ this ->auth
97
115
]
98
116
);
99
117
}
@@ -126,6 +144,8 @@ public function testGetComponentJsonConfig(
126
144
->method ('getUserId ' )
127
145
->willReturn ($ userId );
128
146
147
+ $ this ->adminAdobeImsConfig ->method ('enabled ' )->willReturn (false );
148
+
129
149
$ userRepositoryWillReturn = $ userExists
130
150
? $ this ->returnValue ($ userProfile )
131
151
: $ this ->throwException (new NoSuchEntityException ());
@@ -149,13 +169,63 @@ public function testGetComponentJsonConfig(
149
169
$ this ->assertEquals ($ serializedResult , $ this ->signInBlock ->getComponentJsonConfig ());
150
170
}
151
171
172
+ /**
173
+ * @dataProvider userDataProviderWithAdminAdobeImsEnabled
174
+ * @param int $userId
175
+ * @param bool $userExists
176
+ * @param array $userData
177
+ * @param array $configProviderData
178
+ * @param array $expectedData
179
+ */
180
+ public function testGetComponentJsonConfigWithAdminAdobeImsEnabled (
181
+ int $ userId ,
182
+ bool $ userExists ,
183
+ array $ userData ,
184
+ array $ configProviderData ,
185
+ array $ expectedData
186
+ ): void {
187
+ $ this ->userAuthorizedMock ->expects ($ this ->once ())
188
+ ->method ('execute ' )
189
+ ->willReturn ($ userData ['isAuthorized ' ]);
190
+
191
+ $ userProfile = $ this ->createMock (User::class);
192
+ $ userProfile ->method ('getFirstName ' )->willReturn ($ userData ['firstname ' ]);
193
+ $ userProfile ->method ('getLastName ' )->willReturn ($ userData ['lastname ' ]);
194
+ $ userProfile ->method ('getEmail ' )->willReturn ($ userData ['email ' ]);
195
+
196
+ $ this ->adminAdobeImsConfig ->method ('enabled ' )->willReturn (true );
197
+ $ this ->auth ->method ('getUser ' )->willReturn ($ userProfile );
198
+ $ this ->userContextMock ->method ('getUserId ' )->willReturn ($ userId );
199
+
200
+ $ userRepositoryWillReturn = $ userExists
201
+ ? $ this ->returnValue ($ userProfile )
202
+ : $ this ->throwException (new NoSuchEntityException ());
203
+ $ this ->userProfileRepositoryMock
204
+ ->method ('getByUserId ' )
205
+ ->with ($ userId )
206
+ ->will ($ userRepositoryWillReturn );
207
+
208
+ $ configProviderMock = $ this ->createMock (ConfigProviderInterface::class);
209
+ $ configProviderMock ->method ('get ' )->willReturn ($ configProviderData );
210
+ $ this ->signInBlock ->setData ('configProviders ' , [$ configProviderMock ]);
211
+
212
+ $ serializedResult = 'Some result ' ;
213
+ $ this ->jsonHexTag ->expects ($ this ->once ())
214
+ ->method ('serialize ' )
215
+ ->with ($ expectedData )
216
+ ->willReturn ($ serializedResult );
217
+
218
+ $ this ->assertEquals ($ serializedResult , $ this ->signInBlock ->getComponentJsonConfig ());
219
+ }
220
+
152
221
/**
153
222
* Returns default component config
154
223
*
155
224
* @param array $userData
225
+ * @param bool $isGlobalSignInEnabled
156
226
* @return array
157
227
*/
158
- private function getDefaultComponentConfig (array $ userData ): array
228
+ private function getDefaultComponentConfig (array $ userData, bool $ isGlobalSignInEnabled = false ): array
159
229
{
160
230
return [
161
231
'component ' => 'Magento_AdobeIms/js/signIn ' ,
@@ -172,7 +242,8 @@ private function getDefaultComponentConfig(array $userData): array
172
242
'successCode ' => self ::RESPONSE_SUCCESS_CODE ,
173
243
'errorCode ' => self ::RESPONSE_ERROR_CODE
174
244
]
175
- ]
245
+ ],
246
+ 'isGlobalSignInEnabled ' => $ isGlobalSignInEnabled
176
247
];
177
248
}
178
249
@@ -281,4 +352,33 @@ public function userDataProvider(): array
281
352
]
282
353
];
283
354
}
355
+
356
+ /**
357
+ * @return array
358
+ */
359
+ public function userDataProviderWithAdminAdobeImsEnabled (): array
360
+ {
361
+ return [
362
+ 'Existing authorized user with Admin Adobe IMS enabled ' => [
363
+ 15 ,
364
+ true ,
365
+ [
366
+ 'isAuthorized ' => true ,
367
+ 'firstname ' => 'John ' ,
368
+ 'lastname ' => 'Doe ' ,
369
+ 'email ' => 'john@email.com ' ,
370
+ ],
371
+ [],
372
+ $ this ->getDefaultComponentConfig (
373
+ [
374
+ 'isAuthorized ' => true ,
375
+ 'name ' => 'John Doe ' ,
376
+ 'email ' => 'john@email.com ' ,
377
+ 'image ' => ''
378
+ ],
379
+ true
380
+ )
381
+ ]
382
+ ];
383
+ }
284
384
}
0 commit comments