diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/filestorage/local.php | 5 | ||||
-rw-r--r-- | tests/lib/filesystem.php | 64 | ||||
-rw-r--r-- | tests/lib/group.php | 114 | ||||
-rw-r--r-- | tests/lib/group/backend.php | 105 | ||||
-rw-r--r-- | tests/lib/group/database.php | 55 | ||||
-rw-r--r-- | tests/lib/group/dummy.php | 27 |
6 files changed, 366 insertions, 4 deletions
diff --git a/tests/lib/filestorage/local.php b/tests/lib/filestorage/local.php index 0a2d46c5ebc..692f05f9fca 100644 --- a/tests/lib/filestorage/local.php +++ b/tests/lib/filestorage/local.php @@ -26,10 +26,7 @@ class Test_Filestorage_Local extends Test_FileStorage { */ private $tmpDir; public function setUp(){ - $this->tmpDir=get_temp_dir().'/filestoragelocal'; - if(!file_exists($this->tmpDir)){ - mkdir($this->tmpDir); - } + $this->tmpDir=OC_Helper::tmpFolder(); $this->instance=new OC_Filestorage_Local(array('datadir'=>$this->tmpDir)); } diff --git a/tests/lib/filesystem.php b/tests/lib/filesystem.php new file mode 100644 index 00000000000..3e28d8c06e5 --- /dev/null +++ b/tests/lib/filesystem.php @@ -0,0 +1,64 @@ +<?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_Filesystem extends UnitTestCase{ + /** + * @var array tmpDirs + */ + private $tmpDirs; + + /** + * @return array + */ + private function getStorageData(){ + $dir=OC_Helper::tmpFolder(); + $this->tmpDirs[]=$dir; + return array('datadir'=>$dir); + } + + public function tearDown(){ + foreach($this->tmpDirs as $dir){ + OC_Helper::rmdirr($dir); + } + } + + public function setUp(){ + OC_Filesystem::clearMounts(); + } + + public function testMount(){ + OC_Filesystem::mount('OC_Filestorage_Local',self::getStorageData(),'/'); + $this->assertEqual('/',OC_Filesystem::getMountPoint('/')); + $this->assertEqual('/',OC_Filesystem::getMountPoint('/some/folder')); + $this->assertEqual('',OC_Filesystem::getInternalPath('/')); + $this->assertEqual('some/folder',OC_Filesystem::getInternalPath('/some/folder')); + + OC_Filesystem::mount('OC_Filestorage_Local',self::getStorageData(),'/some'); + $this->assertEqual('/',OC_Filesystem::getMountPoint('/')); + $this->assertEqual('/some/',OC_Filesystem::getMountPoint('/some/folder')); + $this->assertEqual('/some/',OC_Filesystem::getMountPoint('/some/')); + $this->assertEqual('/',OC_Filesystem::getMountPoint('/some')); + $this->assertEqual('folder',OC_Filesystem::getInternalPath('/some/folder')); + } +} + +?>
\ No newline at end of file diff --git a/tests/lib/group.php b/tests/lib/group.php new file mode 100644 index 00000000000..922613211bc --- /dev/null +++ b/tests/lib/group.php @@ -0,0 +1,114 @@ +<?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_Group extends UnitTestCase { + function setUp(){ + OC_Group::clearBackends(); + } + + function testSingleBackend(){ + OC_Group::useBackend(new OC_Group_Dummy()); + + $group1=uniqid(); + $group2=uniqid(); + OC_Group::createGroup($group1); + OC_Group::createGroup($group2); + + $user1=uniqid(); + $user2=uniqid(); + + $this->assertFalse(OC_Group::inGroup($user1,$group1)); + $this->assertFalse(OC_Group::inGroup($user2,$group1)); + $this->assertFalse(OC_Group::inGroup($user1,$group2)); + $this->assertFalse(OC_Group::inGroup($user2,$group2)); + + $this->assertTrue(OC_Group::addToGroup($user1,$group1)); + + $this->assertTrue(OC_Group::inGroup($user1,$group1)); + $this->assertFalse(OC_Group::inGroup($user2,$group1)); + $this->assertFalse(OC_Group::inGroup($user1,$group2)); + $this->assertFalse(OC_Group::inGroup($user2,$group2)); + + $this->assertFalse(OC_Group::addToGroup($user1,$group1)); + + $this->assertEqual(array($user1),OC_Group::usersInGroup($group1)); + $this->assertEqual(array(),OC_Group::usersInGroup($group2)); + + $this->assertEqual(array($group1),OC_Group::getUserGroups($user1)); + $this->assertEqual(array(),OC_Group::getUserGroups($user2)); + + OC_Group::deleteGroup($group1); + $this->assertEqual(array(),OC_Group::getUserGroups($user1)); + $this->assertEqual(array(),OC_Group::usersInGroup($group1)); + $this->assertFalse(OC_Group::inGroup($user1,$group1)); + } + + function testMultiBackend(){ + $backend1=new OC_Group_Dummy(); + $backend2=new OC_Group_Dummy(); + OC_Group::useBackend($backend1); + OC_Group::useBackend($backend2); + + $group1=uniqid(); + $group2=uniqid(); + OC_Group::createGroup($group1); + + //groups should be added to the first registered backend + $this->assertEqual(array($group1),$backend1->getGroups()); + $this->assertEqual(array(),$backend2->getGroups()); + + $this->assertEqual(array($group1),OC_Group::getGroups()); + $this->assertTrue(OC_Group::groupExists($group1)); + $this->assertFalse(OC_Group::groupExists($group2)); + + $backend1->createGroup($group2); + + $this->assertEqual(array($group1,$group2),OC_Group::getGroups()); + $this->assertTrue(OC_Group::groupExists($group1)); + $this->assertTrue(OC_Group::groupExists($group2)); + + $user1=uniqid(); + $user2=uniqid(); + + $this->assertFalse(OC_Group::inGroup($user1,$group1)); + $this->assertFalse(OC_Group::inGroup($user2,$group1)); + + + $this->assertTrue(OC_Group::addToGroup($user1,$group1)); + + $this->assertTrue(OC_Group::inGroup($user1,$group1)); + $this->assertFalse(OC_Group::inGroup($user2,$group1)); + $this->assertFalse($backend2->inGroup($user1,$group1)); + + $this->assertFalse(OC_Group::addToGroup($user1,$group1)); + + $this->assertEqual(array($user1),OC_Group::usersInGroup($group1)); + + $this->assertEqual(array($group1),OC_Group::getUserGroups($user1)); + $this->assertEqual(array(),OC_Group::getUserGroups($user2)); + + OC_Group::deleteGroup($group1); + $this->assertEqual(array(),OC_Group::getUserGroups($user1)); + $this->assertEqual(array(),OC_Group::usersInGroup($group1)); + $this->assertFalse(OC_Group::inGroup($user1,$group1)); + } +} diff --git a/tests/lib/group/backend.php b/tests/lib/group/backend.php new file mode 100644 index 00000000000..9405e90aabf --- /dev/null +++ b/tests/lib/group/backend.php @@ -0,0 +1,105 @@ +<?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 Test_Group_Backend extends UnitTestCase { + /** + * @var OC_Group_Backend $backend + */ + protected $backend; + + /** + * get a new unique group name + * test cases can override this in order to clean up created groups + * @return array + */ + public function getGroupName(){ + return uniqid('test_'); + } + + /** + * get a new unique user name + * test cases can override this in order to clean up created user + * @return array + */ + public function getUserName(){ + return uniqid('test_'); + } + + public function testAddRemove(){ + //get the number of groups we start with, in case there are exising groups + $startCount=count($this->backend->getGroups()); + + $name1=$this->getGroupName(); + $name2=$this->getGroupName(); + $this->backend->createGroup($name1); + $count=count($this->backend->getGroups())-$startCount; + $this->assertEqual(1,$count); + $this->assertTrue((array_search($name1,$this->backend->getGroups())!==false)); + $this->assertFalse((array_search($name2,$this->backend->getGroups())!==false)); + $this->backend->createGroup($name2); + $count=count($this->backend->getGroups())-$startCount; + $this->assertEqual(2,$count); + $this->assertTrue((array_search($name1,$this->backend->getGroups())!==false)); + $this->assertTrue((array_search($name2,$this->backend->getGroups())!==false)); + + $this->backend->deleteGroup($name2); + $count=count($this->backend->getGroups())-$startCount; + $this->assertEqual(1,$count); + $this->assertTrue((array_search($name1,$this->backend->getGroups())!==false)); + $this->assertFalse((array_search($name2,$this->backend->getGroups())!==false)); + } + + public function testUser(){ + $group1=$this->getGroupName(); + $group2=$this->getGroupName(); + $this->backend->createGroup($group1); + $this->backend->createGroup($group2); + + $user1=$this->getUserName(); + $user2=$this->getUserName(); + + $this->assertFalse($this->backend->inGroup($user1,$group1)); + $this->assertFalse($this->backend->inGroup($user2,$group1)); + $this->assertFalse($this->backend->inGroup($user1,$group2)); + $this->assertFalse($this->backend->inGroup($user2,$group2)); + + $this->assertTrue($this->backend->addToGroup($user1,$group1)); + + $this->assertTrue($this->backend->inGroup($user1,$group1)); + $this->assertFalse($this->backend->inGroup($user2,$group1)); + $this->assertFalse($this->backend->inGroup($user1,$group2)); + $this->assertFalse($this->backend->inGroup($user2,$group2)); + + $this->assertFalse($this->backend->addToGroup($user1,$group1)); + + $this->assertEqual(array($user1),$this->backend->usersInGroup($group1)); + $this->assertEqual(array(),$this->backend->usersInGroup($group2)); + + $this->assertEqual(array($group1),$this->backend->getUserGroups($user1)); + $this->assertEqual(array(),$this->backend->getUserGroups($user2)); + + $this->backend->deleteGroup($group1); + $this->assertEqual(array(),$this->backend->getUserGroups($user1)); + $this->assertEqual(array(),$this->backend->usersInGroup($group1)); + $this->assertFalse($this->backend->inGroup($user1,$group1)); + } +} diff --git a/tests/lib/group/database.php b/tests/lib/group/database.php new file mode 100644 index 00000000000..fb51bc8d8d9 --- /dev/null +++ b/tests/lib/group/database.php @@ -0,0 +1,55 @@ +<?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_Group_Database extends Test_Group_Backend { + private $groups=array(); + + /** + * get a new unique group name + * test cases can override this in order to clean up created groups + * @return array + */ + public function getGroupName(){ + $name=uniqid('test_'); + $this->groups[]=$name; + return $name; + } + + /** + * get a new unique user name + * test cases can override this in order to clean up created user + * @return array + */ + public function getUserName(){ + return uniqid('test_'); + } + + public function setUp(){ + $this->backend=new OC_Group_Database(); + } + + public function tearDown(){ + foreach($this->groups as $group){ + $this->backend->deleteGroup($group); + } + } +} diff --git a/tests/lib/group/dummy.php b/tests/lib/group/dummy.php new file mode 100644 index 00000000000..d0b475d3ec5 --- /dev/null +++ b/tests/lib/group/dummy.php @@ -0,0 +1,27 @@ +<?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_Group_Dummy extends Test_Group_Backend { + public function setUp(){ + $this->backend=new OC_Group_Dummy(); + } +} |