RemoveInvalidSharesTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018, ownCloud GmbH
  4. *
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\DAV\Tests\Unit\Command;
  24. use OCA\DAV\Command\RemoveInvalidShares;
  25. use OCA\DAV\Connector\Sabre\Principal;
  26. use OCP\Migration\IOutput;
  27. use Symfony\Component\Console\Input\InputInterface;
  28. use Symfony\Component\Console\Output\OutputInterface;
  29. use Test\TestCase;
  30. /**
  31. * Class RemoveInvalidSharesTest
  32. *
  33. * @package OCA\DAV\Tests\Unit\Repair
  34. * @group DB
  35. */
  36. class RemoveInvalidSharesTest extends TestCase {
  37. protected function setUp(): void {
  38. parent::setUp();
  39. $db = \OC::$server->getDatabaseConnection();
  40. $db->insertIfNotExist('*PREFIX*dav_shares', [
  41. 'principaluri' => 'principal:unknown',
  42. 'type' => 'calendar',
  43. 'access' => 2,
  44. 'resourceid' => 666,
  45. ]);
  46. }
  47. public function test() {
  48. $db = \OC::$server->getDatabaseConnection();
  49. /** @var Principal | \PHPUnit\Framework\MockObject\MockObject $principal */
  50. $principal = $this->createMock(Principal::class);
  51. /** @var IOutput | \PHPUnit\Framework\MockObject\MockObject $output */
  52. $output = $this->createMock(IOutput::class);
  53. $repair = new RemoveInvalidShares($db, $principal);
  54. $this->invokePrivate($repair, 'run', [$this->createMock(InputInterface::class), $this->createMock(OutputInterface::class)]);
  55. $query = $db->getQueryBuilder();
  56. $result = $query->select('*')->from('dav_shares')
  57. ->where($query->expr()->eq('principaluri', $query->createNamedParameter('principal:unknown')))->execute();
  58. $data = $result->fetchAll();
  59. $result->closeCursor();
  60. $this->assertEquals(0, count($data));
  61. }
  62. }