summaryrefslogtreecommitdiffstats
path: root/apps/files
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2016-10-17 21:53:23 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2016-11-03 14:00:33 +0100
commit87855aa97b0d90f8036ec40174ac1a3dcbd463e8 (patch)
tree95aed134338652a4773af4c98549442141b67fb0 /apps/files
parent3d6ee7ffc97af5c426ae7553bcb40f3c28064f93 (diff)
downloadnextcloud-server-87855aa97b0d90f8036ec40174ac1a3dcbd463e8.tar.gz
nextcloud-server-87855aa97b0d90f8036ec40174ac1a3dcbd463e8.zip
Added genertor helper & tests
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/files')
-rw-r--r--apps/files/tests/Controller/ApiControllerTest.php45
1 files changed, 32 insertions, 13 deletions
diff --git a/apps/files/tests/Controller/ApiControllerTest.php b/apps/files/tests/Controller/ApiControllerTest.php
index 4b7bec065a0..56d0f6c8dee 100644
--- a/apps/files/tests/Controller/ApiControllerTest.php
+++ b/apps/files/tests/Controller/ApiControllerTest.php
@@ -28,11 +28,15 @@ namespace OCA\Files\Controller;
use OC\Files\FileInfo;
use OCP\AppFramework\Http;
+use OCP\Files\File;
+use OCP\Files\Folder;
use OCP\Files\NotFoundException;
+use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\StorageNotAvailableException;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserSession;
+use OCP\Share\IManager;
use Test\TestCase;
use OCP\IRequest;
use OCA\Files\Service\TagService;
@@ -54,7 +58,7 @@ class ApiControllerTest extends TestCase {
private $request;
/** @var TagService */
private $tagService;
- /** @var IPreview */
+ /** @var IPreview|\PHPUnit_Framework_MockObject_MockObject */
private $preview;
/** @var ApiController */
private $apiController;
@@ -62,11 +66,13 @@ class ApiControllerTest extends TestCase {
private $shareManager;
/** @var \OCP\IConfig */
private $config;
- /** @var \OC\Files\Node\Folder */
+ /** @var Folder|\PHPUnit_Framework_MockObject_MockObject */
private $userFolder;
public function setUp() {
- $this->request = $this->getMockBuilder('\OCP\IRequest')
+ parent::setUp();
+
+ $this->request = $this->getMockBuilder(IRequest::class)
->disableOriginalConstructor()
->getMock();
$this->user = $this->createMock(IUser::class);
@@ -77,17 +83,17 @@ class ApiControllerTest extends TestCase {
$userSession->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
- $this->tagService = $this->getMockBuilder('\OCA\Files\Service\TagService')
+ $this->tagService = $this->getMockBuilder(TagService::class)
->disableOriginalConstructor()
->getMock();
- $this->shareManager = $this->getMockBuilder('\OCP\Share\IManager')
+ $this->shareManager = $this->getMockBuilder(IManager::class)
->disableOriginalConstructor()
->getMock();
- $this->preview = $this->getMockBuilder('\OCP\IPreview')
+ $this->preview = $this->getMockBuilder(IPreview::class)
->disableOriginalConstructor()
->getMock();
$this->config = $this->createMock(IConfig::class);
- $this->userFolder = $this->getMockBuilder('\OC\Files\Node\Folder')
+ $this->userFolder = $this->getMockBuilder(Folder::class)
->disableOriginalConstructor()
->getMock();
@@ -153,28 +159,41 @@ class ApiControllerTest extends TestCase {
}
public function testGetThumbnailInvalidSize() {
+ $this->userFolder->method('get')
+ ->with($this->equalTo(''))
+ ->willThrowException(new NotFoundException());
$expected = new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST);
$this->assertEquals($expected, $this->apiController->getThumbnail(0, 0, ''));
}
public function testGetThumbnailInvaidImage() {
+ $file = $this->createMock(File::class);
+ $this->userFolder->method('get')
+ ->with($this->equalTo('unknown.jpg'))
+ ->willReturn($file);
$this->preview->expects($this->once())
- ->method('createPreview')
- ->with('files/unknown.jpg', 10, 10, true)
- ->willReturn(new Image);
+ ->method('getPreview')
+ ->with($file, 10, 10, true)
+ ->willThrowException(new NotFoundException());
$expected = new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
$this->assertEquals($expected, $this->apiController->getThumbnail(10, 10, 'unknown.jpg'));
}
public function testGetThumbnail() {
+ $file = $this->createMock(File::class);
+ $this->userFolder->method('get')
+ ->with($this->equalTo('known.jpg'))
+ ->willReturn($file);
+ $preview = $this->createMock(ISimpleFile::class);
$this->preview->expects($this->once())
- ->method('createPreview')
- ->with('files/known.jpg', 10, 10, true)
- ->willReturn(new Image(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
+ ->method('getPreview')
+ ->with($this->equalTo($file), 10, 10, true)
+ ->willReturn($preview);
$ret = $this->apiController->getThumbnail(10, 10, 'known.jpg');
$this->assertEquals(Http::STATUS_OK, $ret->getStatus());
+ $this->assertInstanceOf(Http\FileDisplayResponse::class, $ret);
}
public function testUpdateFileSorting() {