ExternalShareControllerTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Files_Sharing\Tests\Controllers;
  8. use OCA\Files_Sharing\Controller\ExternalSharesController;
  9. use OCA\Files_Sharing\External\Manager;
  10. use OCP\AppFramework\Http\JSONResponse;
  11. use OCP\Http\Client\IClientService;
  12. use OCP\IConfig;
  13. use OCP\IRequest;
  14. use PHPUnit\Framework\MockObject\MockObject;
  15. /**
  16. * Class ExternalShareControllerTest
  17. *
  18. * @package OCA\Files_Sharing\Controllers
  19. */
  20. class ExternalShareControllerTest extends \Test\TestCase {
  21. /** @var IRequest */
  22. private $request;
  23. /** @var \OCA\Files_Sharing\External\Manager */
  24. private $externalManager;
  25. /** @var IConfig|MockObject */
  26. private $config;
  27. /** @var IClientService */
  28. private $clientService;
  29. protected function setUp(): void {
  30. parent::setUp();
  31. $this->request = $this->createMock(IRequest::class);
  32. $this->externalManager = $this->createMock(Manager::class);
  33. $this->clientService = $this->createMock(IClientService::class);
  34. $this->config = $this->createMock(IConfig::class);
  35. }
  36. /**
  37. * @return ExternalSharesController
  38. */
  39. public function getExternalShareController() {
  40. return new ExternalSharesController(
  41. 'files_sharing',
  42. $this->request,
  43. $this->externalManager,
  44. $this->clientService,
  45. $this->config,
  46. );
  47. }
  48. public function testIndex(): void {
  49. $this->externalManager
  50. ->expects($this->once())
  51. ->method('getOpenShares')
  52. ->willReturn(['MyDummyArray']);
  53. $this->assertEquals(new JSONResponse(['MyDummyArray']), $this->getExternalShareController()->index());
  54. }
  55. public function testCreate(): void {
  56. $this->externalManager
  57. ->expects($this->once())
  58. ->method('acceptShare')
  59. ->with(4);
  60. $this->assertEquals(new JSONResponse(), $this->getExternalShareController()->create(4));
  61. }
  62. public function testDestroy(): void {
  63. $this->externalManager
  64. ->expects($this->once())
  65. ->method('declineShare')
  66. ->with(4);
  67. $this->assertEquals(new JSONResponse(), $this->getExternalShareController()->destroy(4));
  68. }
  69. }