2018-04-23 08:02:53 -04:00
|
|
|
<?php
|
2024-05-28 06:34:11 -04:00
|
|
|
|
2018-04-23 08:02:53 -04:00
|
|
|
/**
|
2024-05-28 06:34:11 -04:00
|
|
|
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2018 ownCloud GmbH
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2018-04-23 08:02:53 -04:00
|
|
|
*/
|
2018-05-24 03:27:40 -04:00
|
|
|
namespace OCA\DAV\Tests\Unit\Command;
|
2018-04-23 08:02:53 -04:00
|
|
|
|
2018-05-24 03:27:40 -04:00
|
|
|
use OCA\DAV\Command\RemoveInvalidShares;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\DAV\Connector\Sabre\Principal;
|
2025-02-03 09:34:01 -05:00
|
|
|
use OCP\IDBConnection;
|
2018-04-23 08:02:53 -04:00
|
|
|
use OCP\Migration\IOutput;
|
2025-02-03 09:34:01 -05:00
|
|
|
use OCP\Server;
|
2018-05-24 03:27:40 -04:00
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2018-04-23 08:02:53 -04:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class RemoveInvalidSharesTest
|
|
|
|
|
*
|
|
|
|
|
* @package OCA\DAV\Tests\Unit\Repair
|
|
|
|
|
* @group DB
|
|
|
|
|
*/
|
|
|
|
|
class RemoveInvalidSharesTest extends TestCase {
|
2019-11-27 09:27:18 -05:00
|
|
|
protected function setUp(): void {
|
2018-04-23 08:02:53 -04:00
|
|
|
parent::setUp();
|
2025-02-03 09:34:01 -05:00
|
|
|
$db = Server::get(IDBConnection::class);
|
2018-04-23 08:02:53 -04:00
|
|
|
|
|
|
|
|
$db->insertIfNotExist('*PREFIX*dav_shares', [
|
|
|
|
|
'principaluri' => 'principal:unknown',
|
|
|
|
|
'type' => 'calendar',
|
|
|
|
|
'access' => 2,
|
|
|
|
|
'resourceid' => 666,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function test(): void {
|
2025-02-03 09:34:01 -05:00
|
|
|
$db = Server::get(IDBConnection::class);
|
2020-08-11 15:32:18 -04:00
|
|
|
/** @var Principal | \PHPUnit\Framework\MockObject\MockObject $principal */
|
2018-04-23 08:02:53 -04:00
|
|
|
$principal = $this->createMock(Principal::class);
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
/** @var IOutput | \PHPUnit\Framework\MockObject\MockObject $output */
|
2018-04-23 08:02:53 -04:00
|
|
|
$output = $this->createMock(IOutput::class);
|
|
|
|
|
|
|
|
|
|
$repair = new RemoveInvalidShares($db, $principal);
|
2018-05-24 03:27:40 -04:00
|
|
|
$this->invokePrivate($repair, 'run', [$this->createMock(InputInterface::class), $this->createMock(OutputInterface::class)]);
|
2018-04-23 08:02:53 -04:00
|
|
|
|
|
|
|
|
$query = $db->getQueryBuilder();
|
|
|
|
|
$result = $query->select('*')->from('dav_shares')
|
|
|
|
|
->where($query->expr()->eq('principaluri', $query->createNamedParameter('principal:unknown')))->execute();
|
|
|
|
|
$data = $result->fetchAll();
|
|
|
|
|
$result->closeCursor();
|
|
|
|
|
$this->assertEquals(0, count($data));
|
|
|
|
|
}
|
|
|
|
|
}
|