RemoveInvalidSharesTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2018 ownCloud GmbH
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\Tests\Unit\Command;
  8. use OCA\DAV\Command\RemoveInvalidShares;
  9. use OCA\DAV\Connector\Sabre\Principal;
  10. use OCP\Migration\IOutput;
  11. use Symfony\Component\Console\Input\InputInterface;
  12. use Symfony\Component\Console\Output\OutputInterface;
  13. use Test\TestCase;
  14. /**
  15. * Class RemoveInvalidSharesTest
  16. *
  17. * @package OCA\DAV\Tests\Unit\Repair
  18. * @group DB
  19. */
  20. class RemoveInvalidSharesTest extends TestCase {
  21. protected function setUp(): void {
  22. parent::setUp();
  23. $db = \OC::$server->getDatabaseConnection();
  24. $db->insertIfNotExist('*PREFIX*dav_shares', [
  25. 'principaluri' => 'principal:unknown',
  26. 'type' => 'calendar',
  27. 'access' => 2,
  28. 'resourceid' => 666,
  29. ]);
  30. }
  31. public function test(): void {
  32. $db = \OC::$server->getDatabaseConnection();
  33. /** @var Principal | \PHPUnit\Framework\MockObject\MockObject $principal */
  34. $principal = $this->createMock(Principal::class);
  35. /** @var IOutput | \PHPUnit\Framework\MockObject\MockObject $output */
  36. $output = $this->createMock(IOutput::class);
  37. $repair = new RemoveInvalidShares($db, $principal);
  38. $this->invokePrivate($repair, 'run', [$this->createMock(InputInterface::class), $this->createMock(OutputInterface::class)]);
  39. $query = $db->getQueryBuilder();
  40. $result = $query->select('*')->from('dav_shares')
  41. ->where($query->expr()->eq('principaluri', $query->createNamedParameter('principal:unknown')))->execute();
  42. $data = $result->fetchAll();
  43. $result->closeCursor();
  44. $this->assertEquals(0, count($data));
  45. }
  46. }