request = $this->createMock(IRequest::class); $this->fileConversionManager = $this->createMock(IConversionManager::class); $this->file = $this->createMock(File::class); $this->l10n = $this->createMock(IL10N::class); $this->user = 'userid'; $this->userFolder = $this->createMock(Folder::class); $this->rootFolder = $this->createMock(IRootFolder::class); $this->rootFolder->method('getUserFolder')->with($this->user)->willReturn($this->userFolder); $this->conversionApiController = new ConversionApiController( $this->appName, $this->request, $this->fileConversionManager, $this->rootFolder, $this->l10n, $this->user, ); } public function testThrowsNotFoundException() { $this->expectException(OCSNotFoundException::class); $this->conversionApiController->convert(42, 'image/png'); } public function testThrowsOcsException() { $this->userFolder->method('getFirstNodeById')->with(42)->willReturn($this->file); $this->fileConversionManager->method('convert')->willThrowException(new \Exception()); $this->expectException(OCSException::class); $this->conversionApiController->convert(42, 'image/png'); } public function testConvert() { $convertedFileAbsolutePath = $this->user . '/files/test.png'; $this->userFolder->method('getFirstNodeById')->with(42)->willReturn($this->file); $this->userFolder->method('getRelativePath')->with($convertedFileAbsolutePath)->willReturn('/test.png'); $this->userFolder->method('get')->with('/test.png')->willReturn($this->file); $this->file->method('getId')->willReturn(42); $this->fileConversionManager->method('convert')->with($this->file, 'image/png', null)->willReturn($convertedFileAbsolutePath); $actual = $this->conversionApiController->convert(42, 'image/png', null); $expected = new DataResponse([ 'path' => '/test.png', 'fileId' => 42, ], Http::STATUS_CREATED); $this->assertEquals($expected, $actual); } }