diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2015-03-16 12:42:40 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2015-03-24 18:55:06 +0100 |
commit | 0ea387811151da1fc397fa876b8a59052388d6bc (patch) | |
tree | 1f3ba967cb5a286ce55ed8817f86f446671a26b2 /apps/files/tests/controller | |
parent | 1bd141b65511983326f0076b676b14e1528ddd65 (diff) | |
download | nextcloud-server-0ea387811151da1fc397fa876b8a59052388d6bc.tar.gz nextcloud-server-0ea387811151da1fc397fa876b8a59052388d6bc.zip |
No longer directly output OC_Image for thumbnails
* Only use public interfaces
- Injected IPreview
* Added unit tests
Diffstat (limited to 'apps/files/tests/controller')
-rw-r--r-- | apps/files/tests/controller/apicontrollertest.php | 35 |
1 files changed, 34 insertions, 1 deletions
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()); + } } |