2012-04-12 19:58:53 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2012-04-12 19:58:53 -04:00
|
|
|
/**
|
2024-05-10 09:09:14 -04:00
|
|
|
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-12-30 08:16:51 -05:00
|
|
|
*/
|
2012-04-12 19:58:53 -04:00
|
|
|
|
2016-05-19 02:44:41 -04:00
|
|
|
namespace Test\Group;
|
|
|
|
|
|
2025-06-12 12:31:58 -04:00
|
|
|
use OC\Group\Database;
|
|
|
|
|
|
2015-11-02 19:52:41 -05:00
|
|
|
/**
|
2016-05-19 02:44:41 -04:00
|
|
|
* Class Database
|
2015-11-02 19:52:41 -05:00
|
|
|
*/
|
2025-10-20 19:52:40 -04:00
|
|
|
#[\PHPUnit\Framework\Attributes\Group('DB')]
|
2016-05-20 09:38:20 -04:00
|
|
|
class DatabaseTest extends Backend {
|
2020-03-26 04:30:18 -04:00
|
|
|
private $groups = [];
|
2014-11-05 06:21:02 -05:00
|
|
|
|
2012-04-12 19:58:53 -04:00
|
|
|
/**
|
|
|
|
|
* get a new unique group name
|
|
|
|
|
* test cases can override this in order to clean up created groups
|
|
|
|
|
*/
|
2024-04-10 05:00:51 -04:00
|
|
|
public function getGroupName($name = null): string {
|
2014-11-05 06:21:02 -05:00
|
|
|
$name = parent::getGroupName($name);
|
|
|
|
|
$this->groups[] = $name;
|
2012-04-12 19:58:53 -04:00
|
|
|
return $name;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function setUp(): void {
|
2014-11-05 06:21:02 -05:00
|
|
|
parent::setUp();
|
2025-06-12 12:31:58 -04:00
|
|
|
$this->backend = new Database();
|
2012-04-12 19:58:53 -04:00
|
|
|
}
|
|
|
|
|
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function tearDown(): void {
|
2015-12-30 08:16:51 -05:00
|
|
|
foreach ($this->groups as $group) {
|
2012-04-12 19:58:53 -04:00
|
|
|
$this->backend->deleteGroup($group);
|
|
|
|
|
}
|
2014-11-05 06:21:02 -05:00
|
|
|
parent::tearDown();
|
2012-04-12 19:58:53 -04:00
|
|
|
}
|
2015-12-30 08:16:51 -05:00
|
|
|
|
2024-04-10 05:00:51 -04:00
|
|
|
public function testAddDoubleNoCache(): void {
|
2015-12-30 08:16:51 -05:00
|
|
|
$group = $this->getGroupName();
|
|
|
|
|
|
|
|
|
|
$this->backend->createGroup($group);
|
|
|
|
|
|
2025-06-12 12:31:58 -04:00
|
|
|
$backend = new Database();
|
2024-04-10 05:00:51 -04:00
|
|
|
$this->assertNull($backend->createGroup($group));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAddLongGroupName(): void {
|
|
|
|
|
$groupName = $this->getUniqueID('test_', 100);
|
|
|
|
|
|
|
|
|
|
$gidCreated = $this->backend->createGroup($groupName);
|
|
|
|
|
$this->assertEquals(64, strlen($gidCreated));
|
|
|
|
|
|
|
|
|
|
$group = $this->backend->getGroupDetails($gidCreated);
|
|
|
|
|
$this->assertEquals(['displayName' => $groupName], $group);
|
2015-12-30 08:16:51 -05:00
|
|
|
}
|
2012-04-12 19:58:53 -04:00
|
|
|
}
|