User_ProxyTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\User_LDAP\Tests;
  7. use OCA\User_LDAP\AccessFactory;
  8. use OCA\User_LDAP\Helper;
  9. use OCA\User_LDAP\ILDAPWrapper;
  10. use OCA\User_LDAP\User\DeletedUsersIndex;
  11. use OCA\User_LDAP\User_Proxy;
  12. use OCA\User_LDAP\UserPluginManager;
  13. use OCP\Notification\IManager as INotificationManager;
  14. use PHPUnit\Framework\MockObject\MockObject;
  15. use Psr\Log\LoggerInterface;
  16. use Test\TestCase;
  17. class User_ProxyTest extends TestCase {
  18. /** @var Helper|MockObject */
  19. protected $helper;
  20. /** @var ILDAPWrapper|MockObject */
  21. private $ldapWrapper;
  22. /** @var AccessFactory|MockObject */
  23. private $accessFactory;
  24. /** @var INotificationManager|MockObject */
  25. private $notificationManager;
  26. /** @var User_Proxy|MockObject */
  27. private $proxy;
  28. /** @var UserPluginManager|MockObject */
  29. private $userPluginManager;
  30. /** @var LoggerInterface|MockObject */
  31. protected $logger;
  32. /** @var DeletedUsersIndex|MockObject */
  33. protected $deletedUsersIndex;
  34. protected function setUp(): void {
  35. parent::setUp();
  36. $this->helper = $this->createMock(Helper::class);
  37. $this->ldapWrapper = $this->createMock(ILDAPWrapper::class);
  38. $this->accessFactory = $this->createMock(AccessFactory::class);
  39. $this->notificationManager = $this->createMock(INotificationManager::class);
  40. $this->userPluginManager = $this->createMock(UserPluginManager::class);
  41. $this->logger = $this->createMock(LoggerInterface::class);
  42. $this->deletedUsersIndex = $this->createMock(DeletedUsersIndex::class);
  43. $this->proxy = $this->getMockBuilder(User_Proxy::class)
  44. ->setConstructorArgs([
  45. $this->helper,
  46. $this->ldapWrapper,
  47. $this->accessFactory,
  48. $this->notificationManager,
  49. $this->userPluginManager,
  50. $this->logger,
  51. $this->deletedUsersIndex,
  52. ])
  53. ->setMethods(['handleRequest'])
  54. ->getMock();
  55. }
  56. public function testSetPassword() {
  57. $this->proxy
  58. ->expects($this->once())
  59. ->method('handleRequest')
  60. ->with('MyUid', 'setPassword', ['MyUid', 'MyPassword'])
  61. ->willReturn(true);
  62. $this->assertTrue($this->proxy->setPassword('MyUid', 'MyPassword'));
  63. }
  64. public function testSetDisplayName() {
  65. $this->proxy
  66. ->expects($this->once())
  67. ->method('handleRequest')
  68. ->with('MyUid', 'setDisplayName', ['MyUid', 'MyPassword'])
  69. ->willReturn(true);
  70. $this->assertTrue($this->proxy->setDisplayName('MyUid', 'MyPassword'));
  71. }
  72. public function testCreateUser() {
  73. $this->proxy
  74. ->expects($this->once())
  75. ->method('handleRequest')
  76. ->with('MyUid', 'createUser', ['MyUid', 'MyPassword'])
  77. ->willReturn(true);
  78. $this->assertTrue($this->proxy->createUser('MyUid', 'MyPassword'));
  79. }
  80. }