Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
  • Loading branch information
rullzer committed Nov 9, 2017
1 parent 6114b61 commit 3e2ca98
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions tests/lib/AvatarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use OC\User\User;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
Expand Down Expand Up @@ -49,7 +51,35 @@ public function setUp() {
}

public function testGetNoAvatar() {
$this->assertEquals(false, $this->avatar->get());
$file = $this->createMock(ISimpleFile::class);
$this->folder->method('newFile')
->willReturn($file);

$this->folder->method('getFile')
->will($this->returnCallback(function($path) {
if ($path === 'avatar.64.png') {
throw new NotFoundException();
}
}));
$this->folder->method('fileExists')
->will($this->returnCallback(function($path) {
if ($path === 'generated') {
return true;
}
return false;
}));

$data = NULL;
$file->method('putContent')
->with($this->callback(function ($d) use (&$data) {
$data = $d;
return true;
}));

$file->method('getContent')
->willReturn($data);

$this->assertEquals($data, $this->avatar->get()->data());
}

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

$nonAvatarFile = $this->createMock(File::class);
$nonAvatarFile->method('getName')
->willReturn('avatarX');
$nonAvatarFile->expects($this->never())->method('delete');

$this->folder->method('getDirectoryListing')
->willReturn([$avatarFileJPG, $avatarFilePNG, $resizedAvatarFile, $nonAvatarFile]);
->willReturn([$avatarFileJPG, $avatarFilePNG, $resizedAvatarFile]);

$generated = $this->createMock(File::class);
$this->folder->method('getFile')
->with('generated')
->willReturn($generated);

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

0 comments on commit 3e2ca98

Please sign in to comment.