AvatarControllerTest.php 20 KB

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