1919use OCP \AppFramework \Http \RedirectResponse ;
2020use OCP \AppFramework \Http \TemplateResponse ;
2121use OCP \AppFramework \Services \IAppConfig ;
22+ use OCP \EventDispatcher \IEventDispatcher ;
2223use OCP \IConfig ;
2324use OCP \IL10N ;
2425use OCP \IRequest ;
2829use OCP \IUserSession ;
2930use OCP \Security \ICrypto ;
3031use OCP \Security \ITrustedDomainHelper ;
32+ use OCP \User \Events \UserLoggedInEvent ;
3133use Override ;
3234use PHPUnit \Framework \Attributes \DataProvider ;
3335use PHPUnit \Framework \MockObject \MockObject ;
@@ -51,6 +53,7 @@ class SAMLControllerTest extends TestCase {
5153 private SAMLController $ samlController ;
5254 private ITrustedDomainHelper |MockObject $ trustedDomainController ;
5355 private SessionService |MockObject $ sessionService ;
56+ private IEventDispatcher |MockObject $ eventDispatcher ;
5457
5558 #[Override]
5659 protected function setUp (): void {
@@ -71,6 +74,7 @@ protected function setUp(): void {
7174 $ this ->crypto = $ this ->createMock (ICrypto::class);
7275 $ this ->trustedDomainController = $ this ->createMock (ITrustedDomainHelper::class);
7376 $ this ->sessionService = $ this ->createMock (SessionService::class);
77+ $ this ->eventDispatcher = $ this ->createMock (IEventDispatcher::class);
7478
7579 $ this ->l ->expects ($ this ->any ())->method ('t ' )->willReturnCallback (
7680 static fn (string $ param ): string => $ param
@@ -95,7 +99,8 @@ protected function setUp(): void {
9599 $ this ->userData ,
96100 $ this ->crypto ,
97101 $ this ->trustedDomainController ,
98- $ this ->sessionService
102+ $ this ->sessionService ,
103+ $ this ->eventDispatcher ,
99104 );
100105 }
101106
@@ -304,6 +309,11 @@ public function testLoginWithEnvVariable(array $samlUserData, string $redirect,
304309 ->method ('createUserIfNotExists ' )
305310 ->with ('MyUid ' );
306311
312+ $ this ->eventDispatcher
313+ ->expects ($ this ->once ())
314+ ->method ('dispatchTyped ' )
315+ ->with (new UserLoggedInEvent ($ user , 'MyUid ' , null , false ));
316+
307317 $ expected = new RedirectResponse ($ redirect );
308318 $ result = $ this ->samlController ->login (1 );
309319 $ this ->assertEquals ($ expected , $ result );
0 commit comments