summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/user/manager.php11
-rw-r--r--tests/settings/controller/userscontrollertest.php56
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...