Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
provokateurin committed Nov 12, 2024
1 parent acf1846 commit dbee0fb
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion tests/lib/Repair/RepairInvalidSharesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@

namespace Test\Repair;

use OC\Files\Node\File;
use OC\Files\Node\Folder;
use OC\Repair\RepairInvalidShares;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

/**
Expand Down Expand Up @@ -63,14 +67,14 @@ public function testSharesNonExistingParent(): void {
'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
'share_with' => $qb->expr()->literal('recipientuser1'),
'uid_owner' => $qb->expr()->literal('user1'),
'uid_initiator' => $qb->expr()->literal('user1'),
'item_type' => $qb->expr()->literal('folder'),
'item_source' => $qb->expr()->literal(123),
'item_target' => $qb->expr()->literal('/123'),
'file_source' => $qb->expr()->literal(123),
'file_target' => $qb->expr()->literal('/test'),
'permissions' => $qb->expr()->literal(1),
'stime' => $qb->expr()->literal(time()),
'expiration' => $qb->expr()->literal('2015-09-25 00:00:00')
];

// valid share
Expand Down Expand Up @@ -151,11 +155,27 @@ public function fileSharePermissionsProvider() {
* @dataProvider fileSharePermissionsProvider
*/
public function testFileSharePermissions($itemType, $testPerms, $expectedPerms): void {
$file = $this->createMock(File::class);

$folder = $this->createMock(Folder::class);
$folder
->method('getFirstNodeById')
->with(123)
->willReturn($file);

$this->rootFolder = $this->createMock(IRootFolder::class);
$this->rootFolder
->method('getUserFolder')
->with('user1')
->willReturn($folder);
$this->overwriteService(IRootFolder::class, $this->rootFolder);

$qb = $this->connection->getQueryBuilder();
$qb->insert('share')
->values([
'share_type' => $qb->expr()->literal(IShare::TYPE_LINK),
'uid_owner' => $qb->expr()->literal('user1'),
'uid_initiator' => $qb->expr()->literal('user1'),
'item_type' => $qb->expr()->literal($itemType),
'item_source' => $qb->expr()->literal(123),
'item_target' => $qb->expr()->literal('/123'),
Expand Down Expand Up @@ -185,5 +205,7 @@ public function testFileSharePermissions($itemType, $testPerms, $expectedPerms):
$updatedShare = $results[0];

$this->assertEquals($expectedPerms, $updatedShare['permissions']);

$this->restoreAllServices();
}
}

0 comments on commit dbee0fb

Please sign in to comment.