diff options
author | Lukas Reschke <lukas@owncloud.com> | 2016-04-18 12:14:07 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2016-04-18 21:21:52 +0200 |
commit | 8222ad515706d62cceb14428c959b83a69ccbc8b (patch) | |
tree | 1fb2a2a86d2eaebca7e48366a7b3e50d3f3dbe7f /tests | |
parent | 51975d360a93daba3b2681136a77b8d7078719e9 (diff) | |
download | nextcloud-server-8222ad515706d62cceb14428c959b83a69ccbc8b.tar.gz nextcloud-server-8222ad515706d62cceb14428c959b83a69ccbc8b.zip |
Move logout to controller
Testable code. Yay.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/controller/LoginControllerTest.php | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/tests/core/controller/LoginControllerTest.php b/tests/core/controller/LoginControllerTest.php index f0ffe57d7b4..f9a6080892b 100644 --- a/tests/core/controller/LoginControllerTest.php +++ b/tests/core/controller/LoginControllerTest.php @@ -26,6 +26,7 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IRequest; use OCP\ISession; +use OCP\IURLGenerator; use OCP\IUserManager; use OCP\IUserSession; use Test\TestCase; @@ -43,6 +44,8 @@ class LoginControllerTest extends TestCase { private $session; /** @var IUserSession */ private $userSession; + /** @var IURLGenerator */ + private $urlGenerator; public function setUp() { parent::setUp(); @@ -51,6 +54,7 @@ class LoginControllerTest extends TestCase { $this->config = $this->getMock('\\OCP\\IConfig'); $this->session = $this->getMock('\\OCP\\ISession'); $this->userSession = $this->getMock('\\OCP\\IUserSession'); + $this->urlGenerator = $this->getMock('\\OCP\\IURLGenerator'); $this->loginController = new LoginController( 'core', @@ -58,10 +62,59 @@ class LoginControllerTest extends TestCase { $this->userManager, $this->config, $this->session, - $this->userSession + $this->userSession, + $this->urlGenerator ); } + public function testLogoutWithoutToken() { + $this->request + ->expects($this->once()) + ->method('getCookie') + ->with('oc_token') + ->willReturn(null); + $this->config + ->expects($this->never()) + ->method('deleteUserValue'); + $this->urlGenerator + ->expects($this->once()) + ->method('linkToRouteAbsolute') + ->with('core.login.showLoginForm') + ->willReturn('/login'); + + $expected = new RedirectResponse('/login'); + $this->assertEquals($expected, $this->loginController->logout()); + } + + public function testLogoutWithToken() { + $this->request + ->expects($this->once()) + ->method('getCookie') + ->with('oc_token') + ->willReturn('MyLoginToken'); + $user = $this->getMock('\\OCP\\IUser'); + $user + ->expects($this->once()) + ->method('getUID') + ->willReturn('JohnDoe'); + $this->userSession + ->expects($this->once()) + ->method('getUser') + ->willReturn($user); + $this->config + ->expects($this->once()) + ->method('deleteUserValue') + ->with('JohnDoe', 'login_token', 'MyLoginToken'); + $this->urlGenerator + ->expects($this->once()) + ->method('linkToRouteAbsolute') + ->with('core.login.showLoginForm') + ->willReturn('/login'); + + $expected = new RedirectResponse('/login'); + $this->assertEquals($expected, $this->loginController->logout()); + } + public function testShowLoginFormForLoggedInUsers() { $this->userSession ->expects($this->once()) |