|
|
|
|
@ -52,7 +52,9 @@ use OCA\Settings\Mailer\NewUserMailHelper; |
|
|
|
|
use OCP\Accounts\IAccount; |
|
|
|
|
use OCP\Accounts\IAccountManager; |
|
|
|
|
use OCP\Accounts\IAccountProperty; |
|
|
|
|
use OCP\Accounts\IAccountPropertyCollection; |
|
|
|
|
use OCP\AppFramework\Http\DataResponse; |
|
|
|
|
use OCP\AppFramework\OCS\OCSException; |
|
|
|
|
use OCP\EventDispatcher\IEventDispatcher; |
|
|
|
|
use OCP\IConfig; |
|
|
|
|
use OCP\IGroup; |
|
|
|
|
@ -1544,7 +1546,162 @@ class UsersControllerTest extends TestCase { |
|
|
|
|
$this->assertEquals([], $this->api->editUser('UserToEdit', 'email', 'demo@nextcloud.com')->getData()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testEditUserRegularUserSelfEditAddAdditionalEmailValid(): void { |
|
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class) |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$loggedInUser |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getUID') |
|
|
|
|
->willReturn('UID'); |
|
|
|
|
$targetUser = $this->getMockBuilder(IUser::class) |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$this->userSession |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getUser') |
|
|
|
|
->willReturn($loggedInUser); |
|
|
|
|
$this->userManager |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('get') |
|
|
|
|
->with('UserToEdit') |
|
|
|
|
->willReturn($targetUser); |
|
|
|
|
$targetUser |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getUID') |
|
|
|
|
->willReturn('UID'); |
|
|
|
|
|
|
|
|
|
$backend = $this->createMock(UserInterface::class); |
|
|
|
|
$targetUser |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getBackend') |
|
|
|
|
->willReturn($backend); |
|
|
|
|
|
|
|
|
|
$userAccount = $this->createMock(IAccount::class); |
|
|
|
|
|
|
|
|
|
$this->accountManager |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getAccount') |
|
|
|
|
->with($targetUser) |
|
|
|
|
->willReturn($userAccount); |
|
|
|
|
$this->accountManager |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('updateAccount') |
|
|
|
|
->with($userAccount); |
|
|
|
|
|
|
|
|
|
$this->assertEquals([], $this->api->editUser('UserToEdit', 'additional_mail', 'demo1@nextcloud.com')->getData()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testEditUserRegularUserSelfEditAddAdditionalEmailMainAddress(): void { |
|
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class) |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$loggedInUser |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getUID') |
|
|
|
|
->willReturn('UID'); |
|
|
|
|
$targetUser = $this->getMockBuilder(IUser::class) |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$this->userSession |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getUser') |
|
|
|
|
->willReturn($loggedInUser); |
|
|
|
|
$this->userManager |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('get') |
|
|
|
|
->with('UserToEdit') |
|
|
|
|
->willReturn($targetUser); |
|
|
|
|
$targetUser |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getUID') |
|
|
|
|
->willReturn('UID'); |
|
|
|
|
|
|
|
|
|
$backend = $this->createMock(UserInterface::class); |
|
|
|
|
$targetUser |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getBackend') |
|
|
|
|
->willReturn($backend); |
|
|
|
|
$targetUser |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSystemEMailAddress') |
|
|
|
|
->willReturn('demo@nextcloud.com'); |
|
|
|
|
|
|
|
|
|
$userAccount = $this->createMock(IAccount::class); |
|
|
|
|
|
|
|
|
|
$this->accountManager |
|
|
|
|
->expects($this->never()) |
|
|
|
|
->method('getAccount') |
|
|
|
|
->with($targetUser) |
|
|
|
|
->willReturn($userAccount); |
|
|
|
|
$this->accountManager |
|
|
|
|
->expects($this->never()) |
|
|
|
|
->method('updateAccount') |
|
|
|
|
->with($userAccount); |
|
|
|
|
|
|
|
|
|
$this->expectException(OCSException::class); |
|
|
|
|
$this->expectExceptionCode(102); |
|
|
|
|
$this->api->editUser('UserToEdit', 'additional_mail', 'demo@nextcloud.com')->getData(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testEditUserRegularUserSelfEditAddAdditionalEmailDuplicate(): void { |
|
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class) |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$loggedInUser |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getUID') |
|
|
|
|
->willReturn('UID'); |
|
|
|
|
$targetUser = $this->getMockBuilder(IUser::class) |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$this->userSession |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getUser') |
|
|
|
|
->willReturn($loggedInUser); |
|
|
|
|
$this->userManager |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('get') |
|
|
|
|
->with('UserToEdit') |
|
|
|
|
->willReturn($targetUser); |
|
|
|
|
$targetUser |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getUID') |
|
|
|
|
->willReturn('UID'); |
|
|
|
|
|
|
|
|
|
$backend = $this->createMock(UserInterface::class); |
|
|
|
|
$targetUser |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getBackend') |
|
|
|
|
->willReturn($backend); |
|
|
|
|
|
|
|
|
|
$property = $this->createMock(IAccountProperty::class); |
|
|
|
|
$property->method('getValue') |
|
|
|
|
->willReturn('demo1@nextcloud.com'); |
|
|
|
|
$collection = $this->createMock(IAccountPropertyCollection::class); |
|
|
|
|
$collection->method('getPropertyByValue') |
|
|
|
|
->with('demo1@nextcloud.com') |
|
|
|
|
->willReturn($property); |
|
|
|
|
|
|
|
|
|
$userAccount = $this->createMock(IAccount::class); |
|
|
|
|
$userAccount->method('getPropertyCollection') |
|
|
|
|
->with(IAccountManager::COLLECTION_EMAIL) |
|
|
|
|
->willReturn($collection); |
|
|
|
|
|
|
|
|
|
$this->accountManager |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getAccount') |
|
|
|
|
->with($targetUser) |
|
|
|
|
->willReturn($userAccount); |
|
|
|
|
$this->accountManager |
|
|
|
|
->expects($this->never()) |
|
|
|
|
->method('updateAccount') |
|
|
|
|
->with($userAccount); |
|
|
|
|
|
|
|
|
|
$this->expectException(OCSException::class); |
|
|
|
|
$this->expectExceptionCode(102); |
|
|
|
|
$this->api->editUser('UserToEdit', 'additional_mail', 'demo1@nextcloud.com')->getData(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testEditUserRegularUserSelfEditChangeEmailInvalid() { |
|
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class); |
|
|
|
|
|