RemoveInvalidSharesTest.php 2.2 KB

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