diff options
author | Michael Weimann <mail@michael-weimann.eu> | 2019-01-20 11:13:41 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2019-02-07 14:23:16 +0100 |
commit | bf1253cb49a4931244a6bbde4dfa44bf084f4377 (patch) | |
tree | 6faacd5110c029778ed56554e27a5d73c4e888db /tests/Core | |
parent | b69b17f29fd518495a6495e0f90f60c70ef0fc73 (diff) | |
download | nextcloud-server-bf1253cb49a4931244a6bbde4dfa44bf084f4377.tar.gz nextcloud-server-bf1253cb49a4931244a6bbde4dfa44bf084f4377.zip |
Implement guest avatar endpoint
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
Diffstat (limited to 'tests/Core')
-rw-r--r-- | tests/Core/Controller/AvatarControllerTest.php | 4 | ||||
-rw-r--r-- | tests/Core/Controller/GuestAvatarControllerTest.php | 90 |
2 files changed, 92 insertions, 2 deletions
diff --git a/tests/Core/Controller/AvatarControllerTest.php b/tests/Core/Controller/AvatarControllerTest.php index 3369fa882c8..5fce8fc6359 100644 --- a/tests/Core/Controller/AvatarControllerTest.php +++ b/tests/Core/Controller/AvatarControllerTest.php @@ -53,7 +53,7 @@ use OCP\IUserManager; * @package OC\Core\Controller */ class AvatarControllerTest extends \Test\TestCase { - /** @var \OC\Core\Controller\AvatarController */ + /** @var AvatarController */ private $avatarController; /** @var IAvatar|\PHPUnit_Framework_MockObject_MockObject */ private $avatarMock; @@ -78,7 +78,7 @@ class AvatarControllerTest extends \Test\TestCase { private $request; /** @var TimeFactory|\PHPUnit_Framework_MockObject_MockObject */ private $timeFactory; - + protected function setUp() { parent::setUp(); diff --git a/tests/Core/Controller/GuestAvatarControllerTest.php b/tests/Core/Controller/GuestAvatarControllerTest.php new file mode 100644 index 00000000000..a7c67c684cc --- /dev/null +++ b/tests/Core/Controller/GuestAvatarControllerTest.php @@ -0,0 +1,90 @@ +<?php + +namespace Core\Controller; + +use OC\Core\Controller\GuestAvatarController; +use OCP\AppFramework\Http\FileDisplayResponse; +use OCP\Files\SimpleFS\ISimpleFile; +use OCP\IAvatar; +use OCP\IAvatarManager; +use OCP\ILogger; +use OCP\IRequest; + +/** + * This class provides tests for the guest avatar controller. + */ +class GuestAvatarControllerTest extends \Test\TestCase { + + /** + * @var GuestAvatarController + */ + private $guestAvatarController; + + /** + * @var IRequest|\PHPUnit_Framework_MockObject_MockObject + */ + private $request; + + /** + * @var IAvatarManager|\PHPUnit_Framework_MockObject_MockObject + */ + private $avatarManager; + + /** + * @var IAvatar|\PHPUnit_Framework_MockObject_MockObject + */ + private $avatar; + + /** + * @var \OCP\Files\File|\PHPUnit_Framework_MockObject_MockObject + */ + private $file; + + /** + * @var ILogger|\PHPUnit_Framework_MockObject_MockObject + */ + private $logger; + + /** + * Sets up the test environment. + */ + protected function setUp() { + parent::setUp(); + + $this->logger = $this->getMockBuilder(ILogger::class)->getMock(); + $this->request = $this->getMockBuilder(IRequest::class)->getMock(); + $this->avatar = $this->getMockBuilder(IAvatar::class)->getMock(); + $this->avatarManager = $this->getMockBuilder(IAvatarManager::class)->getMock(); + $this->file = $this->getMockBuilder(ISimpleFile::class)->getMock(); + $this->guestAvatarController = new GuestAvatarController( + 'core', + $this->request, + $this->avatarManager, + $this->logger + ); + } + + /** + * Tests getAvatar returns the guest avatar. + */ + public function testGetAvatar() { + $this->avatarManager->expects($this->once()) + ->method('getGuestAvatar') + ->with('Peter') + ->willReturn($this->avatar); + + $this->avatar->expects($this->once()) + ->method('getFile') + ->with(128) + ->willReturn($this->file); + + $this->file->method('getMimeType') + ->willReturn('image/svg+xml'); + + $response = $this->guestAvatarController->getAvatar('Peter', 128); + + $this->assertGreaterThanOrEqual(201, $response->getStatus()); + $this->assertInstanceOf(FileDisplayResponse::class, $response); + $this->assertSame($this->file, $response->getFile()); + } +} |