1
0

AvatarControllerTest.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <?php
  2. /**
  3. * @author Roeland Jago Douma <roeland@famdouma.nl>
  4. *
  5. * @copyright Copyright (c) 2015, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OC\Core\Controller;
  22. /**
  23. * Overwrite is_uploaded_file in the OC\Core\Controller namespace to allow
  24. * proper unit testing of the postAvatar call.
  25. */
  26. function is_uploaded_file($filename) {
  27. return file_exists($filename);
  28. }
  29. namespace Tests\Core\Controller;
  30. use OC\AppFramework\Utility\TimeFactory;
  31. use OC\Core\Controller\AvatarController;
  32. use OC\Core\Controller\GuestAvatarController;
  33. use OCP\AppFramework\Http;
  34. use OCP\Files\File;
  35. use OCP\Files\IRootFolder;
  36. use OCP\Files\NotFoundException;
  37. use OCP\Files\NotPermittedException;
  38. use OCP\Files\SimpleFS\ISimpleFile;
  39. use OCP\IAvatar;
  40. use OCP\IAvatarManager;
  41. use OCP\ICache;
  42. use OCP\IL10N;
  43. use OCP\IRequest;
  44. use OCP\IUser;
  45. use OCP\IUserManager;
  46. use Psr\Log\LoggerInterface;
  47. /**
  48. * Class AvatarControllerTest
  49. *
  50. * @package OC\Core\Controller
  51. */
  52. class AvatarControllerTest extends \Test\TestCase {
  53. /** @var AvatarController */
  54. private $avatarController;
  55. /** @var GuestAvatarController */
  56. private $guestAvatarController;
  57. /** @var IAvatar|\PHPUnit\Framework\MockObject\MockObject */
  58. private $avatarMock;
  59. /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
  60. private $userMock;
  61. /** @var ISimpleFile|\PHPUnit\Framework\MockObject\MockObject */
  62. private $avatarFile;
  63. /** @var IAvatarManager|\PHPUnit\Framework\MockObject\MockObject */
  64. private $avatarManager;
  65. /** @var ICache|\PHPUnit\Framework\MockObject\MockObject */
  66. private $cache;
  67. /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
  68. private $l;
  69. /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
  70. private $userManager;
  71. /** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */
  72. private $rootFolder;
  73. /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
  74. private $logger;
  75. /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
  76. private $request;
  77. /** @var TimeFactory|\PHPUnit\Framework\MockObject\MockObject */
  78. private $timeFactory;
  79. protected function setUp(): void {
  80. parent::setUp();
  81. $this->avatarManager = $this->getMockBuilder('OCP\IAvatarManager')->getMock();
  82. $this->cache = $this->getMockBuilder('OCP\ICache')
  83. ->disableOriginalConstructor()->getMock();
  84. $this->l = $this->getMockBuilder(IL10N::class)->getMock();
  85. $this->l->method('t')->willReturnArgument(0);
  86. $this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
  87. $this->request = $this->getMockBuilder(IRequest::class)->getMock();
  88. $this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock();
  89. $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
  90. $this->timeFactory = $this->getMockBuilder('OC\AppFramework\Utility\TimeFactory')->getMock();
  91. $this->avatarMock = $this->getMockBuilder('OCP\IAvatar')->getMock();
  92. $this->userMock = $this->getMockBuilder(IUser::class)->getMock();
  93. $this->guestAvatarController = new GuestAvatarController(
  94. 'core',
  95. $this->request,
  96. $this->avatarManager,
  97. $this->logger
  98. );
  99. $this->avatarController = new AvatarController(
  100. 'core',
  101. $this->request,
  102. $this->avatarManager,
  103. $this->cache,
  104. $this->l,
  105. $this->userManager,
  106. $this->rootFolder,
  107. $this->logger,
  108. 'userid',
  109. $this->timeFactory,
  110. $this->guestAvatarController,
  111. );
  112. // Configure userMock
  113. $this->userMock->method('getDisplayName')->willReturn('displayName');
  114. $this->userMock->method('getUID')->willReturn('userId');
  115. $this->userManager->method('get')
  116. ->willReturnMap([['userId', $this->userMock]]);
  117. $this->avatarFile = $this->getMockBuilder(ISimpleFile::class)->getMock();
  118. $this->avatarFile->method('getContent')->willReturn('image data');
  119. $this->avatarFile->method('getMimeType')->willReturn('image type');
  120. $this->avatarFile->method('getEtag')->willReturn('my etag');
  121. $this->avatarFile->method('getName')->willReturn('my name');
  122. $this->avatarFile->method('getMTime')->willReturn(42);
  123. }
  124. protected function tearDown(): void {
  125. parent::tearDown();
  126. }
  127. /**
  128. * Fetch an avatar if a user has no avatar
  129. */
  130. public function testGetAvatarNoAvatar() {
  131. $this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
  132. $this->avatarMock->method('getFile')->will($this->throwException(new NotFoundException()));
  133. $response = $this->avatarController->getAvatar('userId', 32);
  134. //Comment out until JS is fixed
  135. $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
  136. }
  137. /**
  138. * Fetch the user's avatar
  139. */
  140. public function testGetAvatar() {
  141. $this->avatarMock->method('getFile')->willReturn($this->avatarFile);
  142. $this->avatarManager->method('getAvatar')->with('userId')->willReturn($this->avatarMock);
  143. $this->avatarMock->expects($this->once())
  144. ->method('isCustomAvatar')
  145. ->willReturn(true);
  146. $response = $this->avatarController->getAvatar('userId', 32);
  147. $this->assertEquals(Http::STATUS_OK, $response->getStatus());
  148. $this->assertArrayHasKey('Content-Type', $response->getHeaders());
  149. $this->assertEquals('image type', $response->getHeaders()['Content-Type']);
  150. $this->assertArrayHasKey('X-NC-IsCustomAvatar', $response->getHeaders());
  151. $this->assertEquals('1', $response->getHeaders()['X-NC-IsCustomAvatar']);
  152. $this->assertEquals('my etag', $response->getETag());
  153. }
  154. /**
  155. * Fetch the user's avatar
  156. */
  157. public function testGetGeneratedAvatar() {
  158. $this->avatarMock->method('getFile')->willReturn($this->avatarFile);
  159. $this->avatarManager->method('getAvatar')->with('userId')->willReturn($this->avatarMock);
  160. $response = $this->avatarController->getAvatar('userId', 32);
  161. $this->assertEquals(Http::STATUS_OK, $response->getStatus());
  162. $this->assertArrayHasKey('Content-Type', $response->getHeaders());
  163. $this->assertEquals('image type', $response->getHeaders()['Content-Type']);
  164. $this->assertArrayHasKey('X-NC-IsCustomAvatar', $response->getHeaders());
  165. $this->assertEquals('0', $response->getHeaders()['X-NC-IsCustomAvatar']);
  166. $this->assertEquals('my etag', $response->getETag());
  167. }
  168. /**
  169. * Fetch the avatar of a non-existing user
  170. */
  171. public function testGetAvatarNoUser() {
  172. $this->avatarManager
  173. ->method('getAvatar')
  174. ->with('userDoesNotExist')
  175. ->will($this->throwException(new \Exception('user does not exist')));
  176. $response = $this->avatarController->getAvatar('userDoesNotExist', 32);
  177. //Comment out until JS is fixed
  178. $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
  179. }
  180. public function testGetAvatarSize64(): void {
  181. $this->avatarMock->expects($this->once())
  182. ->method('getFile')
  183. ->with($this->equalTo(64))
  184. ->willReturn($this->avatarFile);
  185. $this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
  186. $this->logger->expects($this->never())
  187. ->method('debug');
  188. $this->avatarController->getAvatar('userId', 64);
  189. }
  190. public function testGetAvatarSize512(): void {
  191. $this->avatarMock->expects($this->once())
  192. ->method('getFile')
  193. ->with($this->equalTo(512))
  194. ->willReturn($this->avatarFile);
  195. $this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
  196. $this->logger->expects($this->never())
  197. ->method('debug');
  198. $this->avatarController->getAvatar('userId', 512);
  199. }
  200. /**
  201. * Small sizes return 64 and generate a log
  202. */
  203. public function testGetAvatarSizeTooSmall(): void {
  204. $this->avatarMock->expects($this->once())
  205. ->method('getFile')
  206. ->with($this->equalTo(64))
  207. ->willReturn($this->avatarFile);
  208. $this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
  209. $this->logger->expects($this->once())
  210. ->method('debug')
  211. ->with('Avatar requested in deprecated size 32');
  212. $this->avatarController->getAvatar('userId', 32);
  213. }
  214. /**
  215. * Avatars between 64 and 512 are upgraded to 512
  216. */
  217. public function testGetAvatarSizeBetween(): void {
  218. $this->avatarMock->expects($this->once())
  219. ->method('getFile')
  220. ->with($this->equalTo(512))
  221. ->willReturn($this->avatarFile);
  222. $this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
  223. $this->logger->expects($this->once())
  224. ->method('debug')
  225. ->with('Avatar requested in deprecated size 65');
  226. $this->avatarController->getAvatar('userId', 65);
  227. }
  228. /**
  229. * We do not support avatars larger than 512
  230. */
  231. public function testGetAvatarSizeTooBig(): void {
  232. $this->avatarMock->expects($this->once())
  233. ->method('getFile')
  234. ->with($this->equalTo(512))
  235. ->willReturn($this->avatarFile);
  236. $this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
  237. $this->logger->expects($this->once())
  238. ->method('debug')
  239. ->with('Avatar requested in deprecated size 513');
  240. $this->avatarController->getAvatar('userId', 513);
  241. }
  242. /**
  243. * Remove an avatar
  244. */
  245. public function testDeleteAvatar() {
  246. $this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
  247. $response = $this->avatarController->deleteAvatar();
  248. $this->assertEquals(Http::STATUS_OK, $response->getStatus());
  249. }
  250. /**
  251. * Test what happens if the removing of the avatar fails
  252. */
  253. public function testDeleteAvatarException() {
  254. $this->avatarMock->method('remove')->will($this->throwException(new \Exception("foo")));
  255. $this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
  256. $this->logger->expects($this->once())
  257. ->method('error')
  258. ->with('foo', ['exception' => new \Exception("foo"), 'app' => 'core']);
  259. $expectedResponse = new Http\JSONResponse(['data' => ['message' => 'An error occurred. Please contact your admin.']], Http::STATUS_BAD_REQUEST);
  260. $this->assertEquals($expectedResponse, $this->avatarController->deleteAvatar());
  261. }
  262. /**
  263. * Trying to get a tmp avatar when it is not available. 404
  264. */
  265. public function testTmpAvatarNoTmp() {
  266. $response = $this->avatarController->getTmpAvatar();
  267. $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
  268. }
  269. /**
  270. * Fetch tmp avatar
  271. */
  272. public function testTmpAvatarValid() {
  273. $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
  274. $response = $this->avatarController->getTmpAvatar();
  275. $this->assertEquals(Http::STATUS_OK, $response->getStatus());
  276. }
  277. /**
  278. * When trying to post a new avatar a path or image should be posted.
  279. */
  280. public function testPostAvatarNoPathOrImage() {
  281. $response = $this->avatarController->postAvatar(null);
  282. $this->assertEquals(Http::STATUS_BAD_REQUEST, $response->getStatus());
  283. }
  284. /**
  285. * Test a correct post of an avatar using POST
  286. */
  287. public function testPostAvatarFile() {
  288. //Create temp file
  289. $fileName = tempnam('', "avatarTest");
  290. $copyRes = copy(\OC::$SERVERROOT.'/tests/data/testimage.jpg', $fileName);
  291. $this->assertTrue($copyRes);
  292. //Create file in cache
  293. $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
  294. //Create request return
  295. $reqRet = ['error' => [0], 'tmp_name' => [$fileName], 'size' => [filesize(\OC::$SERVERROOT.'/tests/data/testimage.jpg')]];
  296. $this->request->method('getUploadedFile')->willReturn($reqRet);
  297. $response = $this->avatarController->postAvatar(null);
  298. //On correct upload always respond with the notsquare message
  299. $this->assertEquals('notsquare', $response->getData()['data']);
  300. //File should be deleted
  301. $this->assertFalse(file_exists($fileName));
  302. }
  303. /**
  304. * Test invalid post os an avatar using POST
  305. */
  306. public function testPostAvatarInvalidFile() {
  307. //Create request return
  308. $reqRet = ['error' => [1], 'tmp_name' => ['foo']];
  309. $this->request->method('getUploadedFile')->willReturn($reqRet);
  310. $response = $this->avatarController->postAvatar(null);
  311. $this->assertEquals(Http::STATUS_BAD_REQUEST, $response->getStatus());
  312. }
  313. /**
  314. * Check what happens when we upload a GIF
  315. */
  316. public function testPostAvatarFileGif() {
  317. //Create temp file
  318. $fileName = tempnam('', "avatarTest");
  319. $copyRes = copy(\OC::$SERVERROOT.'/tests/data/testimage.gif', $fileName);
  320. $this->assertTrue($copyRes);
  321. //Create file in cache
  322. $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.gif'));
  323. //Create request return
  324. $reqRet = ['error' => [0], 'tmp_name' => [$fileName], 'size' => [filesize(\OC::$SERVERROOT.'/tests/data/testimage.gif')]];
  325. $this->request->method('getUploadedFile')->willReturn($reqRet);
  326. $response = $this->avatarController->postAvatar(null);
  327. $this->assertEquals('Unknown filetype', $response->getData()['data']['message']);
  328. //File should be deleted
  329. $this->assertFalse(file_exists($fileName));
  330. }
  331. /**
  332. * Test posting avatar from existing file
  333. */
  334. public function testPostAvatarFromFile() {
  335. //Mock node API call
  336. $file = $this->getMockBuilder('OCP\Files\File')
  337. ->disableOriginalConstructor()->getMock();
  338. $file->expects($this->once())
  339. ->method('getContent')
  340. ->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
  341. $file->expects($this->once())
  342. ->method('getMimeType')
  343. ->willReturn('image/jpeg');
  344. $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock();
  345. $this->rootFolder->method('getUserFolder')->with('userid')->willReturn($userFolder);
  346. $userFolder->method('get')->willReturn($file);
  347. //Create request return
  348. $response = $this->avatarController->postAvatar('avatar.jpg');
  349. //On correct upload always respond with the notsquare message
  350. $this->assertEquals('notsquare', $response->getData()['data']);
  351. }
  352. /**
  353. * Test posting avatar from existing folder
  354. */
  355. public function testPostAvatarFromNoFile() {
  356. $file = $this->getMockBuilder('OCP\Files\Node')->getMock();
  357. $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock();
  358. $this->rootFolder->method('getUserFolder')->with('userid')->willReturn($userFolder);
  359. $userFolder
  360. ->method('get')
  361. ->with('folder')
  362. ->willReturn($file);
  363. //Create request return
  364. $response = $this->avatarController->postAvatar('folder');
  365. //On correct upload always respond with the notsquare message
  366. $this->assertEquals(['data' => ['message' => 'Please select a file.']], $response->getData());
  367. }
  368. public function testPostAvatarInvalidType() {
  369. $file = $this->getMockBuilder('OCP\Files\File')
  370. ->disableOriginalConstructor()->getMock();
  371. $file->expects($this->never())
  372. ->method('getContent');
  373. $file->expects($this->exactly(2))
  374. ->method('getMimeType')
  375. ->willReturn('text/plain');
  376. $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock();
  377. $this->rootFolder->method('getUserFolder')->with('userid')->willReturn($userFolder);
  378. $userFolder->method('get')->willReturn($file);
  379. $expectedResponse = new Http\JSONResponse(['data' => ['message' => 'The selected file is not an image.']], Http::STATUS_BAD_REQUEST);
  380. $this->assertEquals($expectedResponse, $this->avatarController->postAvatar('avatar.jpg'));
  381. }
  382. public function testPostAvatarNotPermittedException() {
  383. $file = $this->getMockBuilder('OCP\Files\File')
  384. ->disableOriginalConstructor()->getMock();
  385. $file->expects($this->once())
  386. ->method('getContent')
  387. ->willThrowException(new NotPermittedException());
  388. $file->expects($this->once())
  389. ->method('getMimeType')
  390. ->willReturn('image/jpeg');
  391. $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock();
  392. $this->rootFolder->method('getUserFolder')->with('userid')->willReturn($userFolder);
  393. $userFolder->method('get')->willReturn($file);
  394. $expectedResponse = new Http\JSONResponse(['data' => ['message' => 'The selected file cannot be read.']], Http::STATUS_BAD_REQUEST);
  395. $this->assertEquals($expectedResponse, $this->avatarController->postAvatar('avatar.jpg'));
  396. }
  397. /**
  398. * Test what happens if the upload of the avatar fails
  399. */
  400. public function testPostAvatarException() {
  401. $this->cache->expects($this->once())
  402. ->method('set')
  403. ->will($this->throwException(new \Exception("foo")));
  404. $file = $this->getMockBuilder('OCP\Files\File')
  405. ->disableOriginalConstructor()->getMock();
  406. $file->expects($this->once())
  407. ->method('getContent')
  408. ->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
  409. $file->expects($this->once())
  410. ->method('getMimeType')
  411. ->willReturn('image/jpeg');
  412. $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock();
  413. $this->rootFolder->method('getUserFolder')->with('userid')->willReturn($userFolder);
  414. $userFolder->method('get')->willReturn($file);
  415. $this->logger->expects($this->once())
  416. ->method('error')
  417. ->with('foo', ['exception' => new \Exception("foo"), 'app' => 'core']);
  418. $expectedResponse = new Http\JSONResponse(['data' => ['message' => 'An error occurred. Please contact your admin.']], Http::STATUS_OK);
  419. $this->assertEquals($expectedResponse, $this->avatarController->postAvatar('avatar.jpg'));
  420. }
  421. /**
  422. * Test invalid crop argument
  423. */
  424. public function testPostCroppedAvatarInvalidCrop() {
  425. $response = $this->avatarController->postCroppedAvatar([]);
  426. $this->assertEquals(Http::STATUS_BAD_REQUEST, $response->getStatus());
  427. }
  428. /**
  429. * Test no tmp avatar to crop
  430. */
  431. public function testPostCroppedAvatarNoTmpAvatar() {
  432. $response = $this->avatarController->postCroppedAvatar(['x' => 0, 'y' => 0, 'w' => 10, 'h' => 10]);
  433. $this->assertEquals(Http::STATUS_BAD_REQUEST, $response->getStatus());
  434. }
  435. /**
  436. * Test with non square crop
  437. */
  438. public function testPostCroppedAvatarNoSquareCrop() {
  439. $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
  440. $this->avatarMock->method('set')->will($this->throwException(new \OC\NotSquareException));
  441. $this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
  442. $response = $this->avatarController->postCroppedAvatar(['x' => 0, 'y' => 0, 'w' => 10, 'h' => 11]);
  443. $this->assertEquals(Http::STATUS_BAD_REQUEST, $response->getStatus());
  444. }
  445. /**
  446. * Check for proper reply on proper crop argument
  447. */
  448. public function testPostCroppedAvatarValidCrop() {
  449. $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
  450. $this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
  451. $response = $this->avatarController->postCroppedAvatar(['x' => 0, 'y' => 0, 'w' => 10, 'h' => 10]);
  452. $this->assertEquals(Http::STATUS_OK, $response->getStatus());
  453. $this->assertEquals('success', $response->getData()['status']);
  454. }
  455. /**
  456. * Test what happens if the cropping of the avatar fails
  457. */
  458. public function testPostCroppedAvatarException() {
  459. $this->cache->method('get')->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
  460. $this->avatarMock->method('set')->will($this->throwException(new \Exception('foo')));
  461. $this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
  462. $this->logger->expects($this->once())
  463. ->method('error')
  464. ->with('foo', ['exception' => new \Exception("foo"), 'app' => 'core']);
  465. $expectedResponse = new Http\JSONResponse(['data' => ['message' => 'An error occurred. Please contact your admin.']], Http::STATUS_BAD_REQUEST);
  466. $this->assertEquals($expectedResponse, $this->avatarController->postCroppedAvatar(['x' => 0, 'y' => 0, 'w' => 10, 'h' => 11]));
  467. }
  468. /**
  469. * Check for proper reply on proper crop argument
  470. */
  471. public function testFileTooBig() {
  472. $fileName = \OC::$SERVERROOT.'/tests/data/testimage.jpg';
  473. //Create request return
  474. $reqRet = ['error' => [0], 'tmp_name' => [$fileName], 'size' => [21 * 1024 * 1024]];
  475. $this->request->method('getUploadedFile')->willReturn($reqRet);
  476. $response = $this->avatarController->postAvatar(null);
  477. $this->assertEquals('File is too big', $response->getData()['data']['message']);
  478. }
  479. }