From 0ea387811151da1fc397fa876b8a59052388d6bc Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 16 Mar 2015 12:42:40 +0100 Subject: No longer directly output OC_Image for thumbnails * Only use public interfaces - Injected IPreview * Added unit tests --- apps/files/tests/controller/apicontrollertest.php | 35 ++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'apps/files/tests/controller') diff --git a/apps/files/tests/controller/apicontrollertest.php b/apps/files/tests/controller/apicontrollertest.php index 1be7a749a1b..1d4317f0bca 100644 --- a/apps/files/tests/controller/apicontrollertest.php +++ b/apps/files/tests/controller/apicontrollertest.php @@ -17,6 +17,8 @@ use Test\TestCase; use OCP\IRequest; use OCA\Files\Service\TagService; use OCP\AppFramework\Http\DataResponse; +use OCP\IPreview; +use OCP\Image; /** * Class ApiController @@ -30,6 +32,8 @@ class ApiControllerTest extends TestCase { private $request; /** @var TagService */ private $tagService; + /** @var IPreview */ + private $preview; /** @var ApiController */ private $apiController; @@ -40,11 +44,15 @@ class ApiControllerTest extends TestCase { $this->tagService = $this->getMockBuilder('\OCA\Files\Service\TagService') ->disableOriginalConstructor() ->getMock(); + $this->preview = $this->getMockBuilder('\OCP\IPreview') + ->disableOriginalConstructor() + ->getMock(); $this->apiController = new ApiController( $this->appName, $this->request, - $this->tagService + $this->tagService, + $this->preview ); } @@ -240,4 +248,29 @@ class ApiControllerTest extends TestCase { $expected = new DataResponse(['message' => 'My error message'], Http::STATUS_NOT_FOUND); $this->assertEquals($expected, $this->apiController->updateFileTags('/path.txt', ['Tag1', 'Tag2'])); } + + public function testGetThumbnailInvalidSize() { + $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() { + $this->preview->expects($this->once()) + ->method('createPreview') + ->with('files/unknown.jpg', 10, 10, true) + ->willReturn(new Image); + $expected = new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); + $this->assertEquals($expected, $this->apiController->getThumbnail(10, 10, 'unknown.jpg')); + } + + public function testGetThumbnail() { + $this->preview->expects($this->once()) + ->method('createPreview') + ->with('files/known.jpg', 10, 10, true) + ->willReturn(new Image(\OC::$SERVERROOT.'/tests/data/testimage.jpg')); + + $ret = $this->apiController->getThumbnail(10, 10, 'known.jpg'); + + $this->assertEquals(Http::STATUS_OK, $ret->getStatus()); + } } -- cgit v1.2.3