aboutsummaryrefslogtreecommitdiffstats
path: root/tests/Core/Controller/AvatarControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Core/Controller/AvatarControllerTest.php')
-rw-r--r--tests/Core/Controller/AvatarControllerTest.php95
1 files changed, 48 insertions, 47 deletions
diff --git a/tests/Core/Controller/AvatarControllerTest.php b/tests/Core/Controller/AvatarControllerTest.php
index b000482e29a..a78e2c1bb5c 100644
--- a/tests/Core/Controller/AvatarControllerTest.php
+++ b/tests/Core/Controller/AvatarControllerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -128,9 +129,9 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Fetch an avatar if a user has no avatar
*/
- public function testGetAvatarNoAvatar() {
+ public function testGetAvatarNoAvatar(): void {
$this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
- $this->avatarMock->method('getFile')->will($this->throwException(new NotFoundException()));
+ $this->avatarMock->method('getFile')->willThrowException(new NotFoundException());
$response = $this->avatarController->getAvatar('userId', 32);
//Comment out until JS is fixed
@@ -140,7 +141,7 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Fetch the user's avatar
*/
- public function testGetAvatar() {
+ public function testGetAvatar(): void {
$this->avatarMock->method('getFile')->willReturn($this->avatarFile);
$this->avatarManager->method('getAvatar')->with('userId')->willReturn($this->avatarMock);
$this->avatarMock->expects($this->once())
@@ -161,7 +162,7 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Fetch the user's avatar
*/
- public function testGetGeneratedAvatar() {
+ public function testGetGeneratedAvatar(): void {
$this->avatarMock->method('getFile')->willReturn($this->avatarFile);
$this->avatarManager->method('getAvatar')->with('userId')->willReturn($this->avatarMock);
@@ -179,11 +180,11 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Fetch the avatar of a non-existing user
*/
- public function testGetAvatarNoUser() {
+ public function testGetAvatarNoUser(): void {
$this->avatarManager
->method('getAvatar')
->with('userDoesNotExist')
- ->will($this->throwException(new \Exception('user does not exist')));
+ ->willThrowException(new \Exception('user does not exist'));
$response = $this->avatarController->getAvatar('userDoesNotExist', 32);
@@ -276,7 +277,7 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Remove an avatar
*/
- public function testDeleteAvatar() {
+ public function testDeleteAvatar(): void {
$this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
$response = $this->avatarController->deleteAvatar();
@@ -286,13 +287,13 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Test what happens if the removing of the avatar fails
*/
- public function testDeleteAvatarException() {
- $this->avatarMock->method('remove')->will($this->throwException(new \Exception("foo")));
+ public function testDeleteAvatarException(): void {
+ $this->avatarMock->method('remove')->willThrowException(new \Exception('foo'));
$this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
$this->logger->expects($this->once())
->method('error')
- ->with('foo', ['exception' => new \Exception("foo"), 'app' => 'core']);
+ ->with('foo', ['exception' => new \Exception('foo'), 'app' => 'core']);
$expectedResponse = new Http\JSONResponse(['data' => ['message' => 'An error occurred. Please contact your admin.']], Http::STATUS_BAD_REQUEST);
$this->assertEquals($expectedResponse, $this->avatarController->deleteAvatar());
}
@@ -300,7 +301,7 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Trying to get a tmp avatar when it is not available. 404
*/
- public function testTmpAvatarNoTmp() {
+ public function testTmpAvatarNoTmp(): void {
$response = $this->avatarController->getTmpAvatar();
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
}
@@ -308,8 +309,8 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Fetch tmp avatar
*/
- public function testTmpAvatarValid() {
- $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
+ public function testTmpAvatarValid(): void {
+ $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.jpg'));
$response = $this->avatarController->getTmpAvatar();
$this->assertEquals(Http::STATUS_OK, $response->getStatus());
@@ -319,7 +320,7 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* When trying to post a new avatar a path or image should be posted.
*/
- public function testPostAvatarNoPathOrImage() {
+ public function testPostAvatarNoPathOrImage(): void {
$response = $this->avatarController->postAvatar(null);
$this->assertEquals(Http::STATUS_BAD_REQUEST, $response->getStatus());
@@ -328,17 +329,17 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Test a correct post of an avatar using POST
*/
- public function testPostAvatarFile() {
+ public function testPostAvatarFile(): void {
//Create temp file
- $fileName = tempnam('', "avatarTest");
- $copyRes = copy(\OC::$SERVERROOT.'/tests/data/testimage.jpg', $fileName);
+ $fileName = tempnam('', 'avatarTest');
+ $copyRes = copy(\OC::$SERVERROOT . '/tests/data/testimage.jpg', $fileName);
$this->assertTrue($copyRes);
//Create file in cache
- $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
+ $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.jpg'));
//Create request return
- $reqRet = ['error' => [0], 'tmp_name' => [$fileName], 'size' => [filesize(\OC::$SERVERROOT.'/tests/data/testimage.jpg')]];
+ $reqRet = ['error' => [0], 'tmp_name' => [$fileName], 'size' => [filesize(\OC::$SERVERROOT . '/tests/data/testimage.jpg')]];
$this->request->method('getUploadedFile')->willReturn($reqRet);
$response = $this->avatarController->postAvatar(null);
@@ -353,7 +354,7 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Test invalid post os an avatar using POST
*/
- public function testPostAvatarInvalidFile() {
+ public function testPostAvatarInvalidFile(): void {
//Create request return
$reqRet = ['error' => [1], 'tmp_name' => ['foo']];
$this->request->method('getUploadedFile')->willReturn($reqRet);
@@ -366,17 +367,17 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Check what happens when we upload a GIF
*/
- public function testPostAvatarFileGif() {
+ public function testPostAvatarFileGif(): void {
//Create temp file
- $fileName = tempnam('', "avatarTest");
- $copyRes = copy(\OC::$SERVERROOT.'/tests/data/testimage.gif', $fileName);
+ $fileName = tempnam('', 'avatarTest');
+ $copyRes = copy(\OC::$SERVERROOT . '/tests/data/testimage.gif', $fileName);
$this->assertTrue($copyRes);
//Create file in cache
- $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.gif'));
+ $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.gif'));
//Create request return
- $reqRet = ['error' => [0], 'tmp_name' => [$fileName], 'size' => [filesize(\OC::$SERVERROOT.'/tests/data/testimage.gif')]];
+ $reqRet = ['error' => [0], 'tmp_name' => [$fileName], 'size' => [filesize(\OC::$SERVERROOT . '/tests/data/testimage.gif')]];
$this->request->method('getUploadedFile')->willReturn($reqRet);
$response = $this->avatarController->postAvatar(null);
@@ -390,13 +391,13 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Test posting avatar from existing file
*/
- public function testPostAvatarFromFile() {
+ public function testPostAvatarFromFile(): void {
//Mock node API call
$file = $this->getMockBuilder('OCP\Files\File')
->disableOriginalConstructor()->getMock();
$file->expects($this->once())
->method('getContent')
- ->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
+ ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.jpg'));
$file->expects($this->once())
->method('getMimeType')
->willReturn('image/jpeg');
@@ -414,7 +415,7 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Test posting avatar from existing folder
*/
- public function testPostAvatarFromNoFile() {
+ public function testPostAvatarFromNoFile(): void {
$file = $this->getMockBuilder('OCP\Files\Node')->getMock();
$userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock();
$this->rootFolder->method('getUserFolder')->with('userid')->willReturn($userFolder);
@@ -430,7 +431,7 @@ class AvatarControllerTest extends \Test\TestCase {
$this->assertEquals(['data' => ['message' => 'Please select a file.']], $response->getData());
}
- public function testPostAvatarInvalidType() {
+ public function testPostAvatarInvalidType(): void {
$file = $this->getMockBuilder('OCP\Files\File')
->disableOriginalConstructor()->getMock();
$file->expects($this->never())
@@ -446,7 +447,7 @@ class AvatarControllerTest extends \Test\TestCase {
$this->assertEquals($expectedResponse, $this->avatarController->postAvatar('avatar.jpg'));
}
- public function testPostAvatarNotPermittedException() {
+ public function testPostAvatarNotPermittedException(): void {
$file = $this->getMockBuilder('OCP\Files\File')
->disableOriginalConstructor()->getMock();
$file->expects($this->once())
@@ -466,15 +467,15 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Test what happens if the upload of the avatar fails
*/
- public function testPostAvatarException() {
+ public function testPostAvatarException(): void {
$this->cache->expects($this->once())
->method('set')
- ->will($this->throwException(new \Exception("foo")));
+ ->willThrowException(new \Exception('foo'));
$file = $this->getMockBuilder('OCP\Files\File')
->disableOriginalConstructor()->getMock();
$file->expects($this->once())
->method('getContent')
- ->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
+ ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.jpg'));
$file->expects($this->once())
->method('getMimeType')
->willReturn('image/jpeg');
@@ -484,7 +485,7 @@ class AvatarControllerTest extends \Test\TestCase {
$this->logger->expects($this->once())
->method('error')
- ->with('foo', ['exception' => new \Exception("foo"), 'app' => 'core']);
+ ->with('foo', ['exception' => new \Exception('foo'), 'app' => 'core']);
$expectedResponse = new Http\JSONResponse(['data' => ['message' => 'An error occurred. Please contact your admin.']], Http::STATUS_OK);
$this->assertEquals($expectedResponse, $this->avatarController->postAvatar('avatar.jpg'));
}
@@ -493,7 +494,7 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Test invalid crop argument
*/
- public function testPostCroppedAvatarInvalidCrop() {
+ public function testPostCroppedAvatarInvalidCrop(): void {
$response = $this->avatarController->postCroppedAvatar([]);
$this->assertEquals(Http::STATUS_BAD_REQUEST, $response->getStatus());
@@ -502,7 +503,7 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Test no tmp avatar to crop
*/
- public function testPostCroppedAvatarNoTmpAvatar() {
+ public function testPostCroppedAvatarNoTmpAvatar(): void {
$response = $this->avatarController->postCroppedAvatar(['x' => 0, 'y' => 0, 'w' => 10, 'h' => 10]);
$this->assertEquals(Http::STATUS_BAD_REQUEST, $response->getStatus());
@@ -511,10 +512,10 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Test with non square crop
*/
- public function testPostCroppedAvatarNoSquareCrop() {
- $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
+ public function testPostCroppedAvatarNoSquareCrop(): void {
+ $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.jpg'));
- $this->avatarMock->method('set')->will($this->throwException(new \OC\NotSquareException));
+ $this->avatarMock->method('set')->willThrowException(new \OC\NotSquareException);
$this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
$response = $this->avatarController->postCroppedAvatar(['x' => 0, 'y' => 0, 'w' => 10, 'h' => 11]);
@@ -524,8 +525,8 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Check for proper reply on proper crop argument
*/
- public function testPostCroppedAvatarValidCrop() {
- $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
+ public function testPostCroppedAvatarValidCrop(): void {
+ $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.jpg'));
$this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
$response = $this->avatarController->postCroppedAvatar(['x' => 0, 'y' => 0, 'w' => 10, 'h' => 10]);
@@ -536,15 +537,15 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Test what happens if the cropping of the avatar fails
*/
- public function testPostCroppedAvatarException() {
- $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
+ public function testPostCroppedAvatarException(): void {
+ $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.jpg'));
- $this->avatarMock->method('set')->will($this->throwException(new \Exception('foo')));
+ $this->avatarMock->method('set')->willThrowException(new \Exception('foo'));
$this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
$this->logger->expects($this->once())
->method('error')
- ->with('foo', ['exception' => new \Exception("foo"), 'app' => 'core']);
+ ->with('foo', ['exception' => new \Exception('foo'), 'app' => 'core']);
$expectedResponse = new Http\JSONResponse(['data' => ['message' => 'An error occurred. Please contact your admin.']], Http::STATUS_BAD_REQUEST);
$this->assertEquals($expectedResponse, $this->avatarController->postCroppedAvatar(['x' => 0, 'y' => 0, 'w' => 10, 'h' => 11]));
}
@@ -553,8 +554,8 @@ class AvatarControllerTest extends \Test\TestCase {
/**
* Check for proper reply on proper crop argument
*/
- public function testFileTooBig() {
- $fileName = \OC::$SERVERROOT.'/tests/data/testimage.jpg';
+ public function testFileTooBig(): void {
+ $fileName = \OC::$SERVERROOT . '/tests/data/testimage.jpg';
//Create request return
$reqRet = ['error' => [0], 'tmp_name' => [$fileName], 'size' => [21 * 1024 * 1024]];
$this->request->method('getUploadedFile')->willReturn($reqRet);