diff options
Diffstat (limited to 'apps/files_versions/tests/Controller')
-rw-r--r-- | apps/files_versions/tests/Controller/PreviewControllerTest.php | 78 |
1 files changed, 26 insertions, 52 deletions
diff --git a/apps/files_versions/tests/Controller/PreviewControllerTest.php b/apps/files_versions/tests/Controller/PreviewControllerTest.php index 0457d0d5f24..542ea2b6b34 100644 --- a/apps/files_versions/tests/Controller/PreviewControllerTest.php +++ b/apps/files_versions/tests/Controller/PreviewControllerTest.php @@ -1,37 +1,19 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl> - * - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ + namespace OCA\Files_Versions\Tests\Controller; use OCA\Files_Versions\Controller\PreviewController; use OCA\Files_Versions\Versions\IVersionManager; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; -use OCP\AppFramework\Http\FileDisplayResponse; use OCP\Files\File; use OCP\Files\Folder; -use OCP\Files\IMimeTypeDetector; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFile; @@ -39,30 +21,19 @@ use OCP\IPreview; use OCP\IRequest; use OCP\IUser; use OCP\IUserSession; +use OCP\Preview\IMimeIconProvider; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class PreviewControllerTest extends TestCase { + private IRootFolder&MockObject $rootFolder; + private string $userId; + private IPreview&MockObject $previewManager; + private IUserSession&MockObject $userSession; + private IVersionManager&MockObject $versionManager; - /** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */ - private $rootFolder; - - /** @var string */ - private $userId; - - /** @var IMimeTypeDetector|\PHPUnit\Framework\MockObject\MockObject */ - private $mimeTypeDetector; - - /** @var IPreview|\PHPUnit\Framework\MockObject\MockObject */ - private $previewManager; - - /** @var PreviewController|\PHPUnit\Framework\MockObject\MockObject */ - private $controller; - - /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ - private $userSession; - - /** @var IVersionManager|\PHPUnit\Framework\MockObject\MockObject */ - private $versionManager; + private IMimeIconProvider&MockObject $mimeIconProvider; + private PreviewController $controller; protected function setUp(): void { parent::setUp(); @@ -79,6 +50,7 @@ class PreviewControllerTest extends TestCase { ->method('getUser') ->willReturn($user); $this->versionManager = $this->createMock(IVersionManager::class); + $this->mimeIconProvider = $this->createMock(IMimeIconProvider::class); $this->controller = new PreviewController( 'files_versions', @@ -86,39 +58,40 @@ class PreviewControllerTest extends TestCase { $this->rootFolder, $this->userSession, $this->versionManager, - $this->previewManager + $this->previewManager, + $this->mimeIconProvider, ); } - public function testInvalidFile() { + public function testInvalidFile(): void { $res = $this->controller->getPreview(''); $expected = new DataResponse([], Http::STATUS_BAD_REQUEST); $this->assertEquals($expected, $res); } - public function testInvalidWidth() { + public function testInvalidWidth(): void { $res = $this->controller->getPreview('file', 0); $expected = new DataResponse([], Http::STATUS_BAD_REQUEST); $this->assertEquals($expected, $res); } - public function testInvalidHeight() { + public function testInvalidHeight(): void { $res = $this->controller->getPreview('file', 10, 0); $expected = new DataResponse([], Http::STATUS_BAD_REQUEST); $this->assertEquals($expected, $res); } - public function testInvalidVersion() { + public function testInvalidVersion(): void { $res = $this->controller->getPreview('file', 10, 0); $expected = new DataResponse([], Http::STATUS_BAD_REQUEST); $this->assertEquals($expected, $res); } - public function testValidPreview() { + public function testValidPreview(): void { $userFolder = $this->createMock(Folder::class); $userRoot = $this->createMock(Folder::class); @@ -150,12 +123,13 @@ class PreviewControllerTest extends TestCase { ->willReturn('previewMime'); $res = $this->controller->getPreview('file', 10, 10, '42'); - $expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'previewMime']); - $this->assertEquals($expected, $res); + $this->assertEquals('previewMime', $res->getHeaders()['Content-Type']); + $this->assertEquals(Http::STATUS_OK, $res->getStatus()); + $this->assertEquals($preview, $this->invokePrivate($res, 'file')); } - public function testVersionNotFound() { + public function testVersionNotFound(): void { $userFolder = $this->createMock(Folder::class); $userRoot = $this->createMock(Folder::class); |