diff options
author | Lukas Reschke <lukas@owncloud.com> | 2014-12-09 18:36:40 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2014-12-10 12:07:34 +0100 |
commit | 5dc6406b7075a6f1db3ada7a9d0f5ddc93f58b18 (patch) | |
tree | 87221af31e42aaa9031672706752309b1ccc37db /tests | |
parent | 5398bbdc003a93f8652b7c7a88bc80e7710996c9 (diff) | |
download | nextcloud-server-5dc6406b7075a6f1db3ada7a9d0f5ddc93f58b18.tar.gz nextcloud-server-5dc6406b7075a6f1db3ada7a9d0f5ddc93f58b18.zip |
Add filter for 'backend' to user REST route
This adds a "backend" type filter to the index REST route which is a pre-requisite for https://github.com/owncloud/core/issues/12620
For example when calling `index.php/settings/users/users?offset=0&limit=10&gid=&pattern=&backend=OC_User_Database` only users within the backend `OC_User_Database` would be shown. (requires sending a CSRF token as well)
Depends upon https://github.com/owncloud/core/pull/12711
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/user/manager.php | 11 | ||||
-rw-r--r-- | tests/settings/controller/userscontrollertest.php | 56 |
2 files changed, 67 insertions, 0 deletions
diff --git a/tests/lib/user/manager.php b/tests/lib/user/manager.php index c825ec05775..9cb9374d89f 100644 --- a/tests/lib/user/manager.php +++ b/tests/lib/user/manager.php @@ -10,6 +10,17 @@ namespace Test\User; class Manager extends \Test\TestCase { + public function testGetBackends() { + $userDummyBackend = $this->getMock('\OC_User_Dummy'); + $manager = new \OC\User\Manager(); + $manager->registerBackend($userDummyBackend); + $this->assertEquals([$userDummyBackend], $manager->getBackends()); + $dummyDatabaseBackend = $this->getMock('\OC_User_Database'); + $manager->registerBackend($dummyDatabaseBackend); + $this->assertEquals([$userDummyBackend, $dummyDatabaseBackend], $manager->getBackends()); + } + + public function testUserExistsSingleBackendExists() { /** * @var \OC_User_Dummy | \PHPUnit_Framework_MockObject_MockObject $backend diff --git a/tests/settings/controller/userscontrollertest.php b/tests/settings/controller/userscontrollertest.php index eb48babadc8..42d91c7731a 100644 --- a/tests/settings/controller/userscontrollertest.php +++ b/tests/settings/controller/userscontrollertest.php @@ -172,6 +172,62 @@ class UsersControllerTest extends \Test\TestCase { $this->assertEquals($expectedResponse, $response); } + public function testIndexWithBackend() { + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $user + ->expects($this->exactly(3)) + ->method('getUID') + ->will($this->returnValue('foo')); + $user + ->expects($this->once()) + ->method('getDisplayName') + ->will($this->returnValue('M. Foo')); + $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')); + $this->container['UserManager'] + ->expects($this->once()) + ->method('getBackends') + ->will($this->returnValue([new \OC_User_Dummy(), new \OC_User_Database()])); + $this->container['UserManager'] + ->expects($this->once()) + ->method('clearBackends'); + $this->container['UserManager'] + ->expects($this->once()) + ->method('registerBackend') + ->with(new \OC_User_Dummy()); + $this->container['UserManager'] + ->expects($this->once()) + ->method('search') + ->with('') + ->will($this->returnValue([$user])); + + $expectedResponse = new DataResponse( + array( + 0 => array( + 'name' => 'foo', + 'displayname' => 'M. Foo', + 'groups' => null, + 'subadmin' => array(), + 'quota' => null, + 'storageLocation' => '/home/foo', + 'lastLogin' => 500, + 'backend' => 'OC_User_Database' + ) + ) + ); + $response = $this->usersController->index(0, 10, '','', 'OC_User_Dummy'); + $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... |