aboutsummaryrefslogtreecommitdiffstats
path: root/tests/Core/Controller/GuestAvatarControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Core/Controller/GuestAvatarControllerTest.php')
-rw-r--r--tests/Core/Controller/GuestAvatarControllerTest.php95
1 files changed, 95 insertions, 0 deletions
diff --git a/tests/Core/Controller/GuestAvatarControllerTest.php b/tests/Core/Controller/GuestAvatarControllerTest.php
new file mode 100644
index 00000000000..66a83098130
--- /dev/null
+++ b/tests/Core/Controller/GuestAvatarControllerTest.php
@@ -0,0 +1,95 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace Core\Controller;
+
+use OC\Core\Controller\GuestAvatarController;
+use OCP\AppFramework\Http\FileDisplayResponse;
+use OCP\Files\File;
+use OCP\Files\SimpleFS\ISimpleFile;
+use OCP\IAvatar;
+use OCP\IAvatarManager;
+use OCP\IRequest;
+use Psr\Log\LoggerInterface;
+
+/**
+ * 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 File|\PHPUnit\Framework\MockObject\MockObject
+ */
+ private $file;
+
+ /**
+ * @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject
+ */
+ private $logger;
+
+ /**
+ * Sets up the test environment.
+ */
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->logger = $this->getMockBuilder(LoggerInterface::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->file->method('getName')->willReturn('my name');
+ $this->file->method('getMTime')->willReturn(42);
+ $this->guestAvatarController = new GuestAvatarController(
+ 'core',
+ $this->request,
+ $this->avatarManager,
+ $this->logger
+ );
+ }
+
+ /**
+ * Tests getAvatar returns the guest avatar.
+ */
+ public function testGetAvatar(): void {
+ $this->avatarManager->expects($this->once())
+ ->method('getGuestAvatar')
+ ->with('Peter')
+ ->willReturn($this->avatar);
+
+ $this->avatar->expects($this->once())
+ ->method('getFile')
+ ->with(512)
+ ->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);
+ }
+}