summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-05-23 00:32:46 +0200
committerGitHub <noreply@github.com>2018-05-23 00:32:46 +0200
commita2c518ee5a3d452973052a627e15bcb3bb812dd3 (patch)
tree51732ffcac6d5c445dfd0f3773d27fbfdb36d522 /tests
parentb40bae816a5515b6420c0d82bf64eb187b2cd894 (diff)
parent760b01e8dbad054919fe766112b52d0b9cfb2d32 (diff)
downloadnextcloud-server-a2c518ee5a3d452973052a627e15bcb3bb812dd3.tar.gz
nextcloud-server-a2c518ee5a3d452973052a627e15bcb3bb812dd3.zip
Merge pull request #8824 from nextcloud/settings-vue
Vue migration: settings
Diffstat (limited to 'tests')
-rw-r--r--tests/Settings/ApplicationTest.php1
-rw-r--r--tests/Settings/Controller/GroupsControllerTest.php381
-rw-r--r--tests/Settings/Controller/UsersControllerTest.php2524
-rw-r--r--tests/acceptance/config/behat.yml2
-rw-r--r--tests/acceptance/features/bootstrap/AppNavigationContext.php64
-rw-r--r--tests/acceptance/features/bootstrap/AppSettingsContext.php102
-rw-r--r--tests/acceptance/features/bootstrap/DialogContext.php68
-rw-r--r--tests/acceptance/features/bootstrap/UsersSettingsContext.php156
-rw-r--r--tests/acceptance/features/core/ElementWrapper.php38
-rw-r--r--tests/acceptance/features/login.feature1
-rw-r--r--tests/acceptance/features/users.feature115
11 files changed, 531 insertions, 2921 deletions
diff --git a/tests/Settings/ApplicationTest.php b/tests/Settings/ApplicationTest.php
index 31391a8fac6..eab7d5bd8cf 100644
--- a/tests/Settings/ApplicationTest.php
+++ b/tests/Settings/ApplicationTest.php
@@ -72,7 +72,6 @@ class ApplicationTest extends TestCase {
[AuthSettingsController::class, Controller::class],
// Needs session: [CertificateController::class, Controller::class],
[CheckSetupController::class, Controller::class],
- [GroupsController::class, Controller::class],
[LogSettingsController::class, Controller::class],
[MailSettingsController::class, Controller::class],
[UsersController::class, Controller::class],
diff --git a/tests/Settings/Controller/GroupsControllerTest.php b/tests/Settings/Controller/GroupsControllerTest.php
deleted file mode 100644
index d43d4faf218..00000000000
--- a/tests/Settings/Controller/GroupsControllerTest.php
+++ /dev/null
@@ -1,381 +0,0 @@
-<?php
-/**
- * @author Lukas Reschke
- * @copyright 2014 Lukas Reschke lukas@owncloud.com
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-namespace Tests\Settings\Controller;
-
-use OC\Group\Group;
-use OC\Group\MetaData;
-use OC\Settings\Controller\GroupsController;
-use OC\User\User;
-use OCP\AppFramework\Http;
-use OCP\AppFramework\Http\DataResponse;
-use OCP\IGroupManager;
-use OCP\IL10N;
-use OCP\IRequest;
-use OCP\IUserSession;
-
-/**
- * @package Tests\Settings\Controller
- */
-class GroupsControllerTest extends \Test\TestCase {
-
- /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
- private $groupManager;
-
- /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
- private $userSession;
-
- /** @var GroupsController */
- private $groupsController;
-
- protected function setUp() {
- parent::setUp();
-
- $this->groupManager = $this->createMock(IGroupManager::class);
- $this->userSession = $this->createMock(IUserSession::class);
- $l = $this->createMock(IL10N::class);
- $l->method('t')
- ->will($this->returnCallback(function($text, $parameters = []) {
- return vsprintf($text, $parameters);
- }));
- $this->groupsController = new GroupsController(
- 'settings',
- $this->createMock(IRequest::class),
- $this->groupManager,
- $this->userSession,
- true,
- $l
- );
-
- }
-
- /**
- * TODO: Since GroupManager uses the static OC_Subadmin class it can't be mocked
- * to test for subadmins. Thus the test always assumes you have admin permissions...
- */
- public function testIndexSortByName() {
- $firstGroup = $this->getMockBuilder(Group::class)
- ->disableOriginalConstructor()->getMock();
- $firstGroup
- ->method('getGID')
- ->will($this->returnValue('firstGroup'));
- $firstGroup
- ->method('getDisplayName')
- ->will($this->returnValue('First group'));
- $firstGroup
- ->method('count')
- ->will($this->returnValue(12));
- $secondGroup = $this->getMockBuilder(Group::class)
- ->disableOriginalConstructor()->getMock();
- $secondGroup
- ->method('getGID')
- ->will($this->returnValue('secondGroup'));
- $secondGroup
- ->method('getDisplayName')
- ->will($this->returnValue('Second group'));
- $secondGroup
- ->method('count')
- ->will($this->returnValue(25));
- $thirdGroup = $this->getMockBuilder(Group::class)
- ->disableOriginalConstructor()->getMock();
- $thirdGroup
- ->method('getGID')
- ->will($this->returnValue('thirdGroup'));
- $thirdGroup
- ->method('getDisplayName')
- ->will($this->returnValue('Third group'));
- $thirdGroup
- ->method('count')
- ->will($this->returnValue(14));
- $fourthGroup = $this->getMockBuilder(Group::class)
- ->disableOriginalConstructor()->getMock();
- $fourthGroup
- ->method('getGID')
- ->will($this->returnValue('admin'));
- $fourthGroup
- ->method('getDisplayName')
- ->will($this->returnValue('Admin'));
- $fourthGroup
- ->method('count')
- ->will($this->returnValue(18));
- /** @var \OC\Group\Group[] $groups */
- $groups = array();
- $groups[] = $firstGroup;
- $groups[] = $secondGroup;
- $groups[] = $thirdGroup;
- $groups[] = $fourthGroup;
-
- $user = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $this->userSession
- ->expects($this->once())
- ->method('getUser')
- ->will($this->returnValue($user));
- $user
- ->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('MyAdminUser'));
- $this->groupManager->method('search')
- ->will($this->returnValue($groups));
-
- $expectedResponse = new DataResponse(
- array(
- 'data' => array(
- 'adminGroups' => array(
- 0 => array(
- 'id' => 'admin',
- 'name' => 'Admin',
- 'usercount' => 0,//User count disabled 18,
- )
- ),
- 'groups' =>
- array(
- 0 => array(
- 'id' => 'firstGroup',
- 'name' => 'First group',
- 'usercount' => 0,//User count disabled 12,
- ),
- 1 => array(
- 'id' => 'secondGroup',
- 'name' => 'Second group',
- 'usercount' => 0,//User count disabled 25,
- ),
- 2 => array(
- 'id' => 'thirdGroup',
- 'name' => 'Third group',
- 'usercount' => 0,//User count disabled 14,
- ),
- )
- )
- )
- );
- $response = $this->groupsController->index('', false, MetaData::SORT_GROUPNAME);
- $this->assertEquals($expectedResponse, $response);
- }
-
- /**
- * TODO: Since GroupManager uses the static OC_Subadmin class it can't be mocked
- * to test for subadmins. Thus the test always assumes you have admin permissions...
- */
- public function testIndexSortbyCount() {
- $firstGroup = $this->getMockBuilder(Group::class)
- ->disableOriginalConstructor()->getMock();
- $firstGroup
- ->method('getGID')
- ->will($this->returnValue('firstGroup'));
- $firstGroup
- ->method('getDisplayName')
- ->will($this->returnValue('First group'));
- $firstGroup
- ->method('count')
- ->will($this->returnValue(12));
- $secondGroup = $this->getMockBuilder(Group::class)
- ->disableOriginalConstructor()->getMock();
- $secondGroup
- ->method('getGID')
- ->will($this->returnValue('secondGroup'));
- $secondGroup
- ->method('getDisplayName')
- ->will($this->returnValue('Second group'));
- $secondGroup
- ->method('count')
- ->will($this->returnValue(25));
- $thirdGroup = $this->getMockBuilder(Group::class)
- ->disableOriginalConstructor()->getMock();
- $thirdGroup
- ->method('getGID')
- ->will($this->returnValue('thirdGroup'));
- $thirdGroup
- ->method('getDisplayName')
- ->will($this->returnValue('Third group'));
- $thirdGroup
- ->method('count')
- ->will($this->returnValue(14));
- $fourthGroup = $this->getMockBuilder(Group::class)
- ->disableOriginalConstructor()->getMock();
- $fourthGroup
- ->method('getGID')
- ->will($this->returnValue('admin'));
- $fourthGroup
- ->method('getDisplayName')
- ->will($this->returnValue('Admin'));
- $fourthGroup
- ->method('count')
- ->will($this->returnValue(18));
- /** @var \OC\Group\Group[] $groups */
- $groups = array();
- $groups[] = $firstGroup;
- $groups[] = $secondGroup;
- $groups[] = $thirdGroup;
- $groups[] = $fourthGroup;
-
- $user = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $this->userSession
- ->expects($this->once())
- ->method('getUser')
- ->will($this->returnValue($user));
- $user
- ->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('MyAdminUser'));
- $this->groupManager
- ->method('search')
- ->will($this->returnValue($groups));
-
- $expectedResponse = new DataResponse(
- array(
- 'data' => array(
- 'adminGroups' => array(
- 0 => array(
- 'id' => 'admin',
- 'name' => 'Admin',
- 'usercount' => 18,
- )
- ),
- 'groups' =>
- array(
- 0 => array(
- 'id' => 'secondGroup',
- 'name' => 'Second group',
- 'usercount' => 25,
- ),
- 1 => array(
- 'id' => 'thirdGroup',
- 'name' => 'Third group',
- 'usercount' => 14,
- ),
- 2 => array(
- 'id' => 'firstGroup',
- 'name' => 'First group',
- 'usercount' => 12,
- ),
- )
- )
- )
- );
- $response = $this->groupsController->index();
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testCreateWithExistingGroup() {
- $this->groupManager
- ->expects($this->once())
- ->method('groupExists')
- ->with('ExistingGroup')
- ->will($this->returnValue(true));
-
- $expectedResponse = new DataResponse(
- array(
- 'message' => 'Group already exists.'
- ),
- Http::STATUS_CONFLICT
- );
- $response = $this->groupsController->create('ExistingGroup');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testCreateSuccessful() {
- $group = $this->getMockBuilder(Group::class)
- ->disableOriginalConstructor()->getMock();
- $this->groupManager
- ->expects($this->once())
- ->method('groupExists')
- ->with('NewGroup')
- ->will($this->returnValue(false));
- $this->groupManager
- ->expects($this->once())
- ->method('createGroup')
- ->with('NewGroup')
- ->will($this->returnValue($group));
- $group
- ->expects($this->once())
- ->method('getDisplayName')
- ->will($this->returnValue('NewGroup'));
-
- $expectedResponse = new DataResponse(
- array(
- 'groupname' => 'NewGroup'
- ),
- Http::STATUS_CREATED
- );
- $response = $this->groupsController->create('NewGroup');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testCreateUnsuccessful() {
- $this->groupManager
- ->expects($this->once())
- ->method('groupExists')
- ->with('NewGroup')
- ->will($this->returnValue(false));
- $this->groupManager
- ->expects($this->once())
- ->method('createGroup')
- ->with('NewGroup')
- ->will($this->returnValue(false));
-
- $expectedResponse = new DataResponse(
- array(
- 'status' => 'error',
- 'data' => array('message' => 'Unable to add group.')
- ),
- Http::STATUS_FORBIDDEN
- );
- $response = $this->groupsController->create('NewGroup');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testDestroySuccessful() {
- $group = $this->getMockBuilder(Group::class)
- ->disableOriginalConstructor()->getMock();
- $this->groupManager
- ->expects($this->once())
- ->method('get')
- ->with('ExistingGroup')
- ->will($this->returnValue($group));
- $group
- ->expects($this->once())
- ->method('delete')
- ->will($this->returnValue(true));
- $group
- ->method('getDisplayName')
- ->will($this->returnValue('ExistingGroup'));
-
- $expectedResponse = new DataResponse(
- array(
- 'status' => 'success',
- 'data' => array('groupname' => 'ExistingGroup')
- ),
- Http::STATUS_NO_CONTENT
- );
- $response = $this->groupsController->destroy('ExistingGroup');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testDestroyUnsuccessful() {
- $this->groupManager
- ->expects($this->once())
- ->method('get')
- ->with('ExistingGroup')
- ->will($this->returnValue(null));
-
- $expectedResponse = new DataResponse(
- array(
- 'status' => 'error',
- 'data' => array('message' => 'Unable to delete group.')
- ),
- Http::STATUS_FORBIDDEN
- );
- $response = $this->groupsController->destroy('ExistingGroup');
- $this->assertEquals($expectedResponse, $response);
- }
-
-}
diff --git a/tests/Settings/Controller/UsersControllerTest.php b/tests/Settings/Controller/UsersControllerTest.php
index 4cfec07f78b..74ac990be92 100644
--- a/tests/Settings/Controller/UsersControllerTest.php
+++ b/tests/Settings/Controller/UsersControllerTest.php
@@ -31,10 +31,10 @@ use OCP\IGroupManager;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
-use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
+use OCP\L10N\IFactory;
use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
use OCP\Security\ISecureRandom;
@@ -60,8 +60,8 @@ class UsersControllerTest extends \Test\TestCase {
private $logger;
/** @var IMailer|\PHPUnit_Framework_MockObject_MockObject */
private $mailer;
- /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
- private $urlGenerator;
+ /** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */
+ private $l10nFactory;
/** @var IAppManager|\PHPUnit_Framework_MockObject_MockObject */
private $appManager;
/** @var IAvatarManager|\PHPUnit_Framework_MockObject_MockObject */
@@ -78,8 +78,6 @@ class UsersControllerTest extends \Test\TestCase {
private $jobList;
/** @var \OC\Security\IdentityProof\Manager |\PHPUnit_Framework_MockObject_MockObject */
private $securityManager;
- /** @var IUserMountCache |\PHPUnit_Framework_MockObject_MockObject */
- private $userMountCache;
/** @var IManager | \PHPUnit_Framework_MockObject_MockObject */
private $encryptionManager;
/** @var IEncryptionModule | \PHPUnit_Framework_MockObject_MockObject */
@@ -88,46 +86,28 @@ class UsersControllerTest extends \Test\TestCase {
protected function setUp() {
parent::setUp();
- $this->groupManager = $this->createMock(Manager::class);
$this->userManager = $this->createMock(IUserManager::class);
+ $this->groupManager = $this->createMock(Manager::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->config = $this->createMock(IConfig::class);
- $this->logger = $this->createMock(ILogger::class);
+ $this->l = $this->createMock(IL10N::class);
$this->mailer = $this->createMock(IMailer::class);
- $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->l10nFactory = $this->createMock(IFactory::class);
$this->appManager = $this->createMock(IAppManager::class);
- $this->avatarManager = $this->createMock(IAvatarManager::class);
$this->accountManager = $this->createMock(AccountManager::class);
- $this->secureRandom = $this->createMock(ISecureRandom::class);
- $this->newUserMailHelper = $this->createMock(NewUserMailHelper::class);
$this->securityManager = $this->getMockBuilder(\OC\Security\IdentityProof\Manager::class)->disableOriginalConstructor()->getMock();
$this->jobList = $this->createMock(IJobList::class);
$this->encryptionManager = $this->createMock(IManager::class);
- $this->l = $this->createMock(IL10N::class);
+
$this->l->method('t')
->will($this->returnCallback(function ($text, $parameters = []) {
return vsprintf($text, $parameters);
}));
- $this->userMountCache = $this->createMock(IUserMountCache::class);
$this->encryptionModule = $this->createMock(IEncryptionModule::class);
$this->encryptionManager->expects($this->any())->method('getEncryptionModules')
->willReturn(['encryptionModule' => ['callback' => function() { return $this->encryptionModule;}]]);
- /*
- * Set default avatar behaviour for whole test suite
- */
-
- $avatarExists = $this->createMock(IAvatar::class);
- $avatarExists->method('exists')->willReturn(true);
- $avatarNotExists = $this->createMock(IAvatar::class);
- $avatarNotExists->method('exists')->willReturn(false);
- $this->avatarManager->method('getAvatar')
- ->will($this->returnValueMap([
- ['foo', $avatarExists],
- ['bar', $avatarExists],
- ['admin', $avatarNotExists],
- ]));
}
/**
@@ -145,17 +125,12 @@ class UsersControllerTest extends \Test\TestCase {
$this->config,
$isAdmin,
$this->l,
- $this->logger,
$this->mailer,
- $this->urlGenerator,
+ $this->l10nFactory,
$this->appManager,
- $this->avatarManager,
$this->accountManager,
- $this->secureRandom,
- $this->newUserMailHelper,
$this->securityManager,
$this->jobList,
- $this->userMountCache,
$this->encryptionManager
);
} else {
@@ -170,1926 +145,18 @@ class UsersControllerTest extends \Test\TestCase {
$this->config,
$isAdmin,
$this->l,
- $this->logger,
$this->mailer,
- $this->urlGenerator,
+ $this->l10nFactory,
$this->appManager,
- $this->avatarManager,
$this->accountManager,
- $this->secureRandom,
- $this->newUserMailHelper,
$this->securityManager,
$this->jobList,
- $this->userMountCache,
$this->encryptionManager
]
)->setMethods($mockedMethods)->getMock();
}
}
- public function testIndexAdmin() {
- $controller = $this->getController(true);
-
- $foo = $this->createMock(User::class);
- $foo
- ->expects($this->exactly(2))
- ->method('getUID')
- ->will($this->returnValue('foo'));
- $foo
- ->expects($this->once())
- ->method('getDisplayName')
- ->will($this->returnValue('M. Foo'));
- $foo
- ->expects($this->once())
- ->method('getEMailAddress')
- ->will($this->returnValue('foo@bar.com'));
- $foo
- ->expects($this->exactly(2))
- ->method('getQuota')
- ->will($this->returnValue(1024));
- $foo
- ->method('getLastLogin')
- ->will($this->returnValue(500));
- $foo
- ->method('getHome')
- ->will($this->returnValue('/home/foo'));
- $foo
- ->expects($this->once())
- ->method('getBackendClassName')
- ->will($this->returnValue('OC_User_Database'));
- $foo->expects($this->any())
- ->method('isEnabled')
- ->willReturn(true);
- $admin = $this->createMock(User::class);
- $admin
- ->expects($this->exactly(2))
- ->method('getUID')
- ->will($this->returnValue('admin'));
- $admin
- ->expects($this->once())
- ->method('getDisplayName')
- ->will($this->returnValue('S. Admin'));
- $admin
- ->expects($this->once())
- ->method('getEMailAddress')
- ->will($this->returnValue('admin@bar.com'));
- $admin
- ->expects($this->exactly(2))
- ->method('getQuota')
- ->will($this->returnValue(404));
- $admin
- ->expects($this->once())
- ->method('getLastLogin')
- ->will($this->returnValue(12));
- $admin
- ->expects($this->once())
- ->method('getHome')
- ->will($this->returnValue('/home/admin'));
- $admin
- ->expects($this->once())
- ->method('getBackendClassName')
- ->willReturn(Dummy::class);
- $admin->expects($this->any())
- ->method('isEnabled')
- ->willReturn(true);
- $bar = $this->createMock(User::class);
- $bar
- ->expects($this->exactly(2))
- ->method('getUID')
- ->will($this->returnValue('bar'));
- $bar
- ->expects($this->once())
- ->method('getDisplayName')
- ->will($this->returnValue('B. Ar'));
- $bar
- ->expects($this->once())
- ->method('getEMailAddress')
- ->will($this->returnValue('bar@dummy.com'));
- $bar
- ->expects($this->exactly(2))
- ->method('getQuota')
- ->will($this->returnValue(2323));
- $bar
- ->method('getLastLogin')
- ->will($this->returnValue(3999));
- $bar
- ->method('getHome')
- ->will($this->returnValue('/home/bar'));
- $bar
- ->expects($this->once())
- ->method('getBackendClassName')
- ->willReturn(Dummy::class);
- $bar->expects($this->at(0))
- ->method('isEnabled')
- ->willReturn(true);
- $bar->expects($this->at(1))
- ->method('isEnabled')
- ->willReturn(true);
- $bar->expects($this->at(2))
- ->method('isEnabled')
- ->willReturn(false);
-
- $this->groupManager
- ->expects($this->once())
- ->method('displayNamesInGroup')
- ->with('gid', 'pattern')
- ->will($this->returnValue(array('foo' => 'M. Foo', 'admin' => 'S. Admin', 'bar' => 'B. Ar')));
- $this->groupManager
- ->expects($this->exactly(3))
- ->method('getUserGroupNames')
- ->will($this->onConsecutiveCalls(
- array(
- 'Users' => array('displayName' => 'Users'),
- 'Support' => array('displayName' => 'Support')
- ),
- array(
- 'admins' => array('displayName' => 'admins'),
- 'Support' => array('displayName' => 'Support')
- ),
- array(
- 'External Users' => array('displayName' => 'External Users')
- )
- ));
- $this->userManager
- ->expects($this->at(0))
- ->method('get')
- ->with('foo')
- ->will($this->returnValue($foo));
- $this->userManager
- ->expects($this->at(1))
- ->method('get')
- ->with('admin')
- ->will($this->returnValue($admin));
- $this->userManager
- ->expects($this->at(2))
- ->method('get')
- ->with('bar')
- ->will($this->returnValue($bar));
-
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin
- ->expects($this->any())
- ->method('getSubAdminsGroupsName')
- ->with($foo)
- ->will($this->returnValue([]));
- $subadmin
- ->expects($this->any())
- ->method('getSubAdminsGroupsName')
- ->with($admin)
- ->will($this->returnValue([]));
- $subadmin
- ->expects($this->any())
- ->method('getSubAdminsGroupsName')
- ->with($bar)
- ->will($this->returnValue([]));
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
-
- $this->userMountCache
- ->expects($this->once())
- ->method('getUsedSpaceForUsers')
- ->will($this->returnValue(['admin' => 200, 'bar' => 2000, 'foo' => 512]));
-
- $expectedResponse = new DataResponse(
- array(
- 0 => array(
- 'name' => 'foo',
- 'displayname' => 'M. Foo',
- 'groups' => array(
- 'Users' => array('displayName' => 'Users'),
- 'Support' => array('displayName' => 'Support')
- ),
- 'subadmin' => array(),
- 'quota' => 1024,
- 'quota_bytes' => 1024.0,
- 'storageLocation' => '/home/foo',
- 'lastLogin' => 500000,
- 'backend' => 'OC_User_Database',
- 'email' => 'foo@bar.com',
- 'isRestoreDisabled' => false,
- 'isAvatarAvailable' => true,
- 'isEnabled' => true,
- 'size' => 512,
- ),
- 1 => array(
- 'name' => 'admin',
- 'displayname' => 'S. Admin',
- 'groups' => array(
- 'admins' => array('displayName' => 'admins'),
- 'Support' => array('displayName' => 'Support')
- ),
- 'subadmin' => array(),
- 'quota' => 404,
- 'quota_bytes' => 404.0,
- 'storageLocation' => '/home/admin',
- 'lastLogin' => 12000,
- 'backend' => Dummy::class,
- 'email' => 'admin@bar.com',
- 'isRestoreDisabled' => false,
- 'isAvatarAvailable' => false,
- 'isEnabled' => true,
- 'size' => 200,
- ),
- 2 => array(
- 'name' => 'bar',
- 'displayname' => 'B. Ar',
- 'groups' => array(
- 'External Users' => array('displayName' => 'External Users')
- ),
- 'subadmin' => array(),
- 'quota' => 2323,
- 'quota_bytes' => 2323.0,
- 'storageLocation' => '/home/bar',
- 'lastLogin' => 3999000,
- 'backend' => Dummy::class,
- 'email' => 'bar@dummy.com',
- 'isRestoreDisabled' => false,
- 'isAvatarAvailable' => true,
- 'isEnabled' => false,
- 'size' => 2000,
- ),
- )
- );
- $response = $controller->index(0, 10, 'gid', 'pattern');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testIndexSubAdmin() {
- $controller = $this->getController(false);
-
- $user = $this->createMock(User::class);
- $this->userSession
- ->expects($this->once())
- ->method('getUser')
- ->will($this->returnValue($user));
-
- $foo = $this->createMock(User::class);
- $foo
- ->expects($this->exactly(2))
- ->method('getUID')
- ->will($this->returnValue('foo'));
- $foo
- ->expects($this->once())
- ->method('getDisplayName')
- ->will($this->returnValue('M. Foo'));
- $foo
- ->expects($this->once())
- ->method('getEMailAddress')
- ->will($this->returnValue('foo@bar.com'));
- $foo
- ->expects($this->exactly(2))
- ->method('getQuota')
- ->will($this->returnValue('1024'));
- $foo
- ->method('getLastLogin')
- ->will($this->returnValue(500));
- $foo
- ->method('getHome')
- ->will($this->returnValue('/home/foo'));
- $foo
- ->expects($this->once())
- ->method('getBackendClassName')
- ->will($this->returnValue('OC_User_Database'));
- $foo->expects($this->any())
- ->method('isEnabled')
- ->willReturn(true);
- $admin = $this->createMock(User::class);
- $admin
- ->expects($this->exactly(2))
- ->method('getUID')
- ->will($this->returnValue('admin'));
- $admin
- ->expects($this->once())
- ->method('getDisplayName')
- ->will($this->returnValue('S. Admin'));
- $admin
- ->expects($this->once())
- ->method('getEMailAddress')
- ->will($this->returnValue('admin@bar.com'));
- $admin
- ->expects($this->exactly(2))
- ->method('getQuota')
- ->will($this->returnValue('404'));
- $admin
- ->expects($this->once())
- ->method('getLastLogin')
- ->will($this->returnValue(12));
- $admin
- ->expects($this->once())
- ->method('getHome')
- ->will($this->returnValue('/home/admin'));
- $admin
- ->expects($this->once())
- ->method('getBackendClassName')
- ->willReturn(Dummy::class);
- $admin->expects($this->any())
- ->method('isEnabled')
- ->willReturn(true);
- $bar = $this->createMock(User::class);
- $bar
- ->expects($this->exactly(2))
- ->method('getUID')
- ->will($this->returnValue('bar'));
- $bar
- ->expects($this->once())
- ->method('getDisplayName')
- ->will($this->returnValue('B. Ar'));
- $bar
- ->expects($this->once())
- ->method('getEMailAddress')
- ->will($this->returnValue('bar@dummy.com'));
- $bar
- ->expects($this->exactly(2))
- ->method('getQuota')
- ->will($this->returnValue('2323'));
- $bar
- ->method('getLastLogin')
- ->will($this->returnValue(3999));
- $bar
- ->method('getHome')
- ->will($this->returnValue('/home/bar'));
- $bar
- ->expects($this->once())
- ->method('getBackendClassName')
- ->willReturn(Dummy::class);
- $bar->expects($this->any())
- ->method('isEnabled')
- ->willReturn(true);
-
- $this->groupManager
- ->expects($this->at(2))
- ->method('displayNamesInGroup')
- ->with('SubGroup2', 'pattern')
- ->will($this->returnValue(['foo' => 'M. Foo', 'admin' => 'S. Admin']));
- $this->groupManager
- ->expects($this->at(1))
- ->method('displayNamesInGroup')
- ->with('SubGroup1', 'pattern')
- ->will($this->returnValue(['bar' => 'B. Ar']));
- $this->groupManager
- ->expects($this->exactly(3))
- ->method('getUserGroupIds')
- ->will($this->onConsecutiveCalls(
- ['admin', 'SubGroup1', 'testGroup'],
- ['SubGroup2', 'SubGroup1'],
- ['SubGroup2', 'Foo']
- ));
- $this->userManager
- ->expects($this->at(0))
- ->method('get')
- ->with('bar')
- ->will($this->returnValue($bar));
- $this->userManager
- ->expects($this->at(1))
- ->method('get')
- ->with('foo')
- ->will($this->returnValue($foo));
- $this->userManager
- ->expects($this->at(2))
- ->method('get')
- ->with('admin')
- ->will($this->returnValue($admin));
-
- $subgroup1 = $this->getMockBuilder(IGroup::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subgroup1->expects($this->any())
- ->method('getGID')
- ->will($this->returnValue('SubGroup1'));
- $subgroup2 = $this->getMockBuilder(IGroup::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subgroup2->expects($this->any())
- ->method('getGID')
- ->will($this->returnValue('SubGroup2'));
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin
- ->expects($this->at(0))
- ->method('getSubAdminsGroups')
- ->will($this->returnValue([$subgroup1, $subgroup2]));
- $subadmin
- ->expects($this->any())
- ->method('getSubAdminsGroupsName')
- ->will($this->returnValue([]));
- $subadmin
- ->expects($this->any())
- ->method('getSubAdminsGroups')
- ->will($this->returnValue([]));
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
-
- $this->userMountCache
- ->expects($this->once())
- ->method('getUsedSpaceForUsers')
- ->will($this->returnValue(['admin' => 200, 'bar' => 2000, 'foo' => 512]));
-
- $expectedResponse = new DataResponse(
- [
- 0 => [
- 'name' => 'bar',
- 'displayname' => 'B. Ar',
- 'groups' => ['SubGroup1'],
- 'subadmin' => [],
- 'quota' => '2323',
- 'quota_bytes' => 2323.0,
- 'storageLocation' => '/home/bar',
- 'lastLogin' => 3999000,
- 'backend' => Dummy::class,
- 'email' => 'bar@dummy.com',
- 'isRestoreDisabled' => false,
- 'isAvatarAvailable' => true,
- 'isEnabled' => true,
- 'size' => 2000,
- ],
- 1=> [
- 'name' => 'foo',
- 'displayname' => 'M. Foo',
- 'groups' => ['SubGroup2', 'SubGroup1'],
- 'subadmin' => [],
- 'quota' => '1024',
- 'quota_bytes' => 1024.0,
- 'storageLocation' => '/home/foo',
- 'lastLogin' => 500000,
- 'backend' => 'OC_User_Database',
- 'email' => 'foo@bar.com',
- 'isRestoreDisabled' => false,
- 'isAvatarAvailable' => true,
- 'isEnabled' => true,
- 'size' => 512,
- ],
- 2 => [
- 'name' => 'admin',
- 'displayname' => 'S. Admin',
- 'groups' => ['SubGroup2'],
- 'subadmin' => [],
- 'quota' => '404',
- 'quota_bytes' => 404.0,
- 'storageLocation' => '/home/admin',
- 'lastLogin' => 12000,
- 'backend' => Dummy::class,
- 'email' => 'admin@bar.com',
- 'isRestoreDisabled' => false,
- 'isAvatarAvailable' => false,
- 'isEnabled' => true,
- 'size' => 200,
- ],
- ]
- );
-
- $response = $controller->index(0, 10, '', 'pattern');
- $this->assertEquals($expectedResponse, $response);
- }
-
- /**
- * TODO: Since the function uses the static OC_Subadmin class it can't be mocked
- * to test for subadmins. Thus the test always assumes you have admin permissions...
- */
- public function testIndexWithSearch() {
- $controller = $this->getController(true);
-
- $foo = $this->createMock(User::class);
- $foo
- ->expects($this->exactly(2))
- ->method('getUID')
- ->will($this->returnValue('foo'));
- $foo
- ->expects($this->once())
- ->method('getDisplayName')
- ->will($this->returnValue('M. Foo'));
- $foo
- ->expects($this->once())
- ->method('getEMailAddress')
- ->will($this->returnValue('foo@bar.com'));
- $foo
- ->expects($this->exactly(2))
- ->method('getQuota')
- ->will($this->returnValue('1024'));
- $foo
- ->method('getLastLogin')
- ->will($this->returnValue(500));
- $foo
- ->method('getHome')
- ->will($this->returnValue('/home/foo'));
- $foo
- ->expects($this->once())
- ->method('getBackendClassName')
- ->will($this->returnValue('OC_User_Database'));
- $foo->expects($this->any())
- ->method('isEnabled')
- ->willReturn(true);
- $admin = $this->createMock(User::class);
- $admin
- ->expects($this->exactly(2))
- ->method('getUID')
- ->will($this->returnValue('admin'));
- $admin
- ->expects($this->once())
- ->method('getDisplayName')
- ->will($this->returnValue('S. Admin'));
- $admin
- ->expects($this->once())
- ->method('getEMailAddress')
- ->will($this->returnValue('admin@bar.com'));
- $admin
- ->expects($this->exactly(2))
- ->method('getQuota')
- ->will($this->returnValue('404'));
- $admin
- ->expects($this->once())
- ->method('getLastLogin')
- ->will($this->returnValue(12));
- $admin
- ->expects($this->once())
- ->method('getHome')
- ->will($this->returnValue('/home/admin'));
- $admin
- ->expects($this->once())
- ->method('getBackendClassName')
- ->willReturn(Dummy::class);
- $admin->expects($this->any())
- ->method('isEnabled')
- ->willReturn(true);
- $bar = $this->createMock(User::class);
- $bar
- ->expects($this->exactly(2))
- ->method('getUID')
- ->will($this->returnValue('bar'));
- $bar
- ->expects($this->once())
- ->method('getDisplayName')
- ->will($this->returnValue('B. Ar'));
- $bar
- ->expects($this->once())
- ->method('getEMailAddress')
- ->will($this->returnValue('bar@dummy.com'));
- $bar
- ->expects($this->exactly(2))
- ->method('getQuota')
- ->will($this->returnValue('2323'));
- $bar
- ->method('getLastLogin')
- ->will($this->returnValue(3999));
- $bar
- ->method('getHome')
- ->will($this->returnValue('/home/bar'));
- $bar
- ->expects($this->once())
- ->method('getBackendClassName')
- ->willReturn(Dummy::class);
- $bar->expects($this->any())
- ->method('isEnabled')
- ->willReturn(true);
-
- $this->userManager
- ->expects($this->once())
- ->method('search')
- ->with('pattern', 10, 0)
- ->will($this->returnValue([$foo, $admin, $bar]));
- $this->groupManager
- ->expects($this->exactly(3))
- ->method('getUserGroupNames')
- ->will($this->onConsecutiveCalls(
- array(
- 'Users' => array('displayName' => 'Users'),
- 'Support' => array('displayName' => 'Support')
- ),
- array(
- 'admins' => array('displayName' => 'admins'),
- 'Support' => array('displayName' => 'Support')
- ),
- array(
- 'External Users' => array('displayName' => 'External Users')
- )
- ));
-
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin->expects($this->any())
- ->method('getSubAdminsGroupsName')
- ->will($this->returnValue([]));
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
-
- $this->userMountCache
- ->expects($this->once())
- ->method('getUsedSpaceForUsers')
- ->will($this->returnValue(['admin' => 200, 'bar' => 2000, 'foo' => 512]));
-
- $expectedResponse = new DataResponse(
- array(
- 0 => array(
- 'name' => 'foo',
- 'displayname' => 'M. Foo',
- 'groups' => array(
- 'Users' => array('displayName' => 'Users'),
- 'Support' => array('displayName' => 'Support')
- ),
- 'subadmin' => array(),
- 'quota' => 1024,
- 'quota_bytes' => 1024,
- 'storageLocation' => '/home/foo',
- 'lastLogin' => 500000,
- 'backend' => 'OC_User_Database',
- 'email' => 'foo@bar.com',
- 'isRestoreDisabled' => false,
- 'isAvatarAvailable' => true,
- 'isEnabled' => true,
- 'size' => 512,
- ),
- 1 => array(
- 'name' => 'admin',
- 'displayname' => 'S. Admin',
- 'groups' => array(
- 'admins' => array('displayName' => 'admins'),
- 'Support' => array('displayName' => 'Support')
- ),
- 'subadmin' => array(),
- 'quota' => 404,
- 'quota_bytes' => 404,
- 'storageLocation' => '/home/admin',
- 'lastLogin' => 12000,
- 'backend' => Dummy::class,
- 'email' => 'admin@bar.com',
- 'isRestoreDisabled' => false,
- 'isAvatarAvailable' => false,
- 'isEnabled' => true,
- 'size' => 200,
- ),
- 2 => array(
- 'name' => 'bar',
- 'displayname' => 'B. Ar',
- 'groups' => array(
- 'External Users' => array('displayName' => 'External Users')
- ),
- 'subadmin' => array(),
- 'quota' => 2323,
- 'quota_bytes' => 2323,
- 'storageLocation' => '/home/bar',
- 'lastLogin' => 3999000,
- 'backend' => Dummy::class,
- 'email' => 'bar@dummy.com',
- 'isRestoreDisabled' => false,
- 'isAvatarAvailable' => true,
- 'isEnabled' => true,
- 'size' => 2000,
- ),
- )
- );
- $response = $controller->index(0, 10, '', 'pattern');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testIndexWithBackend() {
- $controller = $this->getController(true);
-
- $user = $this->createMock(User::class);
- $user
- ->expects($this->exactly(2))
- ->method('getUID')
- ->will($this->returnValue('foo'));
- $user
- ->expects($this->once())
- ->method('getDisplayName')
- ->will($this->returnValue('M. Foo'));
- $user
- ->expects($this->once())
- ->method('getEMailAddress')
- ->will($this->returnValue(null));
- $user
- ->expects($this->exactly(2))
- ->method('getQuota')
- ->will($this->returnValue('none'));
- $user
- ->method('getLastLogin')
- ->will($this->returnValue(500));
- $user
- ->method('getHome')
- ->will($this->returnValue('/home/foo'));
- $user
- ->expects($this->once())
- ->method('getBackendClassName')
- ->will($this->returnValue('OC_User_Database'));
- $user->expects($this->any())
- ->method('isEnabled')
- ->willReturn(true);
-
- $this->userManager
- ->expects($this->once())
- ->method('getBackends')
- ->will($this->returnValue([new Dummy(), new \OC\User\Database()]));
- $this->userManager
- ->expects($this->once())
- ->method('clearBackends');
- $this->userManager
- ->expects($this->once())
- ->method('search')
- ->with('')
- ->will($this->returnValue([$user]));
-
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin->expects($this->once())
- ->method('getSubAdminsGroupsName')
- ->will($this->returnValue([]));
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
-
- $this->userMountCache
- ->expects($this->once())
- ->method('getUsedSpaceForUsers')
- ->will($this->returnValue(['foo' => 512]));
-
- $expectedResponse = new DataResponse(
- array(
- 0 => array(
- 'name' => 'foo',
- 'displayname' => 'M. Foo',
- 'groups' => null,
- 'subadmin' => array(),
- 'quota' => 'none',
- 'quota_bytes' => 0,
- 'storageLocation' => '/home/foo',
- 'lastLogin' => 500000,
- 'backend' => 'OC_User_Database',
- 'email' => null,
- 'isRestoreDisabled' => false,
- 'isAvatarAvailable' => true,
- 'isEnabled' => true,
- 'size' => 512,
- )
- )
- );
- $response = $controller->index(0, 10, '','', Dummy::class);
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testIndexWithBackendNoUser() {
- $controller = $this->getController(true);
-
- $this->userManager
- ->expects($this->once())
- ->method('getBackends')
- ->will($this->returnValue([new Dummy(), new \OC\User\Database()]));
- $this->userManager
- ->expects($this->once())
- ->method('search')
- ->with('')
- ->will($this->returnValue([]));
-
- $this->userMountCache
- ->expects($this->once())
- ->method('getUsedSpaceForUsers')
- ->will($this->returnValue([]));
-
- $expectedResponse = new DataResponse([]);
- $response = $controller->index(0, 10, '','', Dummy::class);
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testCreateSuccessfulWithoutGroupAdmin() {
- $controller = $this->getController(true);
-
- $user = $this->createMock(User::class);
- $user
- ->method('getHome')
- ->will($this->returnValue('/home/user'));
- $user
- ->method('getUID')
- ->will($this->returnValue('foo'));
- $user
- ->expects($this->once())
- ->method('getBackendClassName')
- ->will($this->returnValue('bar'));
- $user->expects($this->any())
- ->method('isEnabled')
- ->willReturn(true);
-
- $this->userManager
- ->expects($this->once())
- ->method('createUser')
- ->will($this->onConsecutiveCalls($user));
-
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin
- ->expects($this->any())
- ->method('getSubAdminsGroupsName')
- ->with($user)
- ->will($this->returnValue([]));
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
-
- $expectedResponse = new DataResponse(
- array(
- 'name' => 'foo',
- 'groups' => null,
- 'storageLocation' => '/home/user',
- 'backend' => 'bar',
- 'lastLogin' => null,
- 'displayname' => null,
- 'quota' => null,
- 'subadmin' => array(),
- 'email' => null,
- 'isRestoreDisabled' => false,
- 'isAvatarAvailable' => true,
- 'isEnabled' => true,
- 'quota_bytes' => false,
- ),
- Http::STATUS_CREATED
- );
- $response = $controller->create('foo', 'password', array());
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testCreateSuccessfulWithGroupAdmin() {
- $controller = $this->getController(true);
-
- $user = $this->createMock(User::class);
- $user
- ->method('getHome')
- ->will($this->returnValue('/home/user'));
- $user
- ->method('getHome')
- ->will($this->returnValue('/home/user'));
- $user
- ->method('getUID')
- ->will($this->returnValue('foo'));
- $user
- ->expects($this->once())
- ->method('getBackendClassName')
- ->will($this->returnValue('bar'));
- $user->expects($this->any())
- ->method('isEnabled')
- ->willReturn(true);
- $existingGroup = $this->getMockBuilder(IGroup::class)
- ->disableOriginalConstructor()->getMock();
- $existingGroup
- ->expects($this->once())
- ->method('addUser')
- ->with($user);
- $newGroup = $this->getMockBuilder(IGroup::class)
- ->disableOriginalConstructor()->getMock();
- $newGroup
- ->expects($this->once())
- ->method('addUser')
- ->with($user);
-
- $this->userManager
- ->expects($this->once())
- ->method('createUser')
- ->will($this->onConsecutiveCalls($user));
- $this->groupManager
- ->expects($this->exactly(2))
- ->method('get')
- ->will($this->onConsecutiveCalls(null, $existingGroup));
- $this->groupManager
- ->expects($this->once())
- ->method('createGroup')
- ->with('NewGroup')
- ->will($this->onConsecutiveCalls($newGroup));
- $this->groupManager
- ->expects($this->once())
- ->method('getUserGroupNames')
- ->with($user)
- ->will($this->onConsecutiveCalls(
- array(
- 'NewGroup' => array('displayName' => 'NewGroup'),
- 'ExistingGroup' => array('displayName' => 'ExistingGroup')
- )
- ));
-
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin
- ->expects($this->once())
- ->method('getSubAdminsGroupsName')
- ->with($user)
- ->will($this->returnValue([]));
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
-
- $expectedResponse = new DataResponse(
- array(
- 'name' => 'foo',
- 'groups' => array(
- 'NewGroup' => array('displayName' => 'NewGroup'),
- 'ExistingGroup' => array('displayName' => 'ExistingGroup')
- ),
- 'storageLocation' => '/home/user',
- 'backend' => 'bar',
- 'lastLogin' => null,
- 'displayname' => null,
- 'quota' => null,
- 'subadmin' => array(),
- 'email' => null,
- 'isRestoreDisabled' => false,
- 'isAvatarAvailable' => true,
- 'isEnabled' => true,
- 'quota_bytes' => false,
- ),
- Http::STATUS_CREATED
- );
- $response = $controller->create('foo', 'password', array('NewGroup', 'ExistingGroup'));
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testCreateSuccessfulWithGroupSubAdmin() {
- $controller = $this->getController(false);
- $user = $this->createMock(IUser::class);
- $this->userSession
- ->expects($this->once())
- ->method('getUser')
- ->will($this->returnValue($user));
- $newUser = $this->createMock(IUser::class);
- $newUser
- ->method('getHome')
- ->will($this->returnValue('/home/user'));
- $newUser
- ->method('getHome')
- ->will($this->returnValue('/home/user'));
- $newUser
- ->method('getUID')
- ->will($this->returnValue('foo'));
- $newUser
- ->expects($this->once())
- ->method('getBackendClassName')
- ->will($this->returnValue('bar'));
- $subGroup1 = $this->createMock(IGroup::class);
- $newUser->expects($this->any())
- ->method('isEnabled')
- ->willReturn(true);
- $subGroup1
- ->expects($this->any())
- ->method('getGID')
- ->will($this->returnValue('SubGroup1'));
- $subGroup1
- ->expects($this->once())
- ->method('addUser')
- ->with($user);
- $this->userManager
- ->expects($this->once())
- ->method('createUser')
- ->will($this->returnValue($newUser));
- $this->groupManager
- ->expects($this->once())
- ->method('getUserGroupNames')
- ->with($user)
- ->will($this->onConsecutiveCalls(array('SubGroup1' =>
- array('displayName' => 'SubGroup1')
- )));
- $this->groupManager
- ->expects($this->once())
- ->method('getUserGroupNames')
- ->with($newUser)
- ->will($this->onConsecutiveCalls(['SubGroup1']));
-
- $subadmin = $this->createMock(\OC\SubAdmin::class);
- $subadmin->expects($this->atLeastOnce())
- ->method('getSubAdminsGroupsName')
- ->with($user)
- ->willReturnMap([
- [$user, [$subGroup1]],
- [$newUser, []],
- ]);
- $subadmin->expects($this->atLeastOnce())
- ->method('isSubAdminofGroup')
- ->willReturnMap([
- [$user, $subGroup1, true],
- ]);
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
- $this->groupManager->expects($this->atLeastOnce())
- ->method('get')
- ->willReturnMap([
- ['SubGroup1', $subGroup1],
- ]);
-
- $expectedResponse = new DataResponse(
- array(
- 'name' => 'foo',
- 'groups' => array('SubGroup1' => array('displayName' => 'SubGroup1')),
- 'storageLocation' => '/home/user',
- 'backend' => 'bar',
- 'lastLogin' => 0,
- 'displayname' => null,
- 'quota' => null,
- 'subadmin' => [],
- 'email' => null,
- 'isRestoreDisabled' => false,
- 'isAvatarAvailable' => true,
- 'isEnabled' => true,
- 'quota_bytes' => false,
- ),
- Http::STATUS_CREATED
- );
- $response = $controller->create('foo', 'password', ['SubGroup1', 'ExistingGroup']);
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testCreateUnsuccessfulAdmin() {
- $controller = $this->getController(true);
-
- $this->userManager
- ->method('createUser')
- ->will($this->throwException(new \Exception()));
-
- $expectedResponse = new DataResponse(
- array(
- 'message' => 'Unable to create user.'
- ),
- Http::STATUS_FORBIDDEN
- );
- $response = $controller->create('foo', 'password', array());
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testCreateUnsuccessfulSubAdminNoGroup() {
- $controller = $this->getController(false);
- $user = $this->createMock(IUser::class);
- $user->expects($this->any())
- ->method('getUID')
- ->will($this->returnValue('username'));
- $this->userSession->expects($this->once())
- ->method('getUser')
- ->will($this->returnValue($user));
-
- $this->userManager->expects($this->never())
- ->method('createUser');
-
- $expectedResponse = new DataResponse(
- [
- 'message' => 'No valid group selected'
- ],
- Http::STATUS_FORBIDDEN
- );
- $response = $controller->create('foo', 'password', []);
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testCreateUnsuccessfulSubAdmin() {
- $controller = $this->getController(false);
- $user = $this->createMock(IUser::class);
- $user->expects($this->any())
- ->method('getUID')
- ->will($this->returnValue('username'));
- $this->userSession->expects($this->once())
- ->method('getUser')
- ->will($this->returnValue($user));
-
- $this->userManager
- ->method('createUser')
- ->will($this->throwException(new \Exception()));
-
- $subgroup1 = $this->createMock(IGroup::class);
- $subgroup2 = $this->createMock(IGroup::class);
- $subadmin = $this->createMock(\OC\SubAdmin::class);
- $subadmin->expects($this->atLeastOnce())
- ->method('isSubAdminofGroup')
- ->willReturnMap([
- [$user, $subgroup1, true],
- [$user, $subgroup2, true],
- ]);
- $this->groupManager->expects($this->any())
- ->method('getSubAdmin')
- ->willReturn($subadmin);
- $this->groupManager->expects($this->atLeastOnce())
- ->method('get')
- ->willReturnMap([
- ['SubGroup1', $subgroup1],
- ['SubGroup2', $subgroup2],
- ]);
-
- $expectedResponse = new DataResponse(
- [
- 'message' => 'Unable to create user.'
- ],
- Http::STATUS_FORBIDDEN
- );
- $response = $controller->create('foo', 'password', array('SubGroup1', 'SubGroup2'));
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testDestroySelfAdmin() {
- $controller = $this->getController(true);
-
- $user = $this->createMock(User::class);
- $user
- ->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('myself'));
- $this->userSession
- ->method('getUser')
- ->will($this->returnValue($user));
-
- $expectedResponse = new DataResponse(
- array(
- 'status' => 'error',
- 'data' => array(
- 'message' => 'Unable to delete user.'
- )
- ),
- Http::STATUS_FORBIDDEN
- );
- $response = $controller->destroy('myself');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testDestroySelfSubadmin() {
- $controller = $this->getController(false);
-
- $user = $this->createMock(User::class);
- $user
- ->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('myself'));
- $this->userSession
- ->method('getUser')
- ->will($this->returnValue($user));
-
- $expectedResponse = new DataResponse(
- array(
- 'status' => 'error',
- 'data' => array(
- 'message' => 'Unable to delete user.'
- )
- ),
- Http::STATUS_FORBIDDEN
- );
- $response = $controller->destroy('myself');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testDestroyAdmin() {
- $controller = $this->getController(true);
-
- $user = $this->createMock(User::class);
- $user
- ->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('Admin'));
- $toDeleteUser = $this->createMock(User::class);
- $toDeleteUser
- ->expects($this->once())
- ->method('delete')
- ->will($this->returnValue(true));
- $this->userSession
- ->method('getUser')
- ->will($this->returnValue($user));
- $this->userManager
- ->method('get')
- ->with('UserToDelete')
- ->will($this->returnValue($toDeleteUser));
-
- $expectedResponse = new DataResponse(
- array(
- 'status' => 'success',
- 'data' => array(
- 'username' => 'UserToDelete'
- )
- ),
- Http::STATUS_NO_CONTENT
- );
- $response = $controller->destroy('UserToDelete');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testDestroySubAdmin() {
- $controller = $this->getController(false);
- $user = $this->createMock(User::class);
- $user
- ->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('myself'));
- $this->userSession
- ->method('getUser')
- ->will($this->returnValue($user));
-
- $user = $this->createMock(User::class);
- $toDeleteUser = $this->createMock(User::class);
- $toDeleteUser
- ->expects($this->once())
- ->method('delete')
- ->will($this->returnValue(true));
- $this->userSession
- ->method('getUser')
- ->will($this->returnValue($user));
- $this->userManager
- ->method('get')
- ->with('UserToDelete')
- ->will($this->returnValue($toDeleteUser));
-
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin->expects($this->once())
- ->method('isUserAccessible')
- ->with($user, $toDeleteUser)
- ->will($this->returnValue(true));
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
-
- $expectedResponse = new DataResponse(
- [
- 'status' => 'success',
- 'data' => [
- 'username' => 'UserToDelete'
- ]
- ],
- Http::STATUS_NO_CONTENT
- );
- $response = $controller->destroy('UserToDelete');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testDestroyUnsuccessfulAdmin() {
- $controller = $this->getController(true);
-
- $user = $this->createMock(User::class);
- $user
- ->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('Admin'));
- $toDeleteUser = $this->createMock(User::class);
- $toDeleteUser
- ->expects($this->once())
- ->method('delete')
- ->will($this->returnValue(false));
- $this->userSession
- ->method('getUser')
- ->will($this->returnValue($user));
- $this->userManager
- ->method('get')
- ->with('UserToDelete')
- ->will($this->returnValue($toDeleteUser));
-
- $expectedResponse = new DataResponse(
- array(
- 'status' => 'error',
- 'data' => array(
- 'message' => 'Unable to delete user.'
- )
- ),
- Http::STATUS_FORBIDDEN
- );
- $response = $controller->destroy('UserToDelete');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testDestroyUnsuccessfulSubAdmin() {
- $controller = $this->getController(false);
- $user = $this->createMock(User::class);
- $user
- ->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('myself'));
- $this->userSession
- ->method('getUser')
- ->will($this->returnValue($user));
-
- $toDeleteUser = $this->createMock(User::class);
- $toDeleteUser
- ->expects($this->once())
- ->method('delete')
- ->will($this->returnValue(false));
- $this->userSession
- ->method('getUser')
- ->will($this->returnValue($user));
- $this->userManager
- ->method('get')
- ->with('UserToDelete')
- ->will($this->returnValue($toDeleteUser));
-
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin->expects($this->once())
- ->method('isUserAccessible')
- ->with($user, $toDeleteUser)
- ->will($this->returnValue(true));
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
-
- $expectedResponse = new DataResponse(
- [
- 'status' => 'error',
- 'data' => [
- 'message' => 'Unable to delete user.'
- ]
- ],
- Http::STATUS_FORBIDDEN
- );
- $response = $controller->destroy('UserToDelete');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testDestroyNotAccessibleToSubAdmin() {
- $controller = $this->getController(false);
-
- $user = $this->createMock(User::class);
- $user
- ->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('myself'));
- $this->userSession
- ->method('getUser')
- ->will($this->returnValue($user));
-
- $toDeleteUser = $this->createMock(User::class);
- $this->userSession
- ->method('getUser')
- ->will($this->returnValue($user));
- $this->userManager
- ->method('get')
- ->with('UserToDelete')
- ->will($this->returnValue($toDeleteUser));
-
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin->expects($this->once())
- ->method('isUserAccessible')
- ->with($user, $toDeleteUser)
- ->will($this->returnValue(false));
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
-
- $expectedResponse = new DataResponse(
- [
- 'status' => 'error',
- 'data' => [
- 'message' => 'Authentication error'
- ]
- ],
- Http::STATUS_FORBIDDEN
- );
- $response = $controller->destroy('UserToDelete');
- $this->assertEquals($expectedResponse, $response);
- }
-
- /**
- * test if an invalid mail result in a failure response
- */
- public function testCreateUnsuccessfulWithInvalidEmailAdmin() {
- $controller = $this->getController(true);
-
- $expectedResponse = new DataResponse([
- 'message' => 'Invalid mail address',
- ],
- Http::STATUS_UNPROCESSABLE_ENTITY
- );
- $response = $controller->create('foo', 'password', [], 'invalidMailAdress');
- $this->assertEquals($expectedResponse, $response);
- }
-
- /**
- * test if a valid mail result in a successful mail send
- */
- public function testCreateSuccessfulWithValidEmailAdmin() {
- $controller = $this->getController(true);
- $this->mailer
- ->expects($this->at(0))
- ->method('validateMailAddress')
- ->with('validMail@Adre.ss')
- ->will($this->returnValue(true));
-
- $user = $this->createMock(User::class);
- $user
- ->method('getHome')
- ->will($this->returnValue('/home/user'));
- $user
- ->method('getHome')
- ->will($this->returnValue('/home/user'));
- $user
- ->method('getUID')
- ->will($this->returnValue('foo'));
- $user
- ->method('getDisplayName')
- ->will($this->returnValue('foo'));
- $user
- ->expects($this->once())
- ->method('getBackendClassName')
- ->will($this->returnValue('bar'));
-
- $emailTemplate = $this->createMock(IEMailTemplate::class);
- $this->newUserMailHelper
- ->expects($this->at(0))
- ->method('generateTemplate')
- ->with($user, false)
- ->willReturn($emailTemplate);
- $this->newUserMailHelper
- ->expects($this->at(1))
- ->method('sendMail')
- ->with($user, $emailTemplate);
-
- $this->userManager
- ->expects($this->once())
- ->method('createUser')
- ->will($this->onConsecutiveCalls($user));
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin->expects($this->once())
- ->method('getSubAdminsGroupsName')
- ->with($user)
- ->will($this->returnValue([]));
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
-
- $response = $controller->create('foo', 'password', [], 'validMail@Adre.ss');
- $this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
- }
-
- private function mockUser($userId = 'foo', $displayName = 'M. Foo',
- $lastLogin = 500, $home = '/home/foo',
- $backend = 'OC_User_Database', $enabled = true) {
- $user = $this->createMock(User::class);
- $user
- ->expects($this->any())
- ->method('getUID')
- ->will($this->returnValue($userId));
- $user
- ->expects($this->once())
- ->method('getDisplayName')
- ->will($this->returnValue($displayName));
- $user
- ->method('getLastLogin')
- ->will($this->returnValue($lastLogin));
- $user
- ->method('getHome')
- ->will($this->returnValue($home));
- $user
- ->expects($this->once())
- ->method('getBackendClassName')
- ->will($this->returnValue($backend));
- $user->expects($this->any())
- ->method('isEnabled')
- ->willReturn($enabled);
-
- $result = [
- 'name' => $userId,
- 'displayname' => $displayName,
- 'groups' => null,
- 'subadmin' => array(),
- 'quota' => null,
- 'storageLocation' => $home,
- 'lastLogin' => $lastLogin * 1000,
- 'backend' => $backend,
- 'email' => null,
- 'isRestoreDisabled' => false,
- 'isAvatarAvailable' => true,
- 'isEnabled' => $enabled,
- 'quota_bytes' => false,
- ];
-
- return [$user, $result];
- }
-
- public function testRestorePossibleWithoutEncryption() {
- $controller = $this->getController(true);
-
- list($user, $expectedResult) = $this->mockUser();
-
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin->expects($this->once())
- ->method('getSubAdminsGroupsName')
- ->with($user)
- ->will($this->returnValue([]));
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
-
- $result = self::invokePrivate($controller, 'formatUserForIndex', [$user]);
- $this->assertEquals($expectedResult, $result);
- }
-
- public function testRestorePossibleWithAdminAndUserRestore() {
- list($user, $expectedResult) = $this->mockUser();
-
- $this->appManager
- ->expects($this->once())
- ->method('isEnabledForUser')
- ->with(
- $this->equalTo('encryption')
- )
- ->will($this->returnValue(true));
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with(
- $this->equalTo('encryption'),
- $this->equalTo('recoveryAdminEnabled'),
- $this->anything()
- )
- ->will($this->returnValue('1'));
-
- $this->config
- ->expects($this->at(1))
- ->method('getUserValue')
- ->with(
- $this->anything(),
- $this->equalTo('encryption'),
- $this->equalTo('recoveryEnabled'),
- $this->anything()
- )
- ->will($this->returnValue('1'));
-
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin->expects($this->once())
- ->method('getSubAdminsGroupsName')
- ->with($user)
- ->will($this->returnValue([]));
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
-
- $controller = $this->getController(true);
- $result = self::invokePrivate($controller, 'formatUserForIndex', [$user]);
- $this->assertEquals($expectedResult, $result);
- }
-
- /**
- * @dataProvider dataTestRestoreNotPossibleWithoutAdminRestore
- *
- * @param bool $masterKeyEnabled
- */
- public function testRestoreNotPossibleWithoutAdminRestore($masterKeyEnabled) {
- list($user, $expectedResult) = $this->mockUser();
-
- // without the master key enabled we use per-user keys
- $this->encryptionModule->expects($this->once())->method('needDetailedAccessList')->willReturn(!$masterKeyEnabled);
-
- $this->appManager
- ->method('isEnabledForUser')
- ->with(
- $this->equalTo('encryption')
- )
- ->will($this->returnValue(true));
-
- // without the master key enabled we use per-user keys -> restore is disabled
- $expectedResult['isRestoreDisabled'] = !$masterKeyEnabled;
-
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin->expects($this->once())
- ->method('getSubAdminsGroupsName')
- ->with($user)
- ->will($this->returnValue([]));
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
-
- $controller = $this->getController(true);
- $result = self::invokePrivate($controller, 'formatUserForIndex', [$user]);
- $this->assertEquals($expectedResult, $result);
- }
-
- public function dataTestRestoreNotPossibleWithoutAdminRestore() {
- return [
- [true],
- [false]
- ];
- }
-
- public function testRestoreNotPossibleWithoutUserRestore() {
- list($user, $expectedResult) = $this->mockUser();
-
- $this->appManager
- ->expects($this->once())
- ->method('isEnabledForUser')
- ->with(
- $this->equalTo('encryption')
- )
- ->will($this->returnValue(true));
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with(
- $this->equalTo('encryption'),
- $this->equalTo('recoveryAdminEnabled'),
- $this->anything()
- )
- ->will($this->returnValue('1'));
-
- $this->config
- ->expects($this->at(1))
- ->method('getUserValue')
- ->with(
- $this->anything(),
- $this->equalTo('encryption'),
- $this->equalTo('recoveryEnabled'),
- $this->anything()
- )
- ->will($this->returnValue('0'));
-
- $expectedResult['isRestoreDisabled'] = true;
-
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin->expects($this->once())
- ->method('getSubAdminsGroupsName')
- ->with($user)
- ->will($this->returnValue([]));
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
-
- $controller = $this->getController(true);
- $result = self::invokePrivate($controller, 'formatUserForIndex', [$user]);
- $this->assertEquals($expectedResult, $result);
- }
-
- public function testNoAvatar() {
- $controller = $this->getController(true);
-
- list($user, $expectedResult) = $this->mockUser();
-
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin->expects($this->once())
- ->method('getSubAdminsGroupsName')
- ->with($user)
- ->will($this->returnValue([]));
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
-
- $this->avatarManager
- ->method('getAvatar')
- ->will($this->throwException(new \OCP\Files\NotFoundException()));
- $expectedResult['isAvatarAvailable'] = false;
-
- $result = self::invokePrivate($controller, 'formatUserForIndex', [$user]);
- $this->assertEquals($expectedResult, $result);
- }
-
- public function testStatsAdmin() {
- $controller = $this->getController(true);
-
- $this->userManager
- ->expects($this->at(0))
- ->method('countUsers')
- ->will($this->returnValue([128, 44]));
-
- $expectedResponse = new DataResponse(
- [
- 'totalUsers' => 172
- ]
- );
- $response = $controller->stats();
- $this->assertEquals($expectedResponse, $response);
- }
-
- /**
- * Tests that the subadmin stats return unique users, even
- * when a user appears in several groups.
- */
- public function testStatsSubAdmin() {
- $controller = $this->getController(false);
-
- $user = $this->createMock(User::class);
-
- $this->userSession
- ->expects($this->once())
- ->method('getUser')
- ->will($this->returnValue($user));
-
- $group1 = $this->getMockBuilder(Group::class)
- ->disableOriginalConstructor()->getMock();
- $group1
- ->expects($this->once())
- ->method('getUsers')
- ->will($this->returnValue(['foo' => 'M. Foo', 'admin' => 'S. Admin']));
-
- $group2 = $this->getMockBuilder(Group::class)
- ->disableOriginalConstructor()->getMock();
- $group2
- ->expects($this->once())
- ->method('getUsers')
- ->will($this->returnValue(['bar' => 'B. Ar']));
-
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin
- ->expects($this->at(0))
- ->method('getSubAdminsGroupsName')
- ->will($this->returnValue([$group1, $group2]));
- $subadmin
- ->expects($this->at(0))
- ->method('getSubAdminsGroups')
- ->will($this->returnValue([$group1, $group2]));
-
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
-
- $expectedResponse = new DataResponse(
- [
- 'totalUsers' => 3
- ]
- );
-
- $response = $controller->stats();
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function dataSetDisplayName() {
- $data = [];
-
- $user1 = $this->createMock(IUser::class);
- $user1->method('getUID')->willReturn('user1');
- $user1->method('canChangeDisplayName')->willReturn(true);
- $data[] = [$user1, $user1, false, false, true];
-
- $user1 = $this->createMock(IUser::class);
- $user1->method('getUID')->willReturn('user1');
- $user1->method('canChangeDisplayName')->willReturn(false);
- $data[] = [$user1, $user1, false, false, false];
-
- $user1 = $this->createMock(IUser::class);
- $user1->method('getUID')->willReturn('user1');
- $user2 = $this->createMock(IUser::class);
- $user2->method('getUID')->willReturn('user2');
- $user2->method('canChangeDisplayName')->willReturn(true);
- $data[] = [$user1, $user2, false, false, false];
-
- $user1 = $this->createMock(IUser::class);
- $user1->method('getUID')->willReturn('user1');
- $user2 = $this->createMock(IUser::class);
- $user2->method('getUID')->willReturn('user2');
- $user2->method('canChangeDisplayName')->willReturn(true);
- $data[] = [$user1, $user2, true, false, true];
-
- $user1 = $this->createMock(IUser::class);
- $user1->method('getUID')->willReturn('user1');
- $user2 = $this->createMock(IUser::class);
- $user2->method('getUID')->willReturn('user2');
- $user2->method('canChangeDisplayName')->willReturn(true);
- $data[] = [$user1, $user2, false, true, true];
-
- return $data;
- }
-
- /**
- * @dataProvider dataSetDisplayName
- *
- * @param IUser|\PHPUnit_Framework_MockObject_MockObject $currentUser
- * @param IUser|\PHPUnit_Framework_MockObject_MockObject $editUser
- * @param bool $isAdmin
- * @param bool $isSubAdmin
- * @param bool $valid
- */
- public function testSetDisplayName($currentUser, $editUser, $isAdmin, $isSubAdmin, $valid) {
- $this->userSession
- ->expects($this->once())
- ->method('getUser')
- ->willReturn($currentUser);
- $this->userManager
- ->expects($this->once())
- ->method('get')
- ->with($editUser->getUID())
- ->willReturn($editUser);
- $this->accountManager->expects($this->any())->method('getUser')->willReturn([]);
-
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin
- ->method('isUserAccessible')
- ->with($currentUser, $editUser)
- ->willReturn($isSubAdmin);
-
- $this->groupManager
- ->method('getSubAdmin')
- ->willReturn($subadmin);
- $this->groupManager
- ->method('isAdmin')
- ->with($currentUser->getUID())
- ->willReturn($isAdmin);
-
- if ($valid === true) {
- $expectedResponse = new DataResponse(
- [
- 'status' => 'success',
- 'data' => [
- 'message' => 'Your full name has been changed.',
- 'username' => $editUser->getUID(),
- 'displayName' => 'newDisplayName',
- ],
- ]
- );
- } else {
- $expectedResponse = new DataResponse(
- [
- 'status' => 'error',
- 'data' => [
- 'message' => 'Authentication error',
- ],
- ]
- );
- }
-
- $controller = $this->getController(true);
- $response = $controller->setDisplayName($editUser->getUID(), 'newDisplayName');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testSetDisplayNameFails() {
- /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
- $user = $this->createMock(IUser::class);
- $user->method('canChangeDisplayname')->willReturn(true);
- $user->method('getUID')->willReturn('user');
- $user->expects($this->once())
- ->method('setDisplayName')
- ->with('newDisplayName')
- ->willReturn(false);
- $user->method('getDisplayName')->willReturn('oldDisplayName');
-
- $this->userSession
- ->expects($this->once())
- ->method('getUser')
- ->willReturn($user);
-
- $this->userManager
- ->expects($this->once())
- ->method('get')
- ->with($user->getUID())
- ->willReturn($user);
-
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin
- ->method('isUserAccessible')
- ->with($user, $user)
- ->willReturn(false);
-
- $this->groupManager
- ->method('getSubAdmin')
- ->willReturn($subadmin);
- $this->groupManager
- ->expects($this->once())
- ->method('isAdmin')
- ->with($user->getUID())
- ->willReturn(false);
-
- $expectedResponse = new DataResponse(
- [
- 'status' => 'error',
- 'data' => [
- 'message' => 'Unable to change full name',
- 'displayName' => 'oldDisplayName',
- ],
- ]
- );
- $controller = $this->getController(true);
- $response = $controller->setDisplayName($user->getUID(), 'newDisplayName');
- $this->assertEquals($expectedResponse, $response);
- }
-
/**
* @dataProvider dataTestSetUserSettings
*
@@ -2361,158 +428,6 @@ class UsersControllerTest extends \Test\TestCase {
}
/**
- * @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 $canChangeDisplayName
- * @param int $responseCode
- */
- public function testSetEMailAddress($mailAddress, $isValid, $expectsUpdate, $canChangeDisplayName, $responseCode) {
- $user = $this->createMock(User::class);
- $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)
- );
- $user->method('getEMailAddress')->willReturn('oldEmailAddress');
- $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));
- }
- $controller = $this->getController(true);
- $response = $controller->setEMailAddress($user->getUID(), $mailAddress);
- $this->assertSame($responseCode, $response->getStatus());
- }
-
- public function testCreateUnsuccessfulWithoutPasswordAndEmail() {
- $controller = $this->getController(true);
-
- $expectedResponse = new DataResponse(
- array(
- 'message' => 'To send a password link to the user an email address is required.'
- ),
- Http::STATUS_UNPROCESSABLE_ENTITY
- );
- $response = $controller->create('foo', '', array(), '');
- $this->assertEquals($expectedResponse, $response);
- }
-
-
-
- public function testCreateSuccessfulWithoutPasswordAndWithEmail() {
- $user = $this->createMock(User::class);
- $user
- ->method('getHome')
- ->willReturn('/home/user');
- $user
- ->method('getUID')
- ->willReturn('foo');
- $user
- ->method('getDisplayName')
- ->willReturn('John Doe');
- $user
- ->method('getEmailAddress')
- ->willReturn('abc@example.org');
- $user
- ->expects($this->once())
- ->method('getBackendClassName')
- ->willReturn('bar');
- $user
- ->method('isEnabled')
- ->willReturn(true);
-
- $this->userManager
- ->expects($this->once())
- ->method('createUser')
- ->will($this->onConsecutiveCalls($user));
-
- $subadmin = $this->getMockBuilder(SubAdmin::class)
- ->disableOriginalConstructor()
- ->getMock();
- $subadmin
- ->expects($this->any())
- ->method('getSubAdminsGroupsName')
- ->with($user)
- ->will($this->returnValue([]));
- $this->groupManager
- ->expects($this->any())
- ->method('getSubAdmin')
- ->will($this->returnValue($subadmin));
-
- $controller = $this->getController(true);
- $this->mailer
- ->expects($this->at(0))
- ->method('validateMailAddress')
- ->with('abc@example.org')
- ->will($this->returnValue(true));
- $emailTemplate = $this->createMock(IEMailTemplate::class);
- $this->newUserMailHelper
- ->expects($this->at(0))
- ->method('generateTemplate')
- ->with($user, true)
- ->willReturn($emailTemplate);
- $this->newUserMailHelper
- ->expects($this->at(1))
- ->method('sendMail')
- ->with($user, $emailTemplate);
-
- $expectedResponse = new DataResponse(
- [
- 'name' => 'foo',
- 'groups' => null,
- 'storageLocation' => '/home/user',
- 'backend' => 'bar',
- 'lastLogin' => 0,
- 'displayname' => 'John Doe',
- 'quota' => null,
- 'quota_bytes' => false,
- 'subadmin' => array(),
- 'email' => 'abc@example.org',
- 'isRestoreDisabled' => false,
- 'isAvatarAvailable' => true,
- 'isEnabled' => true,
- ],
- Http::STATUS_CREATED
- );
- $response = $controller->create('foo', '', array(), 'abc@example.org');
- $this->assertEquals($expectedResponse, $response);
- }
-
- /**
* @param string $account
* @param string $type
* @param array $dataBefore
@@ -2598,425 +513,4 @@ class UsersControllerTest extends \Test\TestCase {
$this->assertSame(Http::STATUS_BAD_REQUEST, $result->getStatus());
}
- public function testDisableUserFailsDueSameUser() {
- $user = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('abc'));
- $this->userSession
- ->expects($this->once())
- ->method('getUser')
- ->will($this->returnValue($user));
- $expectedResponse = new DataResponse(
- [
- 'status' => 'error',
- 'data' => [
- 'message' => 'Error while disabling user.',
- ],
- ],
- Http::STATUS_FORBIDDEN
- );
- $response = $this->getController(true)->setEnabled('abc', false);
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testDisableUserFailsDueNoAdminAndNoSubadmin() {
- $user = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('def'));
- $this->userSession
- ->expects($this->exactly(2))
- ->method('getUser')
- ->will($this->returnValue($user));
- $user2 = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user2->expects($this->never())
- ->method('setEnabled');
- $this->userManager
- ->expects($this->once())
- ->method('get')
- ->with('abc')
- ->willReturn($user2);
-
- $subadmin = $this->createMock(SubAdmin::class);
- $subadmin->expects($this->once())
- ->method('isUserAccessible')
- ->will($this->returnValue(false));
- $this->groupManager
- ->expects($this->once())
- ->method('getSubAdmin')
- ->willReturn($subadmin);
-
- $expectedResponse = new DataResponse(
- [
- 'status' => 'error',
- 'data' => [
- 'message' => 'Authentication error',
- ],
- ],
- Http::STATUS_FORBIDDEN
- );
- $response = $this->getController(false)->setEnabled('abc', false);
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testDisableUserFailsDueNoUser() {
- $user = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('def'));
- $this->userSession
- ->expects($this->exactly(1))
- ->method('getUser')
- ->will($this->returnValue($user));
- $this->userManager
- ->expects($this->once())
- ->method('get')
- ->with('abc')
- ->willReturn(null);
-
- $this->groupManager
- ->expects($this->never())
- ->method('getSubAdmin');
-
- $expectedResponse = new DataResponse(
- [
- 'status' => 'error',
- 'data' => [
- 'message' => 'Error while disabling user.',
- ],
- ],
- Http::STATUS_FORBIDDEN
- );
- $response = $this->getController(true)->setEnabled('abc', false);
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testDisableUserFailsDueNoUserForSubAdmin() {
- $user = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('def'));
- $this->userSession
- ->expects($this->exactly(1))
- ->method('getUser')
- ->will($this->returnValue($user));
- $this->userManager
- ->expects($this->once())
- ->method('get')
- ->with('abc')
- ->willReturn(null);
-
- $this->groupManager
- ->expects($this->never())
- ->method('getSubAdmin');
-
- $expectedResponse = new DataResponse(
- [
- 'status' => 'error',
- 'data' => [
- 'message' => 'Error while disabling user.',
- ],
- ],
- Http::STATUS_FORBIDDEN
- );
- $response = $this->getController(false)->setEnabled('abc', false);
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testDisableUserSuccessForAdmin() {
- $user = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('def'));
- $this->userSession
- ->expects($this->exactly(1))
- ->method('getUser')
- ->will($this->returnValue($user));
- $user2 = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user2->expects($this->once())
- ->method('setEnabled')
- ->with(false);
- $this->userManager
- ->expects($this->once())
- ->method('get')
- ->with('abc')
- ->willReturn($user2);
-
- $this->groupManager
- ->expects($this->never())
- ->method('getSubAdmin');
-
- $expectedResponse = new DataResponse(
- [
- 'status' => 'success',
- 'data' => [
- 'username' => 'abc',
- 'enabled' => 0,
- ],
- ]
- );
- $response = $this->getController(true)->setEnabled('abc', false);
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testDisableUserSuccessForSubAdmin() {
- $user = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('def'));
- $this->userSession
- ->expects($this->exactly(2))
- ->method('getUser')
- ->will($this->returnValue($user));
- $user2 = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user2->expects($this->once())
- ->method('setEnabled');
- $this->userManager
- ->expects($this->once())
- ->method('get')
- ->with('abc')
- ->willReturn($user2);
-
- $subadmin = $this->createMock(SubAdmin::class);
- $subadmin->expects($this->once())
- ->method('isUserAccessible')
- ->will($this->returnValue(true));
- $this->groupManager
- ->expects($this->once())
- ->method('getSubAdmin')
- ->willReturn($subadmin);
-
- $expectedResponse = new DataResponse(
- [
- 'status' => 'success',
- 'data' => [
- 'username' => 'abc',
- 'enabled' => 0,
- ],
- ]
- );
- $response = $this->getController(false)->setEnabled('abc', false);
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testEnableUserFailsDueSameUser() {
- $user = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('abc'));
- $this->userSession
- ->expects($this->once())
- ->method('getUser')
- ->will($this->returnValue($user));
- $expectedResponse = new DataResponse(
- [
- 'status' => 'error',
- 'data' => [
- 'message' => 'Error while enabling user.',
- ],
- ],
- Http::STATUS_FORBIDDEN
- );
- $response = $this->getController(true)->setEnabled('abc', true);
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testEnableUserFailsDueNoAdminAndNoSubadmin() {
- $user = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('def'));
- $this->userSession
- ->expects($this->exactly(2))
- ->method('getUser')
- ->will($this->returnValue($user));
- $user2 = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user2->expects($this->never())
- ->method('setEnabled');
- $this->userManager
- ->expects($this->once())
- ->method('get')
- ->with('abc')
- ->willReturn($user2);
-
- $subadmin = $this->createMock(SubAdmin::class);
- $subadmin->expects($this->once())
- ->method('isUserAccessible')
- ->will($this->returnValue(false));
- $this->groupManager
- ->expects($this->once())
- ->method('getSubAdmin')
- ->willReturn($subadmin);
-
- $expectedResponse = new DataResponse(
- [
- 'status' => 'error',
- 'data' => [
- 'message' => 'Authentication error',
- ],
- ],
- Http::STATUS_FORBIDDEN
- );
- $response = $this->getController(false)->setEnabled('abc', true);
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testEnableUserFailsDueNoUser() {
- $user = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('def'));
- $this->userSession
- ->expects($this->exactly(1))
- ->method('getUser')
- ->will($this->returnValue($user));
- $this->userManager
- ->expects($this->once())
- ->method('get')
- ->with('abc')
- ->willReturn(null);
-
- $this->groupManager
- ->expects($this->never())
- ->method('getSubAdmin');
-
- $expectedResponse = new DataResponse(
- [
- 'status' => 'error',
- 'data' => [
- 'message' => 'Error while enabling user.',
- ],
- ],
- Http::STATUS_FORBIDDEN
- );
- $response = $this->getController(true)->setEnabled('abc', true);
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testEnableUserFailsDueNoUserForSubAdmin() {
- $user = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('def'));
- $this->userSession
- ->expects($this->exactly(1))
- ->method('getUser')
- ->will($this->returnValue($user));
- $this->userManager
- ->expects($this->once())
- ->method('get')
- ->with('abc')
- ->willReturn(null);
-
- $this->groupManager
- ->expects($this->never())
- ->method('getSubAdmin');
-
- $expectedResponse = new DataResponse(
- [
- 'status' => 'error',
- 'data' => [
- 'message' => 'Error while enabling user.',
- ],
- ],
- Http::STATUS_FORBIDDEN
- );
- $response = $this->getController(false)->setEnabled('abc', true);
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testEnableUserSuccessForAdmin() {
- $user = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('def'));
- $this->userSession
- ->expects($this->exactly(1))
- ->method('getUser')
- ->will($this->returnValue($user));
- $user2 = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user2->expects($this->once())
- ->method('setEnabled');
- $this->userManager
- ->expects($this->once())
- ->method('get')
- ->with('abc')
- ->willReturn($user2);
-
- $this->groupManager
- ->expects($this->never())
- ->method('getSubAdmin');
-
- $expectedResponse = new DataResponse(
- [
- 'status' => 'success',
- 'data' => [
- 'username' => 'abc',
- 'enabled' => 1,
- ],
- ]
- );
- $response = $this->getController(true)->setEnabled('abc', true);
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testEnableUserSuccessForSubAdmin() {
- $user = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user->expects($this->once())
- ->method('getUID')
- ->will($this->returnValue('def'));
- $this->userSession
- ->expects($this->exactly(2))
- ->method('getUser')
- ->will($this->returnValue($user));
- $user2 = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
- $user2->expects($this->once())
- ->method('setEnabled')
- ->with(true);
- $this->userManager
- ->expects($this->once())
- ->method('get')
- ->with('abc')
- ->willReturn($user2);
-
- $subadmin = $this->createMock(SubAdmin::class);
- $subadmin->expects($this->once())
- ->method('isUserAccessible')
- ->will($this->returnValue(true));
- $this->groupManager
- ->expects($this->once())
- ->method('getSubAdmin')
- ->willReturn($subadmin);
-
- $expectedResponse = new DataResponse(
- [
- 'status' => 'success',
- 'data' => [
- 'username' => 'abc',
- 'enabled' => 1,
- ],
- ]
- );
- $response = $this->getController(false)->setEnabled('abc', true);
- $this->assertEquals($expectedResponse, $response);
- }
}
diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml
index 7eee0a4da9c..5f1b27ffe2d 100644
--- a/tests/acceptance/config/behat.yml
+++ b/tests/acceptance/config/behat.yml
@@ -8,8 +8,10 @@ default:
- NextcloudTestServerContext
- AppNavigationContext
+ - AppSettingsContext
- CommentsAppContext
- ContactsMenuContext
+ - DialogContext
- FeatureContext
- FileListContext
- FilesAppContext
diff --git a/tests/acceptance/features/bootstrap/AppNavigationContext.php b/tests/acceptance/features/bootstrap/AppNavigationContext.php
index 9ef71a06065..e6e6bcc8479 100644
--- a/tests/acceptance/features/bootstrap/AppNavigationContext.php
+++ b/tests/acceptance/features/bootstrap/AppNavigationContext.php
@@ -1,9 +1,10 @@
<?php
/**
- *
+ *
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
- *
+ * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
+ *
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
@@ -32,24 +33,43 @@ class AppNavigationContext implements Context, ActorAwareInterface {
*/
public static function appNavigation() {
return Locator::forThe()->id("app-navigation")->
- describedAs("App navigation");
+ describedAs("App navigation");
}
/**
* @return Locator
*/
public static function appNavigationSectionItemFor($sectionText) {
- return Locator::forThe()->xpath("//li[normalize-space() = '$sectionText']")->
- descendantOf(self::appNavigation())->
- describedAs($sectionText . " section item in App Navigation");
+ return Locator::forThe()->xpath("//li/a[normalize-space() = '$sectionText']/..")->
+ descendantOf(self::appNavigation())->
+ describedAs($sectionText . " section item in App Navigation");
}
/**
* @return Locator
*/
public static function appNavigationCurrentSectionItem() {
- return Locator::forThe()->css(".active")->descendantOf(self::appNavigation())->
- describedAs("Current section item in App Navigation");
+ return Locator::forThe()->css(".active")->
+ descendantOf(self::appNavigation())->
+ describedAs("Current section item in App Navigation");
+ }
+
+ /**
+ * @return Locator
+ */
+ public static function buttonForTheSection($class, $section) {
+ return Locator::forThe()->css("." . $class)->
+ descendantOf(self::appNavigationSectionItemFor($section))->
+ describedAs("The $class button on the $section section in App Navigation");
+ }
+
+ /**
+ * @return Locator
+ */
+ public static function counterForTheSection($section) {
+ return Locator::forThe()->css(".app-navigation-entry-utils-counter")->
+ descendantOf(self::appNavigationSectionItemFor($section))->
+ describedAs("The counter for the $section section in App Navigation");
}
/**
@@ -60,10 +80,38 @@ class AppNavigationContext implements Context, ActorAwareInterface {
}
/**
+ * @Given I click the :class button on the :section section
+ */
+ public function iClickTheButtonInTheSection($class, $section) {
+ $this->actor->find(self::buttonForTheSection($class, $section), 10)->click();
+ }
+
+ /**
* @Then I see that the current section is :section
*/
public function iSeeThatTheCurrentSectionIs($section) {
PHPUnit_Framework_Assert::assertEquals($this->actor->find(self::appNavigationCurrentSectionItem(), 10)->getText(), $section);
}
+ /**
+ * @Then I see that the section :section is shown
+ */
+ public function iSeeThatTheSectionIsShown($section) {
+ WaitFor::elementToBeEventuallyShown($this->actor, self::appNavigationSectionItemFor($section));
+ }
+
+ /**
+ * @Then I see that the section :section is not shown
+ */
+ public function iSeeThatTheSectionIsNotShown($section) {
+ WaitFor::elementToBeEventuallyNotShown($this->actor, self::appNavigationSectionItemFor($section));
+ }
+
+ /**
+ * @Then I see that the section :section has a count of :count
+ */
+ public function iSeeThatTheSectionHasACountOf($section, $count) {
+ PHPUnit_Framework_Assert::assertEquals($this->actor->find(self::counterForTheSection($section), 10)->getText(), $count);
+ }
+
}
diff --git a/tests/acceptance/features/bootstrap/AppSettingsContext.php b/tests/acceptance/features/bootstrap/AppSettingsContext.php
new file mode 100644
index 00000000000..5cf54cb5280
--- /dev/null
+++ b/tests/acceptance/features/bootstrap/AppSettingsContext.php
@@ -0,0 +1,102 @@
+<?php
+
+/**
+ *
+ * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
+ * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+use Behat\Behat\Context\Context;
+
+class AppSettingsContext implements Context, ActorAwareInterface {
+
+ use ActorAware;
+
+ /**
+ * @return Locator
+ */
+ public static function appSettings() {
+ return Locator::forThe()->id("app-settings")->
+ describedAs("App settings");
+ }
+ /**
+ * @return Locator
+ */
+ public static function appSettingsContent() {
+ return Locator::forThe()->id("app-settings-content")->
+ descendantOf(self::appSettings())->
+ describedAs("App settings");
+ }
+
+ /**
+ * @return Locator
+ */
+ public static function appSettingsOpenButton() {
+ return Locator::forThe()->xpath("//div[@id = 'app-settings-header']/button")->
+ descendantOf(self::appSettings())->
+ describedAs("The button to open the app settings");
+ }
+
+ /**
+ * @return Locator
+ */
+ public static function checkboxInTheSettings($id) {
+ return Locator::forThe()->xpath("//input[@id = '$id']")->
+ descendantOf(self::appSettingsContent())->
+ describedAs("The $id checkbox in the settings");
+ }
+
+ /**
+ * @return Locator
+ */
+ public static function checkboxLabelInTheSettings($id) {
+ return Locator::forThe()->xpath("//label[@for = '$id']")->
+ descendantOf(self::appSettingsContent())->
+ describedAs("The label for the $id checkbox in the settings");
+ }
+
+ /**
+ * @Given I open the settings
+ */
+ public function iOpenTheSettings() {
+ $this->actor->find(self::appSettingsOpenButton())->click();
+ }
+
+ /**
+ * @Given I toggle the :id checkbox in the settings
+ */
+ public function iToggleTheCheckboxInTheSettingsTo($id) {
+ $locator = self::CheckboxInTheSettings($id);
+
+ // If locator is not visible, fallback to label
+ if (!$this->actor->find(self::CheckboxInTheSettings($id))->isVisible()) {
+ $locator = self::checkboxLabelInTheSettings($id);
+ }
+
+ $this->actor->find($locator)->click();
+ }
+
+ /**
+ * @Then I see that the settings are opened
+ */
+ public function iSeeThatTheSettingsAreOpened() {
+ WaitFor::elementToBeEventuallyShown($this->actor, self::appSettingsContent());
+ }
+
+}
diff --git a/tests/acceptance/features/bootstrap/DialogContext.php b/tests/acceptance/features/bootstrap/DialogContext.php
new file mode 100644
index 00000000000..8f387992b5f
--- /dev/null
+++ b/tests/acceptance/features/bootstrap/DialogContext.php
@@ -0,0 +1,68 @@
+<?php
+
+/**
+ *
+ * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+use Behat\Behat\Context\Context;
+
+class DialogContext implements Context, ActorAwareInterface {
+
+ use ActorAware;
+
+ /**
+ * @return Locator
+ */
+ public static function theDialog() {
+ return Locator::forThe()->css(".oc-dialog")->
+ describedAs("The dialog");
+ }
+
+ /**
+ * @return Locator
+ */
+ public static function theDialogButton($text) {
+ return Locator::forThe()->xpath("//button[normalize-space() = '$text']")->
+ descendantOf(self::theDialog())->
+ describedAs($text . " button of the dialog");
+ }
+
+ /**
+ * @Given I click the :text button of the confirmation dialog
+ */
+ public function iClickTheDialogButton($text) {
+ $this->actor->find(self::theDialogButton($text), 10)->click();
+ }
+
+ /**
+ * @Then I see that the confirmation dialog is shown
+ */
+ public function iSeeThatTheConfirmationDialogIsShown() {
+ WaitFor::elementToBeEventuallyShown($this->actor, self::theDialog());
+ }
+
+ /**
+ * @Then I see that the confirmation dialog is not shown
+ */
+ public function iSeeThatTheConfirmationDialogIsNotShown() {
+ WaitFor::elementToBeEventuallyNotShown($this->actor, self::theDialog());
+ }
+
+}
diff --git a/tests/acceptance/features/bootstrap/UsersSettingsContext.php b/tests/acceptance/features/bootstrap/UsersSettingsContext.php
index 9ddea57f413..995bbdd8725 100644
--- a/tests/acceptance/features/bootstrap/UsersSettingsContext.php
+++ b/tests/acceptance/features/bootstrap/UsersSettingsContext.php
@@ -1,8 +1,9 @@
<?php
/**
- *
+ *
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
+ * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
*
* @license GNU AGPL version 3 or any later version
*
@@ -31,7 +32,7 @@ class UsersSettingsContext implements Context, ActorAwareInterface {
* @return Locator
*/
public static function newUserForm() {
- return Locator::forThe()->id("newuserHeader")->
+ return Locator::forThe()->id("new-user")->
describedAs("New user form in Users Settings");
}
@@ -63,7 +64,7 @@ class UsersSettingsContext implements Context, ActorAwareInterface {
* @return Locator
*/
public static function createNewUserButton() {
- return Locator::forThe()->xpath("//form[@id = 'newuser']//input[@type = 'submit']")->
+ return Locator::forThe()->xpath("//form[@id = 'new-user']//input[@type = 'submit']")->
describedAs("Create user button in Users Settings");
}
@@ -71,24 +72,72 @@ class UsersSettingsContext implements Context, ActorAwareInterface {
* @return Locator
*/
public static function rowForUser($user) {
- return Locator::forThe()->xpath("//table[@id = 'userlist']//td[normalize-space() = '$user']/..")->
+ return Locator::forThe()->xpath("//div[@id='app-content']/div/div[normalize-space() = '$user']/..")->
describedAs("Row for user $user in Users Settings");
}
/**
+ * Warning: you need to watch out for the proper classes order
+ *
+ * @return Locator
+ */
+ public static function classCellForUser($class, $user) {
+ return Locator::forThe()->xpath("//*[@class='$class']")->
+ descendantOf(self::rowForUser($user))->
+ describedAs("$class cell for user $user in Users Settings");
+ }
+
+ /**
+ * @return Locator
+ */
+ public static function inputForUserInCell($cell, $user) {
+ return Locator::forThe()->css("input")->
+ descendantOf(self::classCellForUser($cell, $user))->
+ describedAs("$cell input for user $user in Users Settings");
+ }
+
+ /**
+ * @return Locator
+ */
+ public static function optionInInputForUser($cell, $user) {
+ return Locator::forThe()->css(".multiselect__option--highlight")->
+ descendantOf(self::classCellForUser($cell, $user))->
+ describedAs("Selected $cell option in $cell input for user $user in Users Settings");
+ }
+
+ /**
+ * @return Locator
+ */
+ public static function actionsMenuOf($user) {
+ return Locator::forThe()->css(".icon-more")->
+ descendantOf(self::rowForUser($user))->
+ describedAs("Actions menu for user $user in Users Settings");
+ }
+
+ /**
+ * @return Locator
+ */
+ public static function theAction($action, $user) {
+ return Locator::forThe()->xpath("//button[normalize-space() = '$action']")->
+ descendantOf(self::rowForUser($user))->
+ describedAs("$action action for the user $user row in Users Settings");
+ }
+
+ /**
* @return Locator
*/
- public static function passwordCellForUser($user) {
- return Locator::forThe()->css(".password")->descendantOf(self::rowForUser($user))->
- describedAs("Password cell for user $user in Users Settings");
+ public static function theColumn($column) {
+ return Locator::forThe()->xpath("//div[@class='user-list-grid']//div[normalize-space() = '$column']")->
+ describedAs("The $column column in Users Settings");
}
/**
* @return Locator
*/
- public static function passwordInputForUser($user) {
- return Locator::forThe()->css("input")->descendantOf(self::passwordCellForUser($user))->
- describedAs("Password input for user $user in Users Settings");
+ public static function selectedSelectOption($cell, $user) {
+ return Locator::forThe()->css(".multiselect__single")->
+ descendantOf(self::classCellForUser($cell, $user))->
+ describedAs("The selected option of the $cell select for the user $user in Users Settings");
}
/**
@@ -99,6 +148,20 @@ class UsersSettingsContext implements Context, ActorAwareInterface {
}
/**
+ * @When I click the :action action in the :user actions menu
+ */
+ public function iClickTheAction($action, $user) {
+ $this->actor->find(self::theAction($action, $user))->click();
+ }
+
+ /**
+ * @When I open the actions menu for the user :user
+ */
+ public function iOpenTheActionsMenuOf($user) {
+ $this->actor->find(self::actionsMenuOf($user))->click();
+ }
+
+ /**
* @When I create user :user with password :password
*/
public function iCreateUserWithPassword($user, $password) {
@@ -108,18 +171,40 @@ class UsersSettingsContext implements Context, ActorAwareInterface {
}
/**
- * @When I set the password for :user to :password
+ * @When I set the :field for :user to :value
*/
- public function iSetThePasswordForUserTo($user, $password) {
- $this->actor->find(self::passwordCellForUser($user), 10)->click();
- $this->actor->find(self::passwordInputForUser($user), 2)->setValue($password . "\r");
+ public function iSetTheFieldForUserTo($field, $user, $value) {
+ $this->actor->find(self::inputForUserInCell($field, $user), 2)->setValue($value . "\r");
+ }
+
+ /**
+ * @When I assign the user :user to the group :group
+ */
+ public function iAssignTheUserToTheGroup($user, $group) {
+ $this->actor->find(self::inputForUserInCell('groups', $user))->setValue($group);
+ $this->actor->find(self::optionInInputForUser('groups', $user))->click();
+ }
+
+ /**
+ * @When I set the user :user quota to :quota
+ */
+ public function iSetTheUserQuotaTo($user, $quota) {
+ $this->actor->find(self::inputForUserInCell('quota', $user))->setValue($quota);
+ $this->actor->find(self::optionInInputForUser('quota', $user))->click();
}
/**
* @Then I see that the list of users contains the user :user
*/
public function iSeeThatTheListOfUsersContainsTheUser($user) {
- PHPUnit_Framework_Assert::assertNotNull($this->actor->find(self::rowForUser($user), 10));
+ WaitFor::elementToBeEventuallyShown($this->actor, self::rowForUser($user));
+ }
+
+ /**
+ * @Then I see that the list of users does not contains the user :user
+ */
+ public function iSeeThatTheListOfUsersDoesNotContainsTheUser($user) {
+ WaitFor::elementToBeEventuallyNotShown($this->actor, self::rowForUser($user));
}
/**
@@ -130,4 +215,45 @@ class UsersSettingsContext implements Context, ActorAwareInterface {
$this->actor->find(self::newUserForm(), 10)->isVisible());
}
+ /**
+ * @Then I see that the :action action in the :user actions menu is shown
+ */
+ public function iSeeTheAction($action, $user) {
+ PHPUnit_Framework_Assert::assertTrue(
+ $this->actor->find(self::theAction($action, $user), 10)->isVisible());
+ }
+
+ /**
+ * @Then I see that the :column column is shown
+ */
+ public function iSeeThatTheColumnIsShown($column) {
+ PHPUnit_Framework_Assert::assertTrue(
+ $this->actor->find(self::theColumn($column), 10)->isVisible());
+ }
+
+ /**
+ * @Then I see that the :field of :user is :value
+ */
+ public function iSeeThatTheFieldOfUserIs($field, $user, $value) {
+ PHPUnit_Framework_Assert::assertEquals(
+ $this->actor->find(self::inputForUserInCell($field, $user), 10)->getValue(), $value);
+ }
+
+ /**
+ * @Then I see that the :cell cell for user :user is done loading
+ */
+ public function iSeeThatTheCellForUserIsDoneLoading($cell, $user) {
+ WaitFor::elementToBeEventuallyShown($this->actor, self::classCellForUser($cell.' icon-loading-small', $user));
+ WaitFor::elementToBeEventuallyNotShown($this->actor, self::classCellForUser($cell.' icon-loading-small', $user));
+ }
+
+ /**
+ * @Then I see that the user quota of :user is :quota
+ */
+ public function iSeeThatTheuserQuotaIs($user, $quota) {
+ PHPUnit_Framework_Assert::assertEquals(
+ $this->actor->find(self::selectedSelectOption('quota', $user), 2)->getText(), $quota);
+ }
+
+
}
diff --git a/tests/acceptance/features/core/ElementWrapper.php b/tests/acceptance/features/core/ElementWrapper.php
index 7d7a86149ed..c866ea699fe 100644
--- a/tests/acceptance/features/core/ElementWrapper.php
+++ b/tests/acceptance/features/core/ElementWrapper.php
@@ -148,6 +148,18 @@ class ElementWrapper {
}
/**
+ * Returns whether the wrapped element is checked or not.
+ *
+ * @return bool true if the wrapped element is checked, false otherwise.
+ */
+ public function isChecked() {
+ $commandCallback = function() {
+ return $this->element->isChecked();
+ };
+ return $this->executeCommand($commandCallback, "check state could not be got");
+ }
+
+ /**
* Returns the text of the wrapped element.
*
* If the wrapped element is not visible the returned text is an empty
@@ -206,6 +218,32 @@ class ElementWrapper {
}
/**
+ * Check the wrapped element.
+ *
+ * If automatically waits for the wrapped element to be visible (up to the
+ * timeout set when finding it).
+ */
+ public function check() {
+ $commandCallback = function() {
+ $this->element->check();
+ };
+ $this->executeCommand($commandCallback, "could not be checked");
+ }
+
+ /**
+ * uncheck the wrapped element.
+ *
+ * If automatically waits for the wrapped element to be visible (up to the
+ * timeout set when finding it).
+ */
+ public function uncheck() {
+ $commandCallback = function() {
+ $this->element->uncheck();
+ };
+ $this->executeCommand($commandCallback, "could not be unchecked");
+ }
+
+ /**
* Executes the given command.
*
* If a StaleElementReference or a NoSuchElement exception is thrown the
diff --git a/tests/acceptance/features/login.feature b/tests/acceptance/features/login.feature
index 3db8c4945ec..3a31d3f88bd 100644
--- a/tests/acceptance/features/login.feature
+++ b/tests/acceptance/features/login.feature
@@ -18,7 +18,6 @@ Feature: login
And I am logged in as the admin
And I open the User settings
And I set the password for user0 to 654321
- And I see that the "Password successfully changed" notification is shown
And I act as John
And I log in with user user0 and password 654321
Then I see that the current page is the Files app
diff --git a/tests/acceptance/features/users.feature b/tests/acceptance/features/users.feature
new file mode 100644
index 00000000000..9bce32a2daa
--- /dev/null
+++ b/tests/acceptance/features/users.feature
@@ -0,0 +1,115 @@
+Feature: users
+
+ Scenario: create a new user
+ Given I act as Jane
+ And I am logged in as the admin
+ And I open the User settings
+ And I click the New user button
+ And I see that the new user form is shown
+ When I create user unknownUser with password 123456acb
+ Then I see that the list of users contains the user unknownUser
+
+ Scenario: delete a user
+ Given I act as Jane
+ And I am logged in as the admin
+ And I open the User settings
+ And I see that the list of users contains the user user0
+ And I open the actions menu for the user user0
+ And I see that the "Delete user" action in the user0 actions menu is shown
+ When I click the "Delete user" action in the user0 actions menu
+ Then I see that the list of users does not contains the user user0
+
+ Scenario: disable a user
+ Given I act as Jane
+ And I am logged in as the admin
+ And I open the User settings
+ And I see that the list of users contains the user user0
+ And I open the actions menu for the user user0
+ And I see that the "Disable user" action in the user0 actions menu is shown
+ When I click the "Disable user" action in the user0 actions menu
+ Then I see that the list of users does not contains the user user0
+ When I open the "Disabled users" section
+ Then I see that the list of users contains the user user0
+
+ Scenario: assign user to a group
+ Given I act as Jane
+ And I am logged in as the admin
+ And I open the User settings
+ And I see that the list of users contains the user user0
+ # disabled because we need the TAB patch:
+ # https://github.com/minkphp/MinkSelenium2Driver/pull/244
+ # When I assign the user user0 to the group admin
+ # Then I see that the section Admins is shown
+ # And I see that the section Admins has a count of 2
+
+ Scenario: create and delete a group
+ Given I act as Jane
+ And I am logged in as the admin
+ And I open the User settings
+ And I see that the list of users contains the user user0
+ # disabled because we need the TAB patch:
+ # https://github.com/minkphp/MinkSelenium2Driver/pull/244
+ # And I assign the user user0 to the group Group1
+ # And I see that the section Group1 is shown
+ # And I click the "icon-delete" button on the Group1 section
+ # And I see that the confirmation dialog is shown
+ # When I click the "Yes" button of the confirmation dialog
+ # Then I see that the section Group1 is not shown
+
+ Scenario: change columns visibility
+ Given I act as Jane
+ And I am logged in as the admin
+ And I open the User settings
+ And I open the settings
+ And I see that the settings are opened
+ When I toggle the showLanguages checkbox in the settings
+ Then I see that the "Languages" column is shown
+ When I toggle the showLastLogin checkbox in the settings
+ Then I see that the "Last login" column is shown
+ When I toggle the showStoragePath checkbox in the settings
+ Then I see that the "Storage location" column is shown
+ When I toggle the showUserBackend checkbox in the settings
+ Then I see that the "User backend" column is shown
+
+ Scenario: change display name
+ Given I act as Jane
+ And I am logged in as the admin
+ And I open the User settings
+ And I see that the list of users contains the user user0
+ And I see that the displayName of user0 is user0
+ When I set the displayName for user0 to user1
+ And I see that the displayName cell for user user0 is done loading
+ Then I see that the displayName of user0 is user1
+
+ Scenario: change password
+ Given I act as Jane
+ And I am logged in as the admin
+ And I open the User settings
+ And I see that the list of users contains the user user0
+ And I see that the password of user0 is ""
+ When I set the password for user0 to 123456
+ And I see that the password cell for user user0 is done loading
+ # password input is emptied on change
+ Then I see that the password of user0 is ""
+
+ Scenario: change email
+ Given I act as Jane
+ And I am logged in as the admin
+ And I open the User settings
+ And I see that the list of users contains the user user0
+ And I see that the mailAddress of user0 is ""
+ When I set the mailAddress for user0 to "test@nextcloud.com"
+ And I see that the mailAddress cell for user user0 is done loading
+ Then I see that the mailAddress of user0 is "test@nextcloud.com"
+
+ Scenario: change user quota
+ Given I act as Jane
+ And I am logged in as the admin
+ And I open the User settings
+ And I see that the list of users contains the user user0
+ And I see that the user quota of user0 is Unlimited
+ # disabled because we need the TAB patch:
+ # https://github.com/minkphp/MinkSelenium2Driver/pull/244
+ # When I set the user user0 quota to 1GB
+ # And I see that the quota cell for user user0 is done loading
+ # Then I see that the user quota of user0 is "1 GB" \ No newline at end of file