summaryrefslogtreecommitdiffstats
path: root/tests/lib/user/session.php
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2013-05-28 23:46:57 +0200
committerRobin Appelman <icewind@owncloud.com>2013-05-29 00:31:55 +0200
commit955bda1842986a6737c8d3b575b0cd3bb5a0e17d (patch)
tree23713e8a21ea4c50574a8610b6262ef92fa9a9cb /tests/lib/user/session.php
parentfee43ec506ee423f67ddae0a9ef29a3135b99ab6 (diff)
downloadnextcloud-server-955bda1842986a6737c8d3b575b0cd3bb5a0e17d.tar.gz
nextcloud-server-955bda1842986a6737c8d3b575b0cd3bb5a0e17d.zip
New user management classes
Diffstat (limited to 'tests/lib/user/session.php')
-rw-r--r--tests/lib/user/session.php155
1 files changed, 155 insertions, 0 deletions
diff --git a/tests/lib/user/session.php b/tests/lib/user/session.php
new file mode 100644
index 00000000000..274e9e2831e
--- /dev/null
+++ b/tests/lib/user/session.php
@@ -0,0 +1,155 @@
+<?php
+
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\User;
+
+class Session extends \PHPUnit_Framework_TestCase {
+ public function testGetUser() {
+ $session = $this->getMock('\OC\Session\Memory', array(), array(''));
+ $session->expects($this->once())
+ ->method('get')
+ ->with('user_id')
+ ->will($this->returnValue('foo'));
+
+ $backend = $this->getMock('OC_User_Dummy');
+ $backend->expects($this->once())
+ ->method('userExists')
+ ->with('foo')
+ ->will($this->returnValue(true));
+
+ $manager = new \OC\User\Manager();
+ $manager->registerBackend($backend);
+
+ $userSession = new \OC\User\Session($manager, $session);
+ $user = $userSession->getUser();
+ $this->assertEquals('foo', $user->getUID());
+ }
+
+ public function testSetUser() {
+ $session = $this->getMock('\OC\Session\Memory', array(), array(''));
+ $session->expects($this->once())
+ ->method('set')
+ ->with('user_id', 'foo');
+
+ $manager = $this->getMock('\OC\User\Manager');
+
+ $backend = $this->getMock('OC_User_Dummy');
+
+ $user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
+ $user->expects($this->once())
+ ->method('getUID')
+ ->will($this->returnValue('foo'));
+
+ $userSession = new \OC\User\Session($manager, $session);
+ $userSession->setUser($user);
+ }
+
+ public function testLoginValidPasswordEnabled() {
+ $session = $this->getMock('\OC\Session\Memory', array(), array(''));
+ $session->expects($this->once())
+ ->method('set')
+ ->with('user_id', 'foo');
+
+ $manager = $this->getMock('\OC\User\Manager');
+
+ $backend = $this->getMock('OC_User_Dummy');
+
+ $user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
+ $user->expects($this->once())
+ ->method('checkPassword')
+ ->with('bar')
+ ->will($this->returnValue(true));
+ $user->expects($this->once())
+ ->method('isEnabled')
+ ->will($this->returnValue(true));
+ $user->expects($this->any())
+ ->method('getUID')
+ ->will($this->returnValue('foo'));
+
+ $manager->expects($this->once())
+ ->method('get')
+ ->with('foo')
+ ->will($this->returnValue($user));
+
+ $userSession = new \OC\User\Session($manager, $session);
+ $userSession->login('foo', 'bar');
+ $this->assertEquals($user, $userSession->getUser());
+ }
+
+ public function testLoginValidPasswordDisabled() {
+ $session = $this->getMock('\OC\Session\Memory', array(), array(''));
+ $session->expects($this->never())
+ ->method('set');
+
+ $manager = $this->getMock('\OC\User\Manager');
+
+ $backend = $this->getMock('OC_User_Dummy');
+
+ $user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
+ $user->expects($this->once())
+ ->method('checkPassword')
+ ->with('bar')
+ ->will($this->returnValue(true));
+ $user->expects($this->once())
+ ->method('isEnabled')
+ ->will($this->returnValue(false));
+
+ $manager->expects($this->once())
+ ->method('get')
+ ->with('foo')
+ ->will($this->returnValue($user));
+
+ $userSession = new \OC\User\Session($manager, $session);
+ $userSession->login('foo', 'bar');
+ }
+
+ public function testLoginInValidPassword() {
+ $session = $this->getMock('\OC\Session\Memory', array(), array(''));
+ $session->expects($this->never())
+ ->method('set');
+
+ $manager = $this->getMock('\OC\User\Manager');
+
+ $backend = $this->getMock('OC_User_Dummy');
+
+ $user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
+ $user->expects($this->once())
+ ->method('checkPassword')
+ ->with('bar')
+ ->will($this->returnValue(false));
+ $user->expects($this->never())
+ ->method('isEnabled');
+
+ $manager->expects($this->once())
+ ->method('get')
+ ->with('foo')
+ ->will($this->returnValue($user));
+
+ $userSession = new \OC\User\Session($manager, $session);
+ $userSession->login('foo', 'bar');
+ }
+
+ public function testLoginNonExisting() {
+ $session = $this->getMock('\OC\Session\Memory', array(), array(''));
+ $session->expects($this->never())
+ ->method('set');
+
+ $manager = $this->getMock('\OC\User\Manager');
+
+ $backend = $this->getMock('OC_User_Dummy');
+
+ $manager->expects($this->once())
+ ->method('get')
+ ->with('foo')
+ ->will($this->returnValue(null));
+
+ $userSession = new \OC\User\Session($manager, $session);
+ $userSession->login('foo', 'bar');
+ }
+}