summaryrefslogtreecommitdiffstats
path: root/tests/Settings
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2016-09-14 15:05:10 +0200
committerMorris Jobke <hey@morrisjobke.de>2017-04-29 00:59:09 -0300
commite521b6799fac5e4765c4e0a7fdf0d182f4dc015d (patch)
tree107fac0c03edcc993f7668447f923b2a2a3c34bf /tests/Settings
parent79d74a1425e6765a30469422a9b9ff218c8e2ef2 (diff)
downloadnextcloud-server-e521b6799fac5e4765c4e0a7fdf0d182f4dc015d.tar.gz
nextcloud-server-e521b6799fac5e4765c4e0a7fdf0d182f4dc015d.zip
add unit tests for disable method
Diffstat (limited to 'tests/Settings')
-rw-r--r--tests/Settings/Controller/UsersControllerTest.php220
1 files changed, 219 insertions, 1 deletions
diff --git a/tests/Settings/Controller/UsersControllerTest.php b/tests/Settings/Controller/UsersControllerTest.php
index 14f43a9e8e3..986f15e7a32 100644
--- a/tests/Settings/Controller/UsersControllerTest.php
+++ b/tests/Settings/Controller/UsersControllerTest.php
@@ -2438,7 +2438,225 @@ class UsersControllerTest extends \Test\TestCase {
$this->userSession->expects($this->once())->method('getUser')->willReturn(null);
$result = $controller->getVerificationCode('account', false);
- $this->assertSame(Http::STATUS_BAD_REQUEST ,$result->getStatus());
+ $this->assertSame(Http::STATUS_BAD_REQUEST, $result->getStatus());
+ }
+
+ public function testDisableUserFailsDueSameUser() {
+ $user = $this->getMockBuilder('\OC\User\User')
+ ->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' => 'Unable to disable user.',
+ ],
+ ],
+ Http::STATUS_FORBIDDEN
+ );
+ $controller = $this->getController(true);
+ $response = $controller->disable('abc');
+ $this->assertEquals($expectedResponse, $response);
+ }
+
+ public function testDisableUserFailsDueNoAdminAndNoSubadmin() {
+ $user = $this->getMockBuilder('\OC\User\User')
+ ->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('\OC\User\User')
+ ->disableOriginalConstructor()->getMock();
+ $user2->expects($this->never())
+ ->method('setEnabled');
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('abc')
+ ->willReturn($user2);
+
+ $subadmin = $this->createMock('\OC\SubAdmin');
+ $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
+ );
+ $controller = $this->getController(false);
+ $response = $controller->disable('abc');
+ $this->assertEquals($expectedResponse, $response);
+ }
+
+ public function testDisableUserFailsDueNoUser() {
+ $user = $this->getMockBuilder('\OC\User\User')
+ ->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' => 'Unable to disable user.',
+ ],
+ ]
+ );
+ $controller = $this->getController(true);
+ $response = $controller->disable('abc');
+ $this->assertEquals($expectedResponse, $response);
+ }
+
+ public function testDisableUserFailsDueNoUserForSubAdmin() {
+ $user = $this->getMockBuilder('\OC\User\User')
+ ->disableOriginalConstructor()->getMock();
+ $user->expects($this->once())
+ ->method('getUID')
+ ->will($this->returnValue('def'));
+ $this->userSession
+ ->expects($this->exactly(2))
+ ->method('getUser')
+ ->will($this->returnValue($user));
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('abc')
+ ->willReturn(null);
+
+ $subadmin = $this->createMock('\OC\SubAdmin');
+ $subadmin->expects($this->once())
+ ->method('isUserAccessible')
+ ->will($this->returnValue(true));
+ $this->groupManager
+ ->expects($this->once())
+ ->method('getSubAdmin')
+ ->willReturn($subadmin);
+
+ $expectedResponse = new DataResponse(
+ [
+ 'status' => 'error',
+ 'data' => [
+ 'message' => 'Unable to disable user.',
+ ],
+ ]
+ );
+ $controller = $this->getController(false);
+ $response = $controller->disable('abc');
+ $this->assertEquals($expectedResponse, $response);
+ }
+
+ public function testDisableUserSuccessForAdmin() {
+ $user = $this->getMockBuilder('\OC\User\User')
+ ->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('\OC\User\User')
+ ->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' => 0,
+ ],
+ ]
+ );
+ $controller = $this->getController(true);
+ $response = $controller->disable('abc');
+ $this->assertEquals($expectedResponse, $response);
+ }
+
+ public function testDisableUserSuccessForSubAdmin() {
+ $user = $this->getMockBuilder('\OC\User\User')
+ ->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('\OC\User\User')
+ ->disableOriginalConstructor()->getMock();
+ $user2->expects($this->once())
+ ->method('setEnabled');
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('abc')
+ ->willReturn($user2);
+
+ $subadmin = $this->createMock('\OC\SubAdmin');
+ $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,
+ ],
+ ]
+ );
+ $controller = $this->getController(false);
+ $response = $controller->disable('abc');
+ $this->assertEquals($expectedResponse, $response);
}
}
an> "Error moving file" : "Грешка при префрлање на датотека", "Error" : "Грешка", "{new_name} already exists" : "{new_name} веќе постои", "Could not rename file" : "Не можам да ја преименувам датотеката", "Could not create file" : "Не множам да креирам датотека", "Could not create folder" : "Не можам да креирам папка", "Name" : "Име", "Size" : "Големина", "Modified" : "Променето", "{dirs} and {files}" : "{dirs} и {files}", "New" : "Ново", "File name cannot be empty." : "Името на датотеката не може да биде празно.", "Your storage is full, files can not be updated or synced anymore!" : "Вашиот сториџ е полн, датотеките веќе не можат да се освежуваат или синхронизираат!", "Your storage is almost full ({usedSpacePercent}%)" : "Вашиот сториџ е скоро полн ({usedSpacePercent}%)", "Upload" : "Подигни", "Text file" : "Текстуална датотека", "Folder" : "Папка", "New folder" : "Нова папка", "You created %1$s" : "Вие креиравте %1$s", "%2$s created %1$s" : "%2$s креирано %1$s", "You changed %1$s" : "Вие изменивте %1$s", "%2$s changed %1$s" : "%2$s променето %1$s", "You deleted %1$s" : "Вие избришавте %1$s", "%2$s deleted %1$s" : "%2$s избришани %1$s", "%s could not be renamed" : "%s не може да биде преименуван", "Upload (max. %s)" : "Префрлање (макс. %s)", "File handling" : "Ракување со датотеки", "Maximum upload size" : "Максимална големина за подигање", "max. possible: " : "макс. можно:", "Save" : "Сними", "Settings" : "Подесувања", "WebDAV" : "WebDAV", "Cancel upload" : "Откажи прикачување", "Upload too large" : "Фајлот кој се вчитува е преголем", "The files you are trying to upload exceed the maximum size for file uploads on this server." : "Датотеките кои се обидувате да ги подигнете ја надминуваат максималната големина за подигнување датотеки на овој сервер.", "Files are being scanned, please wait." : "Се скенираат датотеки, ве молам почекајте." }, "nplurals=2; plural=(n % 10 == 1 && n % 100 != 11) ? 0 : 1;");