backend.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase {
  23. /**
  24. * @var OC_Group_Backend $backend
  25. */
  26. protected $backend;
  27. /**
  28. * get a new unique group name
  29. * test cases can override this in order to clean up created groups
  30. * @return array
  31. */
  32. public function getGroupName() {
  33. return uniqid('test_');
  34. }
  35. /**
  36. * get a new unique user name
  37. * test cases can override this in order to clean up created user
  38. * @return array
  39. */
  40. public function getUserName() {
  41. return uniqid('test_');
  42. }
  43. public function testAddRemove() {
  44. //get the number of groups we start with, in case there are exising groups
  45. $startCount=count($this->backend->getGroups());
  46. $name1=$this->getGroupName();
  47. $name2=$this->getGroupName();
  48. $this->backend->createGroup($name1);
  49. $count=count($this->backend->getGroups())-$startCount;
  50. $this->assertEquals(1, $count);
  51. $this->assertTrue((array_search($name1, $this->backend->getGroups())!==false));
  52. $this->assertFalse((array_search($name2, $this->backend->getGroups())!==false));
  53. $this->backend->createGroup($name2);
  54. $count=count($this->backend->getGroups())-$startCount;
  55. $this->assertEquals(2, $count);
  56. $this->assertTrue((array_search($name1, $this->backend->getGroups())!==false));
  57. $this->assertTrue((array_search($name2, $this->backend->getGroups())!==false));
  58. $this->backend->deleteGroup($name2);
  59. $count=count($this->backend->getGroups())-$startCount;
  60. $this->assertEquals(1, $count);
  61. $this->assertTrue((array_search($name1, $this->backend->getGroups())!==false));
  62. $this->assertFalse((array_search($name2, $this->backend->getGroups())!==false));
  63. }
  64. public function testUser() {
  65. $group1=$this->getGroupName();
  66. $group2=$this->getGroupName();
  67. $this->backend->createGroup($group1);
  68. $this->backend->createGroup($group2);
  69. $user1=$this->getUserName();
  70. $user2=$this->getUserName();
  71. $this->assertFalse($this->backend->inGroup($user1, $group1));
  72. $this->assertFalse($this->backend->inGroup($user2, $group1));
  73. $this->assertFalse($this->backend->inGroup($user1, $group2));
  74. $this->assertFalse($this->backend->inGroup($user2, $group2));
  75. $this->assertTrue($this->backend->addToGroup($user1, $group1));
  76. $this->assertTrue($this->backend->inGroup($user1, $group1));
  77. $this->assertFalse($this->backend->inGroup($user2, $group1));
  78. $this->assertFalse($this->backend->inGroup($user1, $group2));
  79. $this->assertFalse($this->backend->inGroup($user2, $group2));
  80. $this->assertFalse($this->backend->addToGroup($user1, $group1));
  81. $this->assertEquals(array($user1), $this->backend->usersInGroup($group1));
  82. $this->assertEquals(array(), $this->backend->usersInGroup($group2));
  83. $this->assertEquals(array($group1), $this->backend->getUserGroups($user1));
  84. $this->assertEquals(array(), $this->backend->getUserGroups($user2));
  85. $this->backend->deleteGroup($group1);
  86. $this->assertEquals(array(), $this->backend->getUserGroups($user1));
  87. $this->assertEquals(array(), $this->backend->usersInGroup($group1));
  88. $this->assertFalse($this->backend->inGroup($user1, $group1));
  89. }
  90. }