group.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Robin Appelman
  6. * @copyright 2012 Robin Appelman icewind@owncloud.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. class Test_Group extends UnitTestCase {
  23. function setUp() {
  24. OC_Group::clearBackends();
  25. }
  26. function testSingleBackend() {
  27. OC_Group::useBackend(new OC_Group_Dummy());
  28. $group1=uniqid();
  29. $group2=uniqid();
  30. OC_Group::createGroup($group1);
  31. OC_Group::createGroup($group2);
  32. $user1=uniqid();
  33. $user2=uniqid();
  34. $this->assertFalse(OC_Group::inGroup($user1, $group1));
  35. $this->assertFalse(OC_Group::inGroup($user2, $group1));
  36. $this->assertFalse(OC_Group::inGroup($user1, $group2));
  37. $this->assertFalse(OC_Group::inGroup($user2, $group2));
  38. $this->assertTrue(OC_Group::addToGroup($user1, $group1));
  39. $this->assertTrue(OC_Group::inGroup($user1, $group1));
  40. $this->assertFalse(OC_Group::inGroup($user2, $group1));
  41. $this->assertFalse(OC_Group::inGroup($user1, $group2));
  42. $this->assertFalse(OC_Group::inGroup($user2, $group2));
  43. $this->assertFalse(OC_Group::addToGroup($user1, $group1));
  44. $this->assertEqual(array($user1), OC_Group::usersInGroup($group1));
  45. $this->assertEqual(array(), OC_Group::usersInGroup($group2));
  46. $this->assertEqual(array($group1), OC_Group::getUserGroups($user1));
  47. $this->assertEqual(array(), OC_Group::getUserGroups($user2));
  48. OC_Group::deleteGroup($group1);
  49. $this->assertEqual(array(), OC_Group::getUserGroups($user1));
  50. $this->assertEqual(array(), OC_Group::usersInGroup($group1));
  51. $this->assertFalse(OC_Group::inGroup($user1, $group1));
  52. }
  53. function testMultiBackend() {
  54. $backend1=new OC_Group_Dummy();
  55. $backend2=new OC_Group_Dummy();
  56. OC_Group::useBackend($backend1);
  57. OC_Group::useBackend($backend2);
  58. $group1=uniqid();
  59. $group2=uniqid();
  60. OC_Group::createGroup($group1);
  61. //groups should be added to the first registered backend
  62. $this->assertEqual(array($group1), $backend1->getGroups());
  63. $this->assertEqual(array(), $backend2->getGroups());
  64. $this->assertEqual(array($group1), OC_Group::getGroups());
  65. $this->assertTrue(OC_Group::groupExists($group1));
  66. $this->assertFalse(OC_Group::groupExists($group2));
  67. $backend1->createGroup($group2);
  68. $this->assertEqual(array($group1, $group2), OC_Group::getGroups());
  69. $this->assertTrue(OC_Group::groupExists($group1));
  70. $this->assertTrue(OC_Group::groupExists($group2));
  71. $user1=uniqid();
  72. $user2=uniqid();
  73. $this->assertFalse(OC_Group::inGroup($user1, $group1));
  74. $this->assertFalse(OC_Group::inGroup($user2, $group1));
  75. $this->assertTrue(OC_Group::addToGroup($user1, $group1));
  76. $this->assertTrue(OC_Group::inGroup($user1, $group1));
  77. $this->assertFalse(OC_Group::inGroup($user2, $group1));
  78. $this->assertFalse($backend2->inGroup($user1, $group1));
  79. $this->assertFalse(OC_Group::addToGroup($user1, $group1));
  80. $this->assertEqual(array($user1), OC_Group::usersInGroup($group1));
  81. $this->assertEqual(array($group1), OC_Group::getUserGroups($user1));
  82. $this->assertEqual(array(), OC_Group::getUserGroups($user2));
  83. OC_Group::deleteGroup($group1);
  84. $this->assertEqual(array(), OC_Group::getUserGroups($user1));
  85. $this->assertEqual(array(), OC_Group::usersInGroup($group1));
  86. $this->assertFalse(OC_Group::inGroup($user1, $group1));
  87. }
  88. }