1414use OCA \User_LDAP \User \User ;
1515use OCP \AppFramework \Services \IAppConfig ;
1616use OCP \Config \IUserConfig ;
17+ use OCP \EventDispatcher \IEventDispatcher ;
1718use OCP \IAvatar ;
1819use OCP \IAvatarManager ;
1920use OCP \IConfig ;
2223use OCP \IUserManager ;
2324use OCP \Notification \IManager as INotificationManager ;
2425use OCP \Notification \INotification ;
25- use OCP \Util ;
26+ use OCP \Server ;
27+ use OCP \User \Events \UserLoggedInEvent ;
2628use PHPUnit \Framework \MockObject \MockObject ;
2729use Psr \Log \LoggerInterface ;
2830
@@ -44,6 +46,7 @@ class UserTest extends \Test\TestCase {
4446 protected Image &MockObject $ image ;
4547 protected IAvatarManager &MockObject $ avatarManager ;
4648 protected LoggerInterface &MockObject $ logger ;
49+ protected IEventDispatcher $ eventDispatcher ;
4750 protected string $ uid = 'alice ' ;
4851 protected string $ dn = 'uid=alice,dc=foo,dc=bar ' ;
4952 protected User $ user ;
@@ -69,6 +72,7 @@ protected function setUp(): void {
6972 $ this ->image = $ this ->createMock (Image::class);
7073 $ this ->userManager = $ this ->createMock (IUserManager::class);
7174 $ this ->notificationManager = $ this ->createMock (INotificationManager::class);
75+ $ this ->eventDispatcher = Server::get (IEventDispatcher::class);
7276
7377 $ this ->user = new User (
7478 $ this ->uid ,
@@ -81,7 +85,8 @@ protected function setUp(): void {
8185 $ this ->logger ,
8286 $ this ->avatarManager ,
8387 $ this ->userManager ,
84- $ this ->notificationManager
88+ $ this ->notificationManager ,
89+ $ this ->eventDispatcher ,
8590 );
8691 }
8792
@@ -933,8 +938,9 @@ public function testProcessAttributes(): void {
933938 }
934939 \OC_Hook::clear ();//disconnect irrelevant hooks
935940 $ userMock ->processAttributes ($ record );
936- /** @noinspection PhpUnhandledExceptionInspection */
937- \OC_Hook::emit ('OC_User ' , 'post_login ' , ['uid ' => $ this ->uid ]);
941+ $ iuserMock = $ this ->createMock (IUser::class);
942+ $ iuserMock ->method ('getUID ' )->willReturn ($ this ->uid );
943+ $ this ->eventDispatcher ->dispatchTyped (new UserLoggedInEvent ($ iuserMock , $ this ->uid , null , true ));
938944 }
939945
940946 public static function emptyHomeFolderAttributeValueProvider (): array {
@@ -1117,10 +1123,9 @@ public function testHandlePasswordExpiryWarningDefaultPolicy(): void {
11171123 $ this ->notificationManager ->expects ($ this ->exactly (1 ))
11181124 ->method ('notify ' );
11191125
1120- \OC_Hook::clear ();//disconnect irrelevant hooks
1121- Util::connectHook ('OC_User ' , 'post_login ' , $ this ->user , 'handlePasswordExpiry ' );
1122- /** @noinspection PhpUnhandledExceptionInspection */
1123- \OC_Hook::emit ('OC_User ' , 'post_login ' , ['uid ' => $ this ->uid ]);
1126+ $ iuserMock = $ this ->createMock (IUser::class);
1127+ $ iuserMock ->method ('getUID ' )->willReturn ($ this ->uid );
1128+ $ this ->eventDispatcher ->dispatchTyped (new UserLoggedInEvent ($ iuserMock , $ this ->uid , null , true ));
11241129 }
11251130
11261131 public function testHandlePasswordExpiryWarningCustomPolicy (): void {
@@ -1181,9 +1186,8 @@ public function testHandlePasswordExpiryWarningCustomPolicy(): void {
11811186 $ this ->notificationManager ->expects ($ this ->exactly (1 ))
11821187 ->method ('notify ' );
11831188
1184- \OC_Hook::clear ();//disconnect irrelevant hooks
1185- Util::connectHook ('OC_User ' , 'post_login ' , $ this ->user , 'handlePasswordExpiry ' );
1186- /** @noinspection PhpUnhandledExceptionInspection */
1187- \OC_Hook::emit ('OC_User ' , 'post_login ' , ['uid ' => $ this ->uid ]);
1189+ $ iuserMock = $ this ->createMock (IUser::class);
1190+ $ iuserMock ->method ('getUID ' )->willReturn ($ this ->uid );
1191+ $ this ->eventDispatcher ->dispatchTyped (new UserLoggedInEvent ($ iuserMock , $ this ->uid , null , true ));
11881192 }
11891193}
0 commit comments