summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-04-13 01:58:53 +0200
committerRobin Appelman <icewind@owncloud.com>2012-04-13 01:59:05 +0200
commit1d8fdf52d52f4a73cb0a59b5d2c3a088ae1e9247 (patch)
tree09eedd220c847d587639567219194b92d39fa2f2 /tests/lib
parente9c1f8b4e650052eee33de6e1b4e29715e41cdf0 (diff)
downloadnextcloud-server-1d8fdf52d52f4a73cb0a59b5d2c3a088ae1e9247.tar.gz
nextcloud-server-1d8fdf52d52f4a73cb0a59b5d2c3a088ae1e9247.zip
allow multiply group backends
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/group.php114
-rw-r--r--tests/lib/group/backend.php105
-rw-r--r--tests/lib/group/database.php55
-rw-r--r--tests/lib/group/dummy.php27
4 files changed, 301 insertions, 0 deletions
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();
+ }
+}