diff options
author | icewind1991 <icewind1991@gmail.com> | 2013-05-28 13:37:39 -0700 |
---|---|---|
committer | icewind1991 <icewind1991@gmail.com> | 2013-05-28 13:37:39 -0700 |
commit | fee43ec506ee423f67ddae0a9ef29a3135b99ab6 (patch) | |
tree | e33dd76c10f0002f2e8d41c5c35827e9804d6f7c /tests | |
parent | 1d720099c328fe3084e05fe3d2bdd9e49acb8dfe (diff) | |
parent | fa6bfe8837c5f22e724df97c7049d60c1bb904ff (diff) | |
download | nextcloud-server-fee43ec506ee423f67ddae0a9ef29a3135b99ab6.tar.gz nextcloud-server-fee43ec506ee423f67ddae0a9ef29a3135b99ab6.zip |
Merge pull request #3511 from owncloud/sessionclass
Abstract session access away in a class
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/session/memory.php | 16 | ||||
-rw-r--r-- | tests/lib/session/session.php | 64 | ||||
-rw-r--r-- | tests/lib/user/backend.php | 99 | ||||
-rw-r--r-- | tests/lib/user/database.php | 44 | ||||
-rw-r--r-- | tests/lib/user/dummy.php | 27 |
5 files changed, 80 insertions, 170 deletions
diff --git a/tests/lib/session/memory.php b/tests/lib/session/memory.php new file mode 100644 index 00000000000..2dc236b73bf --- /dev/null +++ b/tests/lib/session/memory.php @@ -0,0 +1,16 @@ +<?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\Session; + +class Memory extends Session { + public function setUp() { + $this->instance = new \OC\Session\Memory(uniqid()); + } +} diff --git a/tests/lib/session/session.php b/tests/lib/session/session.php new file mode 100644 index 00000000000..72dee44e7cb --- /dev/null +++ b/tests/lib/session/session.php @@ -0,0 +1,64 @@ +<?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\Session; + +abstract class Session extends \PHPUnit_Framework_TestCase { + /** + * @var \OC\Session\Session + */ + protected $instance; + + public function tearDown() { + $this->instance->clear(); + } + + public function testNotExistsEmpty() { + $this->assertFalse($this->instance->exists('foo')); + } + + public function testExistsAfterSet() { + $this->instance->set('foo', 1); + $this->assertTrue($this->instance->exists('foo')); + } + + public function testNotExistsAfterRemove() { + $this->instance->set('foo', 1); + $this->instance->remove('foo'); + $this->assertFalse($this->instance->exists('foo')); + } + + public function testGetNonExisting() { + $this->assertNull($this->instance->get('foo')); + } + + public function testGetAfterSet() { + $this->instance->set('foo', 'bar'); + $this->assertEquals('bar', $this->instance->get(('foo'))); + } + + public function testRemoveNonExisting() { + $this->instance->remove('foo'); + } + + public function testNotExistsAfterClear() { + $this->instance->set('foo', 1); + $this->instance->clear(); + $this->assertFalse($this->instance->exists('foo')); + } + + public function testArrayInterface() { + $this->assertFalse(isset($this->instance['foo'])); + $this->instance['foo'] = 'bar'; + $this->assertTrue(isset($this->instance['foo'])); + $this->assertEquals('bar', $this->instance['foo']); + unset($this->instance['foo']); + $this->assertFalse(isset($this->instance['foo'])); + } +} diff --git a/tests/lib/user/backend.php b/tests/lib/user/backend.php deleted file mode 100644 index 40674424c96..00000000000 --- a/tests/lib/user/backend.php +++ /dev/null @@ -1,99 +0,0 @@ -<?php -/** -* ownCloud -* -* @author Robin Appelman -* @copyright 2012 Robin Appelman icewind@owncloud.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -/** - * Abstract class to provide the basis of backend-specific unit test classes. - * - * All subclasses MUST assign a backend property in setUp() which implements - * user operations (add, remove, etc.). Test methods in this class will then be - * run on each separate subclass and backend therein. - * - * For an example see /tests/lib/user/dummy.php - */ - -abstract class Test_User_Backend extends PHPUnit_Framework_TestCase { - /** - * @var OC_User_Backend $backend - */ - protected $backend; - - /** - * get a new unique user name - * test cases can override this in order to clean up created user - * @return array - */ - public function getUser() { - return uniqid('test_'); - } - - public function testAddRemove() { - //get the number of groups we start with, in case there are exising groups - $startCount=count($this->backend->getUsers()); - - $name1=$this->getUser(); - $name2=$this->getUser(); - $this->backend->createUser($name1, ''); - $count=count($this->backend->getUsers())-$startCount; - $this->assertEquals(1, $count); - $this->assertTrue((array_search($name1, $this->backend->getUsers())!==false)); - $this->assertFalse((array_search($name2, $this->backend->getUsers())!==false)); - $this->backend->createUser($name2, ''); - $count=count($this->backend->getUsers())-$startCount; - $this->assertEquals(2, $count); - $this->assertTrue((array_search($name1, $this->backend->getUsers())!==false)); - $this->assertTrue((array_search($name2, $this->backend->getUsers())!==false)); - - $this->backend->deleteUser($name2); - $count=count($this->backend->getUsers())-$startCount; - $this->assertEquals(1, $count); - $this->assertTrue((array_search($name1, $this->backend->getUsers())!==false)); - $this->assertFalse((array_search($name2, $this->backend->getUsers())!==false)); - } - - public function testLogin() { - $name1=$this->getUser(); - $name2=$this->getUser(); - - $this->assertFalse($this->backend->userExists($name1)); - $this->assertFalse($this->backend->userExists($name2)); - - $this->backend->createUser($name1, 'pass1'); - $this->backend->createUser($name2, 'pass2'); - - $this->assertTrue($this->backend->userExists($name1)); - $this->assertTrue($this->backend->userExists($name2)); - - $this->assertTrue($this->backend->checkPassword($name1, 'pass1')); - $this->assertTrue($this->backend->checkPassword($name2, 'pass2')); - - $this->assertFalse($this->backend->checkPassword($name1, 'pass2')); - $this->assertFalse($this->backend->checkPassword($name2, 'pass1')); - - $this->assertFalse($this->backend->checkPassword($name1, 'dummy')); - $this->assertFalse($this->backend->checkPassword($name2, 'foobar')); - - $this->backend->setPassword($name1, 'newpass1'); - $this->assertFalse($this->backend->checkPassword($name1, 'pass1')); - $this->assertTrue($this->backend->checkPassword($name1, 'newpass1')); - $this->assertFalse($this->backend->checkPassword($name2, 'newpass1')); - } -} diff --git a/tests/lib/user/database.php b/tests/lib/user/database.php deleted file mode 100644 index fe7d87c44de..00000000000 --- a/tests/lib/user/database.php +++ /dev/null @@ -1,44 +0,0 @@ -<?php -/** -* ownCloud -* -* @author Robin Appelman -* @copyright 2012 Robin Appelman icewind@owncloud.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -class Test_User_Database extends Test_User_Backend { - /** - * get a new unique user name - * test cases can override this in order to clean up created user - * @return array - */ - public function getUser() { - $user=uniqid('test_'); - $this->users[]=$user; - return $user; - } - - public function setUp() { - $this->backend=new OC_User_Dummy(); - } - - public function tearDown() { - foreach($this->users as $user) { - $this->backend->deleteUser($user); - } - } -} diff --git a/tests/lib/user/dummy.php b/tests/lib/user/dummy.php deleted file mode 100644 index e417fd97603..00000000000 --- a/tests/lib/user/dummy.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php -/** -* ownCloud -* -* @author Robin Appelman -* @copyright 2012 Robin Appelman icewind@owncloud.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -class Test_User_Dummy extends Test_User_Backend { - public function setUp() { - $this->backend=new OC_User_Dummy(); - } -} |