1
0

DatabaseTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace Test\Group;
  8. /**
  9. * Class Database
  10. *
  11. * @group DB
  12. */
  13. class DatabaseTest extends Backend {
  14. private $groups = [];
  15. /**
  16. * get a new unique group name
  17. * test cases can override this in order to clean up created groups
  18. */
  19. public function getGroupName($name = null): string {
  20. $name = parent::getGroupName($name);
  21. $this->groups[] = $name;
  22. return $name;
  23. }
  24. protected function setUp(): void {
  25. parent::setUp();
  26. $this->backend = new \OC\Group\Database();
  27. }
  28. protected function tearDown(): void {
  29. foreach ($this->groups as $group) {
  30. $this->backend->deleteGroup($group);
  31. }
  32. parent::tearDown();
  33. }
  34. public function testAddDoubleNoCache(): void {
  35. $group = $this->getGroupName();
  36. $this->backend->createGroup($group);
  37. $backend = new \OC\Group\Database();
  38. $this->assertNull($backend->createGroup($group));
  39. }
  40. public function testAddLongGroupName(): void {
  41. $groupName = $this->getUniqueID('test_', 100);
  42. $gidCreated = $this->backend->createGroup($groupName);
  43. $this->assertEquals(64, strlen($gidCreated));
  44. $group = $this->backend->getGroupDetails($gidCreated);
  45. $this->assertEquals(['displayName' => $groupName], $group);
  46. }
  47. }