namespace Tests\Settings\Controller;
+use OC\Accounts\AccountManager;
use OC\Group\Manager;
use OC\Settings\Controller\UsersController;
use OCP\App\IAppManager;
private $avatarManager;
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
private $l;
+ /** @var AccountManager | \PHPUnit_Framework_MockObject_MockObject */
+ private $accountManager;
protected function setUp() {
parent::setUp();
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->avatarManager = $this->createMock(IAvatarManager::class);
+ $this->accountManager = $this->createMock(AccountManager::class);
$this->l = $this->createMock(IL10N::class);
$this->l->method('t')
->will($this->returnCallback(function ($text, $parameters = []) {
'no-reply@owncloud.com',
$this->urlGenerator,
$this->appManager,
- $this->avatarManager
+ $this->avatarManager,
+ $this->accountManager
);
}
$this->assertEquals($expectedResult, $result);
}
- /**
- * @return array
- */
- public function setEmailAddressData() {
- return [
- /* mailAddress, isValid, expectsUpdate, canChangeDisplayName, responseCode */
- [ '', true, true, true, Http::STATUS_OK ],
- [ 'foo@local', true, true, true, Http::STATUS_OK],
- [ 'foo@bar@local', false, false, true, Http::STATUS_UNPROCESSABLE_ENTITY],
- [ 'foo@local', true, false, false, Http::STATUS_FORBIDDEN],
- ];
- }
-
- /**
- * @dataProvider setEmailAddressData
- *
- * @param string $mailAddress
- * @param bool $isValid
- * @param bool $expectsUpdate
- * @param bool $expectsDelete
- */
- public function testSetEmailAddress($mailAddress, $isValid, $expectsUpdate, $canChangeDisplayName, $responseCode) {
- $controller = $this->getController(true);
-
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
- $user
- ->expects($this->any())
- ->method('getUID')
- ->will($this->returnValue('foo'));
- $user
- ->expects($this->any())
- ->method('canChangeDisplayName')
- ->will($this->returnValue($canChangeDisplayName));
- $user
- ->expects($expectsUpdate ? $this->once() : $this->never())
- ->method('setEMailAddress')
- ->with(
- $this->equalTo($mailAddress)
- );
-
- $this->userSession
- ->expects($this->atLeastOnce())
- ->method('getUser')
- ->will($this->returnValue($user));
- $this->mailer
- ->expects($this->any())
- ->method('validateMailAddress')
- ->with($mailAddress)
- ->willReturn($isValid);
-
- if ($isValid) {
- $user->expects($this->atLeastOnce())
- ->method('canChangeDisplayName')
- ->willReturn(true);
-
- $this->userManager
- ->expects($this->atLeastOnce())
- ->method('get')
- ->with('foo')
- ->will($this->returnValue($user));
- }
-
- $response = $controller->setMailAddress($user->getUID(), $mailAddress);
-
- $this->assertSame($responseCode, $response->getStatus());
- }
-
public function testStatsAdmin() {
$controller = $this->getController(true);
->method('get')
->with($editUser->getUID())
->willReturn($editUser);
+ $this->accountManager->expects($this->any())->method('getUser')->willReturn([]);
$subadmin = $this->getMockBuilder('\OC\SubAdmin')
->disableOriginalConstructor()
->willReturn($isAdmin);
if ($valid === true) {
- $editUser->expects($this->once())
- ->method('setDisplayName')
- ->with('newDisplayName')
- ->willReturn(true);
$expectedResponse = new DataResponse(
[
'status' => 'success',
]
);
} else {
- $editUser->expects($this->never())->method('setDisplayName');
$expectedResponse = new DataResponse(
[
'status' => 'error',