|
12 | 12 | use OC\User\User; |
13 | 13 | use OCP\Files\File; |
14 | 14 | use OCP\Files\Folder; |
| 15 | +use OCP\Files\NotFoundException; |
| 16 | +use OCP\Files\SimpleFS\ISimpleFile; |
15 | 17 | use OCP\IConfig; |
16 | 18 | use OCP\IL10N; |
17 | 19 | use OCP\ILogger; |
@@ -49,7 +51,35 @@ public function setUp() { |
49 | 51 | } |
50 | 52 |
|
51 | 53 | public function testGetNoAvatar() { |
52 | | - $this->assertEquals(false, $this->avatar->get()); |
| 54 | + $file = $this->createMock(ISimpleFile::class); |
| 55 | + $this->folder->method('newFile') |
| 56 | + ->willReturn($file); |
| 57 | + |
| 58 | + $this->folder->method('getFile') |
| 59 | + ->will($this->returnCallback(function($path) { |
| 60 | + if ($path === 'avatar.64.png') { |
| 61 | + throw new NotFoundException(); |
| 62 | + } |
| 63 | + })); |
| 64 | + $this->folder->method('fileExists') |
| 65 | + ->will($this->returnCallback(function($path) { |
| 66 | + if ($path === 'generated') { |
| 67 | + return true; |
| 68 | + } |
| 69 | + return false; |
| 70 | + })); |
| 71 | + |
| 72 | + $data = NULL; |
| 73 | + $file->method('putContent') |
| 74 | + ->with($this->callback(function ($d) use (&$data) { |
| 75 | + $data = $d; |
| 76 | + return true; |
| 77 | + })); |
| 78 | + |
| 79 | + $file->method('getContent') |
| 80 | + ->willReturn($data); |
| 81 | + |
| 82 | + $this->assertEquals($data, $this->avatar->get()->data()); |
53 | 83 | } |
54 | 84 |
|
55 | 85 | public function testGetAvatarSizeMatch() { |
@@ -161,13 +191,13 @@ public function testSetAvatar() { |
161 | 191 | ->willReturn('avatar.32.jpg'); |
162 | 192 | $resizedAvatarFile->expects($this->once())->method('delete'); |
163 | 193 |
|
164 | | - $nonAvatarFile = $this->createMock(File::class); |
165 | | - $nonAvatarFile->method('getName') |
166 | | - ->willReturn('avatarX'); |
167 | | - $nonAvatarFile->expects($this->never())->method('delete'); |
168 | | - |
169 | 194 | $this->folder->method('getDirectoryListing') |
170 | | - ->willReturn([$avatarFileJPG, $avatarFilePNG, $resizedAvatarFile, $nonAvatarFile]); |
| 195 | + ->willReturn([$avatarFileJPG, $avatarFilePNG, $resizedAvatarFile]); |
| 196 | + |
| 197 | + $generated = $this->createMock(File::class); |
| 198 | + $this->folder->method('getFile') |
| 199 | + ->with('generated') |
| 200 | + ->willReturn($generated); |
171 | 201 |
|
172 | 202 | $newFile = $this->createMock(File::class); |
173 | 203 | $this->folder->expects($this->once()) |
|
0 commit comments