You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AvatarManagerTest.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * @author Roeland Jago Douma <rullzer@owncloud.com>
  4. * @author Lukas Reschke <lukas@statuscode.ch>
  5. *
  6. * @copyright Copyright (c) 2015, ownCloud, Inc.
  7. * @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace Test;
  25. use OC\Avatar;
  26. use OC\AvatarManager;
  27. use OC\Files\AppData\AppData;
  28. use OCP\Files\IAppData;
  29. use OCP\Files\SimpleFS\ISimpleFolder;
  30. use OCP\IConfig;
  31. use OCP\IL10N;
  32. use OCP\ILogger;
  33. use OCP\IUser;
  34. use OCP\IUserManager;
  35. /**
  36. * Class AvatarManagerTest
  37. */
  38. class AvatarManagerTest extends \Test\TestCase {
  39. /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
  40. private $userManager;
  41. /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
  42. private $appData;
  43. /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
  44. private $l10n;
  45. /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
  46. private $logger;
  47. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  48. private $config;
  49. /** @var AvatarManager | \PHPUnit_Framework_MockObject_MockObject */
  50. private $avatarManager;
  51. public function setUp() {
  52. parent::setUp();
  53. $this->userManager = $this->createMock(IUserManager::class);
  54. $this->appData = $this->createMock(IAppData::class);
  55. $this->l10n = $this->createMock(IL10N::class);
  56. $this->logger = $this->createMock(ILogger::class);
  57. $this->config = $this->createMock(IConfig::class);
  58. $this->avatarManager = new AvatarManager(
  59. $this->userManager,
  60. $this->appData,
  61. $this->l10n,
  62. $this->logger,
  63. $this->config
  64. );
  65. }
  66. /**
  67. * @expectedException \Exception
  68. * @expectedExceptionMessage user does not exist
  69. */
  70. public function testGetAvatarInvalidUser() {
  71. $this->userManager
  72. ->expects($this->once())
  73. ->method('get')
  74. ->with('invalidUser')
  75. ->willReturn(null);
  76. $this->avatarManager->getAvatar('invalidUser');
  77. }
  78. public function testGetAvatarValidUser() {
  79. $user = $this->createMock(IUser::class);
  80. $user
  81. ->expects($this->once())
  82. ->method('getUID')
  83. ->willReturn('valid-user');
  84. $this->userManager
  85. ->expects($this->once())
  86. ->method('get')
  87. ->with('valid-user')
  88. ->willReturn($user);
  89. $folder = $this->createMock(ISimpleFolder::class);
  90. $this->appData
  91. ->expects($this->once())
  92. ->method('getFolder')
  93. ->with('valid-user')
  94. ->willReturn($folder);
  95. $expected = new Avatar($folder, $this->l10n, $user, $this->logger, $this->config);
  96. $this->assertEquals($expected, $this->avatarManager->getAvatar('valid-user'));
  97. }
  98. public function testGetAvatarValidUserDifferentCasing() {
  99. $user = $this->createMock(IUser::class);
  100. $this->userManager->expects($this->once())
  101. ->method('get')
  102. ->with('vaLid-USER')
  103. ->willReturn($user);
  104. $user->expects($this->once())
  105. ->method('getUID')
  106. ->willReturn('valid-user');
  107. $folder = $this->createMock(ISimpleFolder::class);
  108. $this->appData
  109. ->expects($this->once())
  110. ->method('getFolder')
  111. ->with('valid-user')
  112. ->willReturn($folder);
  113. $expected = new Avatar($folder, $this->l10n, $user, $this->logger, $this->config);
  114. $this->assertEquals($expected, $this->avatarManager->getAvatar('vaLid-USER'));
  115. }
  116. }