1
0

AvatarManagerTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 OC\User\Manager;
  29. use OCP\Files\IAppData;
  30. use OCP\Files\SimpleFS\ISimpleFolder;
  31. use OCP\IConfig;
  32. use OCP\IL10N;
  33. use OCP\ILogger;
  34. use OCP\IUser;
  35. use OCP\IUserManager;
  36. /**
  37. * Class AvatarManagerTest
  38. */
  39. class AvatarManagerTest extends \Test\TestCase {
  40. /** @var Manager|\PHPUnit_Framework_MockObject_MockObject */
  41. private $userManager;
  42. /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
  43. private $appData;
  44. /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
  45. private $l10n;
  46. /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
  47. private $logger;
  48. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  49. private $config;
  50. /** @var AvatarManager | \PHPUnit_Framework_MockObject_MockObject */
  51. private $avatarManager;
  52. public function setUp() {
  53. parent::setUp();
  54. $this->userManager = $this->createMock(Manager::class);
  55. $this->appData = $this->createMock(IAppData::class);
  56. $this->l10n = $this->createMock(IL10N::class);
  57. $this->logger = $this->createMock(ILogger::class);
  58. $this->config = $this->createMock(IConfig::class);
  59. $this->avatarManager = new AvatarManager(
  60. $this->userManager,
  61. $this->appData,
  62. $this->l10n,
  63. $this->logger,
  64. $this->config
  65. );
  66. }
  67. /**
  68. * @expectedException \Exception
  69. * @expectedExceptionMessage user does not exist
  70. */
  71. public function testGetAvatarInvalidUser() {
  72. $this->userManager
  73. ->expects($this->once())
  74. ->method('get')
  75. ->with('invalidUser')
  76. ->willReturn(null);
  77. $this->avatarManager->getAvatar('invalidUser');
  78. }
  79. public function testGetAvatarValidUser() {
  80. $user = $this->createMock(IUser::class);
  81. $user
  82. ->expects($this->once())
  83. ->method('getUID')
  84. ->willReturn('valid-user');
  85. $this->userManager
  86. ->expects($this->once())
  87. ->method('get')
  88. ->with('valid-user')
  89. ->willReturn($user);
  90. $folder = $this->createMock(ISimpleFolder::class);
  91. $this->appData
  92. ->expects($this->once())
  93. ->method('getFolder')
  94. ->with('valid-user')
  95. ->willReturn($folder);
  96. $expected = new Avatar($folder, $this->l10n, $user, $this->logger, $this->config);
  97. $this->assertEquals($expected, $this->avatarManager->getAvatar('valid-user'));
  98. }
  99. public function testGetAvatarValidUserDifferentCasing() {
  100. $user = $this->createMock(IUser::class);
  101. $this->userManager->expects($this->once())
  102. ->method('get')
  103. ->with('vaLid-USER')
  104. ->willReturn($user);
  105. $user->expects($this->once())
  106. ->method('getUID')
  107. ->willReturn('valid-user');
  108. $folder = $this->createMock(ISimpleFolder::class);
  109. $this->appData
  110. ->expects($this->once())
  111. ->method('getFolder')
  112. ->with('valid-user')
  113. ->willReturn($folder);
  114. $expected = new Avatar($folder, $this->l10n, $user, $this->logger, $this->config);
  115. $this->assertEquals($expected, $this->avatarManager->getAvatar('vaLid-USER'));
  116. }
  117. }