|
|
@@ -33,6 +33,7 @@ use OC\Accounts\AccountManager; |
|
|
|
use OCA\Provisioning_API\Controller\UsersController; |
|
|
|
use OCP\AppFramework\Http\DataResponse; |
|
|
|
use OCP\IGroup; |
|
|
|
use OCP\IRequest; |
|
|
|
use OCP\IUser; |
|
|
|
use OCP\IUserManager; |
|
|
|
use OCP\IConfig; |
|
|
@@ -57,6 +58,8 @@ class UsersControllerTest extends OriginalTest { |
|
|
|
protected $api; |
|
|
|
/** @var AccountManager | PHPUnit_Framework_MockObject_MockObject */ |
|
|
|
protected $accountManager; |
|
|
|
/** @var IRequest | PHPUnit_Framework_MockObject_MockObject */ |
|
|
|
protected $request; |
|
|
|
|
|
|
|
protected function tearDown() { |
|
|
|
parent::tearDown(); |
|
|
@@ -80,7 +83,7 @@ class UsersControllerTest extends OriginalTest { |
|
|
|
$this->logger = $this->getMockBuilder('OCP\ILogger') |
|
|
|
->disableOriginalConstructor() |
|
|
|
->getMock(); |
|
|
|
$request = $this->getMockBuilder('OCP\IRequest') |
|
|
|
$this->request = $this->getMockBuilder('OCP\IRequest') |
|
|
|
->disableOriginalConstructor() |
|
|
|
->getMock(); |
|
|
|
$this->accountManager = $this->getMockBuilder(AccountManager::class) |
|
|
@@ -89,7 +92,7 @@ class UsersControllerTest extends OriginalTest { |
|
|
|
$this->api = $this->getMockBuilder('OCA\Provisioning_API\Controller\UsersController') |
|
|
|
->setConstructorArgs([ |
|
|
|
'provisioning_api', |
|
|
|
$request, |
|
|
|
$this->request, |
|
|
|
$this->userManager, |
|
|
|
$this->config, |
|
|
|
$this->groupManager, |
|
|
@@ -683,8 +686,13 @@ class UsersControllerTest extends OriginalTest { |
|
|
|
->expects($this->once()) |
|
|
|
->method('getDisplayName') |
|
|
|
->will($this->returnValue('Demo User')); |
|
|
|
$targetUser |
|
|
|
->expects($this->once()) |
|
|
|
->method('getUID') |
|
|
|
->will($this->returnValue('UID')); |
|
|
|
|
|
|
|
$expected = [ |
|
|
|
'id' => 'UID', |
|
|
|
'enabled' => 'true', |
|
|
|
'quota' => ['DummyValue'], |
|
|
|
'email' => 'demo@owncloud.org', |
|
|
@@ -752,6 +760,10 @@ class UsersControllerTest extends OriginalTest { |
|
|
|
->expects($this->once()) |
|
|
|
->method('getDisplayName') |
|
|
|
->will($this->returnValue('Demo User')); |
|
|
|
$targetUser |
|
|
|
->expects($this->once()) |
|
|
|
->method('getUID') |
|
|
|
->will($this->returnValue('UID')); |
|
|
|
$this->accountManager->expects($this->any())->method('getUser') |
|
|
|
->with($targetUser) |
|
|
|
->willReturn( |
|
|
@@ -764,6 +776,7 @@ class UsersControllerTest extends OriginalTest { |
|
|
|
); |
|
|
|
|
|
|
|
$expected = [ |
|
|
|
'id' => 'UID', |
|
|
|
'enabled' => 'true', |
|
|
|
'quota' => ['DummyValue'], |
|
|
|
'email' => 'demo@owncloud.org', |
|
|
@@ -872,6 +885,10 @@ class UsersControllerTest extends OriginalTest { |
|
|
|
->expects($this->once()) |
|
|
|
->method('getEMailAddress') |
|
|
|
->will($this->returnValue('subadmin@owncloud.org')); |
|
|
|
$targetUser |
|
|
|
->expects($this->once()) |
|
|
|
->method('getUID') |
|
|
|
->will($this->returnValue('UID')); |
|
|
|
$this->accountManager->expects($this->any())->method('getUser') |
|
|
|
->with($targetUser) |
|
|
|
->willReturn( |
|
|
@@ -884,6 +901,7 @@ class UsersControllerTest extends OriginalTest { |
|
|
|
); |
|
|
|
|
|
|
|
$expected = [ |
|
|
|
'id' => 'UID', |
|
|
|
'quota' => ['DummyValue'], |
|
|
|
'email' => 'subadmin@owncloud.org', |
|
|
|
'displayname' => 'Subadmin User', |
|
|
@@ -2534,4 +2552,70 @@ class UsersControllerTest extends OriginalTest { |
|
|
|
|
|
|
|
$this->assertEquals([], $this->api->disableUser('RequestedUser')->getData()); |
|
|
|
} |
|
|
|
|
|
|
|
public function testGetCurrentUserLoggedIn() { |
|
|
|
|
|
|
|
$user = $this->getMock(IUser::class); |
|
|
|
$user->expects($this->once())->method('getUID')->willReturn('UID'); |
|
|
|
|
|
|
|
$this->userSession->expects($this->once())->method('getUser') |
|
|
|
->willReturn($user); |
|
|
|
|
|
|
|
/** @var UsersController | PHPUnit_Framework_MockObject_MockObject $api */ |
|
|
|
$api = $this->getMockBuilder('OCA\Provisioning_API\Controller\UsersController') |
|
|
|
->setConstructorArgs([ |
|
|
|
'provisioning_api', |
|
|
|
$this->request, |
|
|
|
$this->userManager, |
|
|
|
$this->config, |
|
|
|
$this->groupManager, |
|
|
|
$this->userSession, |
|
|
|
$this->accountManager, |
|
|
|
$this->logger, |
|
|
|
]) |
|
|
|
->setMethods(['getUser']) |
|
|
|
->getMock(); |
|
|
|
|
|
|
|
$api->expects($this->once())->method('getUser')->with('UID') |
|
|
|
->willReturn( |
|
|
|
[ |
|
|
|
'id' => 'UID', |
|
|
|
'enabled' => 'true', |
|
|
|
'quota' => ['DummyValue'], |
|
|
|
'email' => 'demo@owncloud.org', |
|
|
|
'displayname' => 'Demo User', |
|
|
|
'phone' => 'phone', |
|
|
|
'address' => 'address', |
|
|
|
'webpage' => 'website', |
|
|
|
'twitter' => 'twitter' |
|
|
|
] |
|
|
|
); |
|
|
|
|
|
|
|
$expected = [ |
|
|
|
'id' => 'UID', |
|
|
|
'enabled' => 'true', |
|
|
|
'quota' => ['DummyValue'], |
|
|
|
'email' => 'demo@owncloud.org', |
|
|
|
'phone' => 'phone', |
|
|
|
'address' => 'address', |
|
|
|
'webpage' => 'website', |
|
|
|
'twitter' => 'twitter', |
|
|
|
'display-name' => 'Demo User' |
|
|
|
]; |
|
|
|
|
|
|
|
$this->assertSame($expected, $api->getCurrentUser()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @expectedException \OCP\AppFramework\OCS\OCSException |
|
|
|
*/ |
|
|
|
public function testGetCurrentUserNotLoggedIn() { |
|
|
|
|
|
|
|
$this->userSession->expects($this->once())->method('getUser') |
|
|
|
->willReturn(null); |
|
|
|
|
|
|
|
$this->api->getCurrentUser(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |