DatabaseTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * @author Arthur Schiwon <blizzz@owncloud.com>
  4. * @author Joas Schilling <nickvergessen@owncloud.com>
  5. * @author Robin Appelman <icewind@owncloud.com>
  6. * @author Scrutinizer Auto-Fixer <auto-fixer@scrutinizer-ci.com>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @copyright Copyright (c) 2015, ownCloud, Inc.
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace Test\Group;
  26. /**
  27. * Class Database
  28. *
  29. * @group DB
  30. */
  31. class DatabaseTest extends Backend {
  32. private $groups = [];
  33. /**
  34. * get a new unique group name
  35. * test cases can override this in order to clean up created groups
  36. */
  37. public function getGroupName($name = null): string {
  38. $name = parent::getGroupName($name);
  39. $this->groups[] = $name;
  40. return $name;
  41. }
  42. protected function setUp(): void {
  43. parent::setUp();
  44. $this->backend = new \OC\Group\Database();
  45. }
  46. protected function tearDown(): void {
  47. foreach ($this->groups as $group) {
  48. $this->backend->deleteGroup($group);
  49. }
  50. parent::tearDown();
  51. }
  52. public function testAddDoubleNoCache(): void {
  53. $group = $this->getGroupName();
  54. $this->backend->createGroup($group);
  55. $backend = new \OC\Group\Database();
  56. $this->assertNull($backend->createGroup($group));
  57. }
  58. public function testAddLongGroupName(): void {
  59. $groupName = $this->getUniqueID('test_', 100);
  60. $gidCreated = $this->backend->createGroup($groupName);
  61. $this->assertEquals(64, strlen($gidCreated));
  62. $group = $this->backend->getGroupDetails($gidCreated);
  63. $this->assertEquals(['displayName' => $groupName], $group);
  64. }
  65. }