Skip to content

Commit

Permalink
fix: ACLManager tests
Browse files Browse the repository at this point in the history
Signed-off-by: Git'Fellow <[email protected]>

chore: optimize code

Signed-off-by: Git'Fellow <[email protected]>

fix: call logger

Signed-off-by: Git'Fellow <[email protected]>

fix: Add LoggerInterface

Signed-off-by: Git'Fellow <[email protected]>

Fix: Typo

Signed-off-by: Git'Fellow <[email protected]>
  • Loading branch information
solracsf authored and skjnldsv committed Aug 30, 2024
1 parent 03be9e2 commit 69f808d
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions tests/ACL/ACLManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,26 @@
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
use OCP\IUser;
use Psr\Log\LoggerInterface;
use Test\TestCase;

class ACLManagerTest extends TestCase {
/** @var RuleManager */
private $ruleManager;
/** @var TrashManager */
private $trashManager;
/** @var IUser */
private $user;
/** @var ACLManager */
private $aclManager;
/** @var IUserMapping */
private $dummyMapping;
private RuleManager $ruleManager;
private TrashManager $trashManager;
private LoggerInterface $logger;
private IUser $user;
private ACLManager $aclManager;
private IUserMapping $dummyMapping;
/** @var Rule[] */
private $rules = [];
private array $rules = [];

protected function setUp(): void {
parent::setUp();

$this->user = $this->createMock(IUser::class);
$this->ruleManager = $this->createMock(RuleManager::class);
$this->trashManager = $this->createMock(TrashManager::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->aclManager = $this->getAclManager();
$this->dummyMapping = $this->createMapping('dummy');

Expand All @@ -77,25 +75,25 @@ private function createMapping(string $id): IUserMapping {
return $mapping;
}

private function getAclManager(bool $perUserMerge = false) {
private function getAclManager(bool $perUserMerge = false): ACLManager {
$rootMountPoint = $this->createMock(IMountPoint::class);
$rootMountPoint->method('getNumericStorageId')
->willReturn(1);
$rootFolder = $this->createMock(IRootFolder::class);
$rootFolder->method('getMountPoint')
->willReturn($rootMountPoint);

return new ACLManager($this->ruleManager, $this->trashManager, $this->user, function () use ($rootFolder) {
return new ACLManager($this->ruleManager, $this->trashManager, $this->logger, $this->user, function () use ($rootFolder) {
return $rootFolder;
}, null, $perUserMerge);
}

public function testGetACLPermissionsForPathNoRules() {
public function testGetACLPermissionsForPathNoRules(): void {
$this->rules = [];
$this->assertEquals(Constants::PERMISSION_ALL, $this->aclManager->getACLPermissionsForPath('foo'));
}

public function testGetACLPermissionsForPath() {
public function testGetACLPermissionsForPath(): void {
$this->rules = [
'foo' => [
new Rule($this->createMapping('1'), 10, Constants::PERMISSION_READ + Constants::PERMISSION_UPDATE, Constants::PERMISSION_READ), // read only
Expand All @@ -121,7 +119,7 @@ public function testGetACLPermissionsForPath() {
$this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE - Constants::PERMISSION_UPDATE - Constants::PERMISSION_READ, $this->aclManager->getACLPermissionsForPath('foo/blocked2'));
}

public function testGetACLPermissionsForPathInTrashbin() {
public function testGetACLPermissionsForPathInTrashbin(): void {
$this->rules = [
'__groupfolders/1' => [
new Rule($this->dummyMapping, 10, Constants::PERMISSION_READ + Constants::PERMISSION_UPDATE, Constants::PERMISSION_READ), // read only
Expand Down Expand Up @@ -151,7 +149,7 @@ public function testGetACLPermissionsForPathInTrashbin() {



public function testGetACLPermissionsForPathPerUserMerge() {
public function testGetACLPermissionsForPathPerUserMerge(): void {
$aclManager = $this->getAclManager(true);
$this->rules = [
'foo' => [
Expand Down

0 comments on commit 69f808d

Please sign in to comment.