GuestAvatarControllerTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Core\Controller;
  3. use OC\Core\Controller\GuestAvatarController;
  4. use OCP\AppFramework\Http\FileDisplayResponse;
  5. use OCP\Files\SimpleFS\ISimpleFile;
  6. use OCP\IAvatar;
  7. use OCP\IAvatarManager;
  8. use OCP\ILogger;
  9. use OCP\IRequest;
  10. /**
  11. * This class provides tests for the guest avatar controller.
  12. */
  13. class GuestAvatarControllerTest extends \Test\TestCase {
  14. /**
  15. * @var GuestAvatarController
  16. */
  17. private $guestAvatarController;
  18. /**
  19. * @var IRequest|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. private $request;
  22. /**
  23. * @var IAvatarManager|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. private $avatarManager;
  26. /**
  27. * @var IAvatar|\PHPUnit_Framework_MockObject_MockObject
  28. */
  29. private $avatar;
  30. /**
  31. * @var \OCP\Files\File|\PHPUnit_Framework_MockObject_MockObject
  32. */
  33. private $file;
  34. /**
  35. * @var ILogger|\PHPUnit_Framework_MockObject_MockObject
  36. */
  37. private $logger;
  38. /**
  39. * Sets up the test environment.
  40. */
  41. protected function setUp() {
  42. parent::setUp();
  43. $this->logger = $this->getMockBuilder(ILogger::class)->getMock();
  44. $this->request = $this->getMockBuilder(IRequest::class)->getMock();
  45. $this->avatar = $this->getMockBuilder(IAvatar::class)->getMock();
  46. $this->avatarManager = $this->getMockBuilder(IAvatarManager::class)->getMock();
  47. $this->file = $this->getMockBuilder(ISimpleFile::class)->getMock();
  48. $this->guestAvatarController = new GuestAvatarController(
  49. 'core',
  50. $this->request,
  51. $this->avatarManager,
  52. $this->logger
  53. );
  54. }
  55. /**
  56. * Tests getAvatar returns the guest avatar.
  57. */
  58. public function testGetAvatar() {
  59. $this->avatarManager->expects($this->once())
  60. ->method('getGuestAvatar')
  61. ->with('Peter')
  62. ->willReturn($this->avatar);
  63. $this->avatar->expects($this->once())
  64. ->method('getFile')
  65. ->with(128)
  66. ->willReturn($this->file);
  67. $this->file->method('getMimeType')
  68. ->willReturn('image/svg+xml');
  69. $response = $this->guestAvatarController->getAvatar('Peter', 128);
  70. $this->assertGreaterThanOrEqual(201, $response->getStatus());
  71. $this->assertInstanceOf(FileDisplayResponse::class, $response);
  72. }
  73. }