namespace Test\User;
+use OC\Session\Memory;
+use OC\User\User;
+
class Session extends \PHPUnit_Framework_TestCase {
public function testGetUser() {
$session = $this->getMock('\OC\Session\Memory', array(), array(''));
$session = $this->getMock('\OC\Session\Memory', array(), array(''));
$session->expects($this->exactly(2))
->method('set')
- ->with($this->callback(function($key) {
- switch($key) {
- case 'user_id':
- case 'loginname':
- return true;
- break;
- default:
- return false;
- break;
- }
- },
- 'foo'));
+ ->with($this->callback(function ($key) {
+ switch ($key) {
+ case 'user_id':
+ case 'loginname':
+ return true;
+ break;
+ default:
+ return false;
+ break;
+ }
+ },
+ 'foo'));
$managerMethods = get_class_methods('\OC\User\Manager');
//keep following methods intact in order to ensure hooks are
//working
$doNotMock = array('__construct', 'emit', 'listen');
- foreach($doNotMock as $methodName) {
+ foreach ($doNotMock as $methodName) {
$i = array_search($methodName, $managerMethods, true);
- if($i !== false) {
+ if ($i !== false) {
unset($managerMethods[$i]);
}
}
//keep following methods intact in order to ensure hooks are
//working
$doNotMock = array('__construct', 'emit', 'listen');
- foreach($doNotMock as $methodName) {
+ foreach ($doNotMock as $methodName) {
$i = array_search($methodName, $managerMethods, true);
- if($i !== false) {
+ if ($i !== false) {
unset($managerMethods[$i]);
}
}
//keep following methods intact in order to ensure hooks are
//working
$doNotMock = array('__construct', 'emit', 'listen');
- foreach($doNotMock as $methodName) {
+ foreach ($doNotMock as $methodName) {
$i = array_search($methodName, $managerMethods, true);
- if($i !== false) {
+ if ($i !== false) {
unset($managerMethods[$i]);
}
}
$session = $this->getMock('\OC\Session\Memory', array(), array(''));
$session->expects($this->exactly(1))
->method('set')
- ->with($this->callback(function($key) {
- switch($key) {
- case 'user_id':
- return true;
- default:
- return false;
- }
- },
- 'foo'));
+ ->with($this->callback(function ($key) {
+ switch ($key) {
+ case 'user_id':
+ return true;
+ default:
+ return false;
+ }
+ },
+ 'foo'));
$managerMethods = get_class_methods('\OC\User\Manager');
//keep following methods intact in order to ensure hooks are
//working
$doNotMock = array('__construct', 'emit', 'listen');
- foreach($doNotMock as $methodName) {
+ foreach ($doNotMock as $methodName) {
$i = array_search($methodName, $managerMethods, true);
- if($i !== false) {
+ if ($i !== false) {
unset($managerMethods[$i]);
}
}
//keep following methods intact in order to ensure hooks are
//working
$doNotMock = array('__construct', 'emit', 'listen');
- foreach($doNotMock as $methodName) {
+ foreach ($doNotMock as $methodName) {
$i = array_search($methodName, $managerMethods, true);
- if($i !== false) {
+ if ($i !== false) {
unset($managerMethods[$i]);
}
}
//keep following methods intact in order to ensure hooks are
//working
$doNotMock = array('__construct', 'emit', 'listen');
- foreach($doNotMock as $methodName) {
+ foreach ($doNotMock as $methodName) {
$i = array_search($methodName, $managerMethods, true);
- if($i !== false) {
+ if ($i !== false) {
unset($managerMethods[$i]);
}
}
$this->assertSame($granted, false);
}
+
+ public function testActiveUserAfterSetSession() {
+ $users = array(
+ 'foo' => new User('foo', null),
+ 'bar' => new User('bar', null)
+ );
+
+ $manager = $this->getMockBuilder('\OC\User\Manager')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $manager->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(function ($uid) use ($users) {
+ return $users[$uid];
+ }));
+
+ $session = new Memory('');
+ $session->set('user_id', 'foo');
+ $userSession = new \OC\User\Session($manager, $session);
+ $this->assertEquals($users['foo'], $userSession->getUser());
+
+ $session2 = new Memory('');
+ $session2->set('user_id', 'bar');
+ $userSession->setSession($session2);
+ $this->assertEquals($users['bar'], $userSession->getUser());
+ }
}