diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2017-11-09 11:34:50 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2017-11-29 14:23:15 +0100 |
commit | 8e8fe6b8ebc4b3ad32a72e1262aed82c96a52b36 (patch) | |
tree | 929911b46ea61ef5c71dba5a5c7ef213b2c5c67f /tests | |
parent | d5496dc435eeff931ab1d540ea4b069520e88e12 (diff) | |
download | nextcloud-server-8e8fe6b8ebc4b3ad32a72e1262aed82c96a52b36.tar.gz nextcloud-server-8e8fe6b8ebc4b3ad32a72e1262aed82c96a52b36.zip |
Fix tests
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Core/Controller/AvatarControllerTest.php | 8 | ||||
-rw-r--r-- | tests/lib/AvatarTest.php | 44 |
2 files changed, 39 insertions, 13 deletions
diff --git a/tests/Core/Controller/AvatarControllerTest.php b/tests/Core/Controller/AvatarControllerTest.php index de568438022..3194d671908 100644 --- a/tests/Core/Controller/AvatarControllerTest.php +++ b/tests/Core/Controller/AvatarControllerTest.php @@ -134,9 +134,7 @@ class AvatarControllerTest extends \Test\TestCase { $response = $this->avatarController->getAvatar('userId', 32); //Comment out until JS is fixed - //$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); - $this->assertEquals(Http::STATUS_OK, $response->getStatus()); - $this->assertEquals('displayName', $response->getData()['data']['displayname']); + $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); } /** @@ -167,9 +165,7 @@ class AvatarControllerTest extends \Test\TestCase { $response = $this->avatarController->getAvatar('userDoesNotExist', 32); //Comment out until JS is fixed - //$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); - $this->assertEquals(Http::STATUS_OK, $response->getStatus()); - $this->assertEquals('userDoesNotExist', $response->getData()['data']['displayname']); + $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); } /** diff --git a/tests/lib/AvatarTest.php b/tests/lib/AvatarTest.php index cea3f9bed1a..240aecc115e 100644 --- a/tests/lib/AvatarTest.php +++ b/tests/lib/AvatarTest.php @@ -12,6 +12,8 @@ use OC\Files\SimpleFS\SimpleFolder; 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; @@ -49,7 +51,35 @@ class AvatarTest extends \Test\TestCase { } 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() { @@ -161,13 +191,13 @@ class AvatarTest extends \Test\TestCase { ->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()) |