-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(provisioning_api): Translate exceptions shown in the frontend + r…
…eplace some deprecations Signed-off-by: Ferdinand Thiessen <[email protected]>
- Loading branch information
Showing
2 changed files
with
48 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,6 +129,10 @@ protected function setUp(): void { | |
$this->eventDispatcher = $this->createMock(IEventDispatcher::class); | ||
$this->phoneNumberUtil = new PhoneNumberUtil(); | ||
|
||
$l10n = $this->createMock(IL10N::class); | ||
$l10n->method('t')->willReturnCallback(fn (string $txt, array $replacement = []) => sprintf($txt, ...$replacement)); | ||
$this->l10nFactory->method('get')->with('provisioning_api')->willReturn($l10n); | ||
|
||
$this->api = $this->getMockBuilder(UsersController::class) | ||
->setConstructorArgs([ | ||
'provisioning_api', | ||
|
@@ -138,9 +142,9 @@ protected function setUp(): void { | |
$this->groupManager, | ||
$this->userSession, | ||
$this->accountManager, | ||
$this->l10nFactory, | ||
$this->urlGenerator, | ||
$this->logger, | ||
$this->l10nFactory, | ||
$this->newUserMailHelper, | ||
$this->secureRandom, | ||
$this->remoteWipe, | ||
|
@@ -274,20 +278,14 @@ public function testAddUserAlreadyExisting() { | |
->method('isAdmin') | ||
->with('adminUser') | ||
->willReturn(true); | ||
$l10n = $this->createMock(IL10N::class); | ||
$this->l10nFactory | ||
->expects($this->once()) | ||
->method('get') | ||
->with('provisioning_api') | ||
->willReturn($l10n); | ||
|
||
$this->api->addUser('AlreadyExistingUser', 'password', '', '', []); | ||
} | ||
|
||
|
||
public function testAddUserNonExistingGroup() { | ||
$this->expectException(\OCP\AppFramework\OCS\OCSException::class); | ||
$this->expectExceptionMessage('group NonExistingGroup does not exist'); | ||
$this->expectExceptionMessage('Group NonExistingGroup does not exist'); | ||
$this->expectExceptionCode(104); | ||
|
||
$this->userManager | ||
|
@@ -323,7 +321,7 @@ public function testAddUserNonExistingGroup() { | |
|
||
public function testAddUserExistingGroupNonExistingGroup() { | ||
$this->expectException(\OCP\AppFramework\OCS\OCSException::class); | ||
$this->expectExceptionMessage('group NonExistingGroup does not exist'); | ||
$this->expectExceptionMessage('Group NonExistingGroup does not exist'); | ||
$this->expectExceptionCode(104); | ||
|
||
$this->userManager | ||
|
@@ -400,6 +398,9 @@ public function testAddUserSuccessful() { | |
} | ||
|
||
public function testAddUserSuccessfulWithDisplayName() { | ||
/** | ||
* @var UserController | ||
*/ | ||
$api = $this->getMockBuilder(UsersController::class) | ||
->setConstructorArgs([ | ||
'provisioning_api', | ||
|
@@ -409,9 +410,9 @@ public function testAddUserSuccessfulWithDisplayName() { | |
$this->groupManager, | ||
$this->userSession, | ||
$this->accountManager, | ||
$this->l10nFactory, | ||
$this->urlGenerator, | ||
$this->logger, | ||
$this->l10nFactory, | ||
$this->newUserMailHelper, | ||
$this->secureRandom, | ||
$this->remoteWipe, | ||
|
@@ -758,7 +759,7 @@ public function testAddUserUnsuccessful() { | |
|
||
public function testAddUserAsSubAdminNoGroup() { | ||
$this->expectException(\OCP\AppFramework\OCS\OCSException::class); | ||
$this->expectExceptionMessage('no group specified (required for subadmins)'); | ||
$this->expectExceptionMessage('No group specified (required for sub-admins)'); | ||
$this->expectExceptionCode(106); | ||
|
||
$loggedInUser = $this->getMockBuilder(IUser::class) | ||
|
@@ -791,7 +792,7 @@ public function testAddUserAsSubAdminNoGroup() { | |
|
||
public function testAddUserAsSubAdminValidGroupNotSubAdmin() { | ||
$this->expectException(\OCP\AppFramework\OCS\OCSException::class); | ||
$this->expectExceptionMessage('insufficient privileges for group ExistingGroup'); | ||
$this->expectExceptionMessage('Insufficient privileges for group ExistingGroup'); | ||
$this->expectExceptionCode(105); | ||
|
||
$loggedInUser = $this->getMockBuilder(IUser::class) | ||
|
@@ -3199,7 +3200,7 @@ public function testRemoveFromGroupAsAdminFromAdmin() { | |
|
||
public function testRemoveFromGroupAsSubAdminFromSubAdmin() { | ||
$this->expectException(\OCP\AppFramework\OCS\OCSException::class); | ||
$this->expectExceptionMessage('Cannot remove yourself from this group as you are a SubAdmin'); | ||
$this->expectExceptionMessage('Cannot remove yourself from this group as you are a sub-admin'); | ||
$this->expectExceptionCode(105); | ||
|
||
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock(); | ||
|
@@ -3254,7 +3255,7 @@ public function testRemoveFromGroupAsSubAdminFromSubAdmin() { | |
|
||
public function testRemoveFromGroupAsSubAdminFromLastSubAdminGroup() { | ||
$this->expectException(\OCP\AppFramework\OCS\OCSException::class); | ||
$this->expectExceptionMessage('Not viable to remove user from the last group you are SubAdmin of'); | ||
$this->expectExceptionMessage('Not viable to remove user from the last group you are sub-admin of'); | ||
$this->expectExceptionCode(105); | ||
|
||
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock(); | ||
|
@@ -3394,7 +3395,7 @@ public function testAddSubAdminWithNotExistingTargetGroup() { | |
|
||
public function testAddSubAdminToAdminGroup() { | ||
$this->expectException(\OCP\AppFramework\OCS\OCSException::class); | ||
$this->expectExceptionMessage('Cannot create subadmins for admin group'); | ||
$this->expectExceptionMessage('Cannot create sub-admins for admin group'); | ||
$this->expectExceptionCode(103); | ||
|
||
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock(); | ||
|
@@ -3517,7 +3518,7 @@ public function testRemoveSubAdminNotExistingTargetGroup() { | |
|
||
public function testRemoveSubAdminFromNotASubadmin() { | ||
$this->expectException(\OCP\AppFramework\OCS\OCSException::class); | ||
$this->expectExceptionMessage('User is not a subadmin of this group'); | ||
$this->expectExceptionMessage('User is not a sub-admin of this group'); | ||
$this->expectExceptionCode(102); | ||
|
||
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock(); | ||
|
@@ -3692,9 +3693,9 @@ public function testGetCurrentUserLoggedIn() { | |
$this->groupManager, | ||
$this->userSession, | ||
$this->accountManager, | ||
$this->l10nFactory, | ||
$this->urlGenerator, | ||
$this->logger, | ||
$this->l10nFactory, | ||
$this->newUserMailHelper, | ||
$this->secureRandom, | ||
$this->remoteWipe, | ||
|
@@ -3779,9 +3780,9 @@ public function testGetUser() { | |
$this->groupManager, | ||
$this->userSession, | ||
$this->accountManager, | ||
$this->l10nFactory, | ||
$this->urlGenerator, | ||
$this->logger, | ||
$this->l10nFactory, | ||
$this->newUserMailHelper, | ||
$this->secureRandom, | ||
$this->remoteWipe, | ||
|
@@ -4048,9 +4049,6 @@ public function testResendWelcomeMessageSuccessWithFallbackLanguage() { | |
->expects($this->once()) | ||
->method('getEmailAddress') | ||
->willReturn('[email protected]'); | ||
$l10n = $this->getMockBuilder(IL10N::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$emailTemplate = $this->createMock(IEMailTemplate::class); | ||
$this->newUserMailHelper | ||
->expects($this->once()) | ||
|