Fix PublicPreviewControllerTests

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2018-06-14 10:04:31 +02:00
parent 20e514690c
commit ff3f63fd47
No known key found for this signature in database
GPG Key ID: F941078878347C0C
1 changed files with 10 additions and 8 deletions

View File

@ -33,6 +33,7 @@ use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile; use OCP\Files\SimpleFS\ISimpleFile;
use OCP\IPreview; use OCP\IPreview;
use OCP\IRequest; use OCP\IRequest;
use OCP\ISession;
use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager; use OCP\Share\IManager;
use OCP\Share\IShare; use OCP\Share\IShare;
@ -60,26 +61,27 @@ class PublicPreviewControllerTest extends TestCase {
'files_sharing', 'files_sharing',
$this->createMock(IRequest::class), $this->createMock(IRequest::class),
$this->shareManager, $this->shareManager,
$this->createMock(ISession::class),
$this->previewManager $this->previewManager
); );
} }
public function testInvalidToken() { public function testInvalidToken() {
$res = $this->controller->getPreview('file', 10, 10, ''); $res = $this->controller->getPreview('', 'file', 10, 10, '');
$expected = new DataResponse([], Http::STATUS_BAD_REQUEST); $expected = new DataResponse([], Http::STATUS_BAD_REQUEST);
$this->assertEquals($expected, $res); $this->assertEquals($expected, $res);
} }
public function testInvalidWidth() { public function testInvalidWidth() {
$res = $this->controller->getPreview('file', 0); $res = $this->controller->getPreview('token', 'file', 0);
$expected = new DataResponse([], Http::STATUS_BAD_REQUEST); $expected = new DataResponse([], Http::STATUS_BAD_REQUEST);
$this->assertEquals($expected, $res); $this->assertEquals($expected, $res);
} }
public function testInvalidHeight() { public function testInvalidHeight() {
$res = $this->controller->getPreview('file', 10, 0); $res = $this->controller->getPreview('token', 'file', 10, 0);
$expected = new DataResponse([], Http::STATUS_BAD_REQUEST); $expected = new DataResponse([], Http::STATUS_BAD_REQUEST);
$this->assertEquals($expected, $res); $this->assertEquals($expected, $res);
@ -90,7 +92,7 @@ class PublicPreviewControllerTest extends TestCase {
->with($this->equalTo('token')) ->with($this->equalTo('token'))
->willThrowException(new ShareNotFound()); ->willThrowException(new ShareNotFound());
$res = $this->controller->getPreview('file', 10, 10, 'token'); $res = $this->controller->getPreview('token', 'file', 10, 10);
$expected = new DataResponse([], Http::STATUS_NOT_FOUND); $expected = new DataResponse([], Http::STATUS_NOT_FOUND);
$this->assertEquals($expected, $res); $this->assertEquals($expected, $res);
@ -105,7 +107,7 @@ class PublicPreviewControllerTest extends TestCase {
$share->method('getPermissions') $share->method('getPermissions')
->willReturn(0); ->willReturn(0);
$res = $this->controller->getPreview('file', 10, 10, 'token'); $res = $this->controller->getPreview('token', 'file', 10, 10);
$expected = new DataResponse([], Http::STATUS_FORBIDDEN); $expected = new DataResponse([], Http::STATUS_FORBIDDEN);
$this->assertEquals($expected, $res); $this->assertEquals($expected, $res);
@ -132,7 +134,7 @@ class PublicPreviewControllerTest extends TestCase {
$preview->method('getMimeType') $preview->method('getMimeType')
->willReturn('myMime'); ->willReturn('myMime');
$res = $this->controller->getPreview('file', 10, 10, 'token', true); $res = $this->controller->getPreview('token', 'file', 10, 10, true);
$expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']); $expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']);
$this->assertEquals($expected, $res); $this->assertEquals($expected, $res);
} }
@ -154,7 +156,7 @@ class PublicPreviewControllerTest extends TestCase {
->with($this->equalTo('file')) ->with($this->equalTo('file'))
->willThrowException(new NotFoundException()); ->willThrowException(new NotFoundException());
$res = $this->controller->getPreview('file', 10, 10, 'token', true); $res = $this->controller->getPreview('token', 'file', 10, 10, true);
$expected = new DataResponse([], Http::STATUS_NOT_FOUND); $expected = new DataResponse([], Http::STATUS_NOT_FOUND);
$this->assertEquals($expected, $res); $this->assertEquals($expected, $res);
} }
@ -186,7 +188,7 @@ class PublicPreviewControllerTest extends TestCase {
$preview->method('getMimeType') $preview->method('getMimeType')
->willReturn('myMime'); ->willReturn('myMime');
$res = $this->controller->getPreview('file', 10, 10, 'token', true); $res = $this->controller->getPreview('token', 'file', 10, 10, true);
$expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']); $expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']);
$this->assertEquals($expected, $res); $this->assertEquals($expected, $res);
} }