Skip to content

Commit

Permalink
fix(Trash): Fix empty original location
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Oct 14, 2024
1 parent 2994e18 commit 9ff7e62
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/Trash/TrashBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@

use OC\Files\SetupManager;
use OC\Group\Database;
use OCA\Files_Trashbin\Trash\ITrashManager;
use OCA\GroupFolders\ACL\ACLManager;
use OCA\GroupFolders\ACL\ACLManagerFactory;
use OCA\GroupFolders\ACL\Rule;
use OCA\GroupFolders\ACL\RuleManager;
use OCA\GroupFolders\ACL\UserMapping\UserMapping;
use OCA\GroupFolders\Folder\FolderManager;
use OCA\GroupFolders\Mount\GroupFolderStorage;
use OCA\GroupFolders\Trash\GroupTrashItem;
use OCA\GroupFolders\Trash\TrashBackend;
use OCP\Constants;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\IUser;
use OCP\Server;
use OCP\Share;
use Test\TestCase;
use Test\Traits\UserTrait;

Expand Down Expand Up @@ -211,4 +216,61 @@ public function testHideDeletedTrashItemInDeletedParentFolderAcl(): void {

$this->logout();
}

public function testBug() {

Check failure on line 220 in tests/Trash/TrashBackendTest.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

MissingReturnType

tests/Trash/TrashBackendTest.php:220:18: MissingReturnType: Method OCA\GroupFolders\Tests\Trash\TrashBackendTest::testBug does not have a return type, expecting void (see https://psalm.dev/050)
$userA = $this->createUser('A', 'test');
$userAFolder = Server::get(IRootFolder::class)->getUserFolder('A');
$userB = $this->createUser('B', 'test');
$userBFolder = Server::get(IRootFolder::class)->getUserFolder('B');

$groupBackend = Server::get(Database::class);
$groupBackend->createGroup('A');
$groupBackend->addToGroup('A', 'A');

$groupFolderId = $this->folderManager->createFolder('A');
$this->folderManager->addApplicableGroup($groupFolderId, 'A');
$this->assertInstanceOf(Folder::class, $userAFolder->get('A'));

$this->loginAsUser('A');

$userAFolder->newFolder('A/B');
$this->ruleManager->saveRule(new Rule(new UserMapping('group', 'A'), $userAFolder->get('A/B')->getId(), Constants::PERMISSION_ALL, 0));
$this->ruleManager->saveRule(new Rule(new UserMapping('user', 'A'), $userAFolder->get('A/B')->getId(), Constants::PERMISSION_ALL, Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_CREATE));
// TODO: Bug?
//$this->assertSame(Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_CREATE, $this->aclManager->getACLPermissionsForPath('A/B'));

$userAFolder->newFolder('A/B/C');
$this->ruleManager->saveRule(new Rule(new UserMapping('user', 'A'), $userAFolder->get('A/B/C')->getId(), Constants::PERMISSION_ALL, Constants::PERMISSION_ALL));
$this->assertSame(Constants::PERMISSION_ALL, $this->aclManager->getACLPermissionsForPath('A/B/C'));

$userAFolder->newFile('A/B/C/D', 'foo');

$shareManager = Server::get(Share\IManager::class);

$folderShare = $shareManager->newShare();
$folderShare->setShareType(Share\IShare::TYPE_USER);
$folderShare->setSharedWith('B');
$folderShare->setSharedBy('A');
$folderShare->setPermissions(19);
$folderShare->setNode($userAFolder->get('A/B/C'));
$folderShare = $shareManager->createShare($folderShare);
$this->assertNotEmpty($folderShare->getId());

$fileShare = $shareManager->newShare();
$fileShare->setShareType(Share\IShare::TYPE_USER);
$fileShare->setSharedWith('B');
$fileShare->setSharedBy('A');
$fileShare->setPermissions(19);
$fileShare->setNode($userAFolder->get('A/B/C/D'));
$fileShare = $shareManager->createShare($fileShare);
$this->assertNotEmpty($fileShare->getId());

$this->loginAsUser('B');

$this->assertTrue($userBFolder->get('D')->isDeletable());
$userBFolder->get('D')->delete();

// TODO: Bug?
$this->assertCount(1, $this->trashBackend->listTrashRoot($userA));
}
}

0 comments on commit 9ff7e62

Please sign in to comment.