From 37e524dc6d12c9a7d8b8f845b5a2a04506783cf1 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 28 Nov 2012 18:30:47 +0100 Subject: [PATCH] added more unittests for the group file --- tests/lib/group.php | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tests/lib/group.php b/tests/lib/group.php index 7b9ca3414b0..28264b0f168 100644 --- a/tests/lib/group.php +++ b/tests/lib/group.php @@ -3,7 +3,9 @@ * ownCloud * * @author Robin Appelman +* @author Bernhard Posselt * @copyright 2012 Robin Appelman icewind@owncloud.com +* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE @@ -62,6 +64,72 @@ class Test_Group extends UnitTestCase { $this->assertFalse(OC_Group::inGroup($user1, $group1)); } + + public function testNoEmptyGIDs(){ + OC_Group::useBackend(new OC_Group_Dummy()); + $emptyGroup = null; + + $this->assertEqual(false, OC_Group::createGroup($emptyGroup)); + } + + + public function testNoGroupsTwice(){ + OC_Group::useBackend(new OC_Group_Dummy()); + $group = uniqid(); + OC_Group::createGroup($group); + + $groupCopy = $group; + + $this->assertEqual(false, OC_Group::createGroup($groupCopy)); + $this->assertEqual(array($group), OC_Group::getGroups()); + } + + + public function testDontDeleteAdminGroup(){ + OC_Group::useBackend(new OC_Group_Dummy()); + $adminGroup = 'admin'; + OC_Group::createGroup($adminGroup); + + $this->assertEqual(false, OC_Group::deleteGroup($adminGroup)); + $this->assertEqual(array($adminGroup), OC_Group::getGroups()); + } + + + public function testDontAddUserToNonexistentGroup(){ + OC_Group::useBackend(new OC_Group_Dummy()); + $groupNonExistent = 'notExistent'; + $user = uniqid(); + + $this->assertEqual(false, OC_Group::addToGroup($user, $groupNonExistent)); + $this->assertEqual(array(), OC_Group::getGroups()); + } + + + public function testUsersInGroup(){ + OC_Group::useBackend(new OC_Group_Dummy()); + $group1 = uniqid(); + $group2 = uniqid(); + $group3 = uniqid(); + $user1 = uniqid(); + $user2 = uniqid(); + $user3 = uniqid(); + OC_Group::createGroup($group1); + OC_Group::createGroup($group2); + OC_Group::createGroup($group3); + + OC_Group::addToGroup($user1, $group1); + OC_Group::addToGroup($user2, $group1); + OC_Group::addToGroup($user3, $group1); + OC_Group::addToGroup($user3, $group2); + + $this->assertEqual(array($user1, $user2, $user3), + OC_Group::usersInGroups(array($group1, $group2, $group3))); + + // FIXME: needs more parameter variation + } + + + function testMultiBackend() { $backend1=new OC_Group_Dummy(); $backend2=new OC_Group_Dummy();