2015-08-22 14:36:01 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2024-06-06 19:48:28 +02:00
|
|
|
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-08-22 14:36:01 +02:00
|
|
|
*/
|
2016-05-17 11:42:03 +02:00
|
|
|
namespace OCA\Files_Sharing\Tests\Controllers;
|
2015-08-22 14:36:01 +02:00
|
|
|
|
2016-10-24 11:46:25 +02:00
|
|
|
use OCA\Files_Sharing\Controller\ExternalSharesController;
|
2020-03-12 13:43:29 +01:00
|
|
|
use OCA\Files_Sharing\External\Manager;
|
2015-08-22 14:36:01 +02:00
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
|
|
|
use OCP\Http\Client\IClientService;
|
2023-10-12 11:36:35 +02:00
|
|
|
use OCP\IConfig;
|
2015-08-22 14:36:01 +02:00
|
|
|
use OCP\IRequest;
|
2023-10-16 10:16:22 +02:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2015-08-22 14:36:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ExternalShareControllerTest
|
|
|
|
*
|
|
|
|
* @package OCA\Files_Sharing\Controllers
|
|
|
|
*/
|
|
|
|
class ExternalShareControllerTest extends \Test\TestCase {
|
|
|
|
/** @var IRequest */
|
|
|
|
private $request;
|
|
|
|
/** @var \OCA\Files_Sharing\External\Manager */
|
|
|
|
private $externalManager;
|
2023-10-16 10:16:22 +02:00
|
|
|
/** @var IConfig|MockObject */
|
|
|
|
private $config;
|
2015-08-22 14:36:01 +02:00
|
|
|
/** @var IClientService */
|
|
|
|
private $clientService;
|
|
|
|
|
2019-11-27 15:27:18 +01:00
|
|
|
protected function setUp(): void {
|
2016-05-17 11:42:03 +02:00
|
|
|
parent::setUp();
|
2020-03-12 13:43:29 +01:00
|
|
|
$this->request = $this->createMock(IRequest::class);
|
|
|
|
$this->externalManager = $this->createMock(Manager::class);
|
|
|
|
$this->clientService = $this->createMock(IClientService::class);
|
2023-10-12 11:36:35 +02:00
|
|
|
$this->config = $this->createMock(IConfig::class);
|
2015-08-22 14:36:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ExternalSharesController
|
|
|
|
*/
|
|
|
|
public function getExternalShareController() {
|
|
|
|
return new ExternalSharesController(
|
|
|
|
'files_sharing',
|
|
|
|
$this->request,
|
|
|
|
$this->externalManager,
|
2023-10-12 11:36:35 +02:00
|
|
|
$this->clientService,
|
|
|
|
$this->config,
|
2015-08-22 14:36:01 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-10-02 09:57:33 +02:00
|
|
|
public function testIndex(): void {
|
2015-08-22 14:36:01 +02:00
|
|
|
$this->externalManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getOpenShares')
|
2020-03-12 13:43:29 +01:00
|
|
|
->willReturn(['MyDummyArray']);
|
2015-08-22 14:36:01 +02:00
|
|
|
|
|
|
|
$this->assertEquals(new JSONResponse(['MyDummyArray']), $this->getExternalShareController()->index());
|
|
|
|
}
|
|
|
|
|
2015-10-02 09:57:33 +02:00
|
|
|
public function testCreate(): void {
|
2015-08-22 14:36:01 +02:00
|
|
|
$this->externalManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('acceptShare')
|
|
|
|
->with(4);
|
|
|
|
|
|
|
|
$this->assertEquals(new JSONResponse(), $this->getExternalShareController()->create(4));
|
|
|
|
}
|
|
|
|
|
2015-10-02 09:57:33 +02:00
|
|
|
public function testDestroy(): void {
|
2015-08-22 14:36:01 +02:00
|
|
|
$this->externalManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('declineShare')
|
|
|
|
->with(4);
|
|
|
|
|
|
|
|
$this->assertEquals(new JSONResponse(), $this->getExternalShareController()->destroy(4));
|
|
|
|
}
|
|
|
|
}
|