aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Repair/RepairInvalidSharesTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Repair/RepairInvalidSharesTest.php')
-rw-r--r--tests/lib/Repair/RepairInvalidSharesTest.php72
1 files changed, 30 insertions, 42 deletions
diff --git a/tests/lib/Repair/RepairInvalidSharesTest.php b/tests/lib/Repair/RepairInvalidSharesTest.php
index 64ae6322657..72103976da5 100644
--- a/tests/lib/Repair/RepairInvalidSharesTest.php
+++ b/tests/lib/Repair/RepairInvalidSharesTest.php
@@ -1,17 +1,19 @@
<?php
+
/**
- * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Repair;
use OC\Repair\RepairInvalidShares;
+use OCP\Constants;
use OCP\IConfig;
+use OCP\IDBConnection;
use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
+use OCP\Server;
use OCP\Share\IShare;
use Test\TestCase;
@@ -24,11 +26,8 @@ use Test\TestCase;
*/
class RepairInvalidSharesTest extends TestCase {
- /** @var IRepairStep */
- private $repair;
-
- /** @var \OCP\IDBConnection */
- private $connection;
+ private RepairInvalidShares $repair;
+ private IDBConnection $connection;
protected function setUp(): void {
parent::setUp();
@@ -37,14 +36,13 @@ class RepairInvalidSharesTest extends TestCase {
->disableOriginalConstructor()
->getMock();
$config->expects($this->any())
- ->method('getSystemValue')
+ ->method('getSystemValueString')
->with('version')
->willReturn('12.0.0.0');
- $this->connection = \OC::$server->getDatabaseConnection();
+ $this->connection = Server::get(IDBConnection::class);
$this->deleteAllShares();
- /** @var \OCP\IConfig $config */
$this->repair = new RepairInvalidShares($config, $this->connection);
}
@@ -56,13 +54,13 @@ class RepairInvalidSharesTest extends TestCase {
protected function deleteAllShares() {
$qb = $this->connection->getQueryBuilder();
- $qb->delete('share')->execute();
+ $qb->delete('share')->executeStatement();
}
/**
* Test remove shares where the parent share does not exist anymore
*/
- public function testSharesNonExistingParent() {
+ public function testSharesNonExistingParent(): void {
$qb = $this->connection->getQueryBuilder();
$shareValues = [
'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
@@ -82,30 +80,30 @@ class RepairInvalidSharesTest extends TestCase {
$qb = $this->connection->getQueryBuilder();
$qb->insert('share')
->values($shareValues)
- ->execute();
- $parent = $this->getLastShareId();
+ ->executeStatement();
+ $parent = $qb->getLastInsertId();
// share with existing parent
$qb = $this->connection->getQueryBuilder();
$qb->insert('share')
->values(array_merge($shareValues, [
'parent' => $qb->expr()->literal($parent),
- ]))->execute();
- $validChild = $this->getLastShareId();
+ ]))->executeStatement();
+ $validChild = $qb->getLastInsertId();
// share with non-existing parent
$qb = $this->connection->getQueryBuilder();
$qb->insert('share')
->values(array_merge($shareValues, [
'parent' => $qb->expr()->literal($parent + 100),
- ]))->execute();
- $invalidChild = $this->getLastShareId();
+ ]))->executeStatement();
+ $invalidChild = $qb->getLastInsertId();
$query = $this->connection->getQueryBuilder();
$result = $query->select('id')
->from('share')
->orderBy('id', 'ASC')
- ->execute();
+ ->executeQuery();
$rows = $result->fetchAll();
$this->assertEquals([['id' => $parent], ['id' => $validChild], ['id' => $invalidChild]], $rows);
$result->closeCursor();
@@ -121,13 +119,13 @@ class RepairInvalidSharesTest extends TestCase {
$result = $query->select('id')
->from('share')
->orderBy('id', 'ASC')
- ->execute();
+ ->executeQuery();
$rows = $result->fetchAll();
$this->assertEquals([['id' => $parent], ['id' => $validChild]], $rows);
$result->closeCursor();
}
- public function fileSharePermissionsProvider() {
+ public static function fileSharePermissionsProvider(): array {
return [
// unchanged for folder
[
@@ -138,24 +136,23 @@ class RepairInvalidSharesTest extends TestCase {
// unchanged for read-write + share
[
'file',
- \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE,
- \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE,
+ Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_SHARE,
+ Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_SHARE,
],
// fixed for all perms
[
'file',
- \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_SHARE,
- \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE,
+ Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE | Constants::PERMISSION_SHARE,
+ Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_SHARE,
],
];
}
/**
* Test adjusting file share permissions
- *
- * @dataProvider fileSharePermissionsProvider
*/
- public function testFileSharePermissions($itemType, $testPerms, $expectedPerms) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('fileSharePermissionsProvider')]
+ public function testFileSharePermissions($itemType, $testPerms, $expectedPerms): void {
$qb = $this->connection->getQueryBuilder();
$qb->insert('share')
->values([
@@ -169,9 +166,7 @@ class RepairInvalidSharesTest extends TestCase {
'permissions' => $qb->expr()->literal($testPerms),
'stime' => $qb->expr()->literal(time()),
])
- ->execute();
-
- $shareId = $this->getLastShareId();
+ ->executeStatement();
/** @var IOutput | \PHPUnit\Framework\MockObject\MockObject $outputMock */
$outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
@@ -184,7 +179,7 @@ class RepairInvalidSharesTest extends TestCase {
->select('*')
->from('share')
->orderBy('permissions', 'ASC')
- ->execute()
+ ->executeQuery()
->fetchAll();
$this->assertCount(1, $results);
@@ -193,11 +188,4 @@ class RepairInvalidSharesTest extends TestCase {
$this->assertEquals($expectedPerms, $updatedShare['permissions']);
}
-
- /**
- * @return int
- */
- protected function getLastShareId() {
- return $this->connection->lastInsertId('*PREFIX*share');
- }
}