1
0

RemoveInvalidSharesTest.php 2.2 KB

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