Skip to content

Commit 2c67928

Browse files
committed
Fix tests
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
1 parent 061a548 commit 2c67928

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

tests/Core/Controller/AvatarControllerTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ public function testGetAvatarNoAvatar() {
134134
$response = $this->avatarController->getAvatar('userId', 32);
135135

136136
//Comment out until JS is fixed
137-
//$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
138-
$this->assertEquals(Http::STATUS_OK, $response->getStatus());
139-
$this->assertEquals('displayName', $response->getData()['data']['displayname']);
137+
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
140138
}
141139

142140
/**
@@ -167,9 +165,7 @@ public function testGetAvatarNoUser() {
167165
$response = $this->avatarController->getAvatar('userDoesNotExist', 32);
168166

169167
//Comment out until JS is fixed
170-
//$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
171-
$this->assertEquals(Http::STATUS_OK, $response->getStatus());
172-
$this->assertEquals('userDoesNotExist', $response->getData()['data']['displayname']);
168+
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
173169
}
174170

175171
/**

tests/lib/AvatarTest.php

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use OC\User\User;
1313
use OCP\Files\File;
1414
use OCP\Files\Folder;
15+
use OCP\Files\NotFoundException;
16+
use OCP\Files\SimpleFS\ISimpleFile;
1517
use OCP\IConfig;
1618
use OCP\IL10N;
1719
use OCP\ILogger;
@@ -49,7 +51,35 @@ public function setUp() {
4951
}
5052

5153
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());
5383
}
5484

5585
public function testGetAvatarSizeMatch() {
@@ -161,13 +191,13 @@ public function testSetAvatar() {
161191
->willReturn('avatar.32.jpg');
162192
$resizedAvatarFile->expects($this->once())->method('delete');
163193

164-
$nonAvatarFile = $this->createMock(File::class);
165-
$nonAvatarFile->method('getName')
166-
->willReturn('avatarX');
167-
$nonAvatarFile->expects($this->never())->method('delete');
168-
169194
$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);
171201

172202
$newFile = $this->createMock(File::class);
173203
$this->folder->expects($this->once())

0 commit comments

Comments
 (0)