aboutsummaryrefslogtreecommitdiffstats
path: root/tests/Core/Controller/GuestAvatarControllerTest.php
blob: dd8188b002f7e3d550e565575de98d91efa5c4ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?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(): void {
		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);
	}
}