summaryrefslogtreecommitdiffstats
path: root/tests/Core
diff options
context:
space:
mode:
authorMichael Weimann <mail@michael-weimann.eu>2018-07-21 13:05:25 +0200
committerMichael Weimann <mail@michael-weimann.eu>2018-07-21 13:05:25 +0200
commitde7606dc6802a026f8ce33115c2f51a304aabc61 (patch)
tree1ea0a762b7765a113209748556666d293abcc815 /tests/Core
parentc92d7429d7ff9a76a6dd62607e55ef680a43a679 (diff)
downloadnextcloud-server-de7606dc6802a026f8ce33115c2f51a304aabc61.tar.gz
nextcloud-server-de7606dc6802a026f8ce33115c2f51a304aabc61.zip
Adds disabled user unit tests
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
Diffstat (limited to 'tests/Core')
-rw-r--r--tests/Core/Controller/LoginControllerTest.php50
1 files changed, 47 insertions, 3 deletions
diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php
index 1e26d86a039..7ebd6ee8340 100644
--- a/tests/Core/Controller/LoginControllerTest.php
+++ b/tests/Core/Controller/LoginControllerTest.php
@@ -286,7 +286,52 @@ class LoginControllerTest extends TestCase {
$this->assertEquals($expectedResponse, $this->loginController->showLoginForm('LdapUser', '', ''));
}
- public function testShowLoginFormForUserNamedNull() {
+ /**
+ * Asserts that a disabled user can't login and gets the expected response.
+ */
+ public function testLoginForDisabledUser() {
+ /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
+ $user = $this->createMock(IUser::class);
+ $user->method('getUID')
+ ->willReturn('uid');
+ $user->method('isEnabled')
+ ->willReturn(false);
+
+ $this->request
+ ->expects($this->once())
+ ->method('passesCSRFCheck')
+ ->willReturn(true);
+
+ $this->userSession
+ ->method('isLoggedIn')
+ ->willReturn(false);
+
+ $loginName = 'iMDisabled';
+ $password = 'secret';
+
+ $this->session
+ ->expects($this->once())
+ ->method('set')
+ ->with('loginMessages', [
+ [LoginController::LOGIN_MSG_USERDISABLED], []
+ ]);
+
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with($loginName)
+ ->willReturn($user);
+
+ $expected = new RedirectResponse('');
+ $expected->throttle(['user' => $loginName]);
+
+ $response = $this->loginController->tryLogin(
+ $loginName, $password, null, false, 'Europe/Berlin', '1'
+ );
+ $this->assertEquals($expected, $response);
+ }
+
+ public function testShowLoginFormForUserNamed0() {
$this->userSession
->expects($this->once())
->method('isLoggedIn')
@@ -297,8 +342,7 @@ class LoginControllerTest extends TestCase {
->with('lost_password_link')
->willReturn(false);
$user = $this->createMock(IUser::class);
- $user
- ->expects($this->once())
+ $user->expects($this->once())
->method('canChangePassword')
->willReturn(false);
$this->userManager