diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/strängé filename (duplicate #2).txt | 4 | ||||
-rw-r--r-- | tests/lib/largefilehelpergetfilesize.php | 4 | ||||
-rw-r--r-- | tests/lib/user/session.php | 96 |
3 files changed, 69 insertions, 35 deletions
diff --git a/tests/data/strängé filename (duplicate #2).txt b/tests/data/strängé filename (duplicate #2).txt new file mode 100644 index 00000000000..b62c3fb2ffd --- /dev/null +++ b/tests/data/strängé filename (duplicate #2).txt @@ -0,0 +1,4 @@ +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. +Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\ No newline at end of file diff --git a/tests/lib/largefilehelpergetfilesize.php b/tests/lib/largefilehelpergetfilesize.php index 21a0aa9a233..58571d641e0 100644 --- a/tests/lib/largefilehelpergetfilesize.php +++ b/tests/lib/largefilehelpergetfilesize.php @@ -20,8 +20,8 @@ class LargeFileHelperGetFileSize extends \PHPUnit_Framework_TestCase { public function setUp() { parent::setUp(); $ds = DIRECTORY_SEPARATOR; - $this->filename = dirname(__DIR__) . "{$ds}data{$ds}data.tar.gz"; - $this->fileSize = 4195; + $this->filename = dirname(__DIR__) . "{$ds}data{$ds}strängé filename (duplicate #2).txt"; + $this->fileSize = 446; $this->helper = new \OC\LargeFileHelper; } diff --git a/tests/lib/user/session.php b/tests/lib/user/session.php index 2845a9c964a..5126049d77f 100644 --- a/tests/lib/user/session.php +++ b/tests/lib/user/session.php @@ -9,6 +9,9 @@ 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('')); @@ -54,26 +57,26 @@ class Session extends \PHPUnit_Framework_TestCase { $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]); } } @@ -110,9 +113,9 @@ class Session extends \PHPUnit_Framework_TestCase { //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]); } } @@ -145,9 +148,9 @@ class Session extends \PHPUnit_Framework_TestCase { //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]); } } @@ -192,23 +195,23 @@ class Session extends \PHPUnit_Framework_TestCase { $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]); } } @@ -254,9 +257,9 @@ class Session extends \PHPUnit_Framework_TestCase { //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]); } } @@ -296,9 +299,9 @@ class Session extends \PHPUnit_Framework_TestCase { //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]); } } @@ -327,4 +330,31 @@ class Session extends \PHPUnit_Framework_TestCase { $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()); + } } |