1
0

User_ProxyTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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\IConfig;
  14. use OCP\IUserSession;
  15. use OCP\Notification\IManager as INotificationManager;
  16. use PHPUnit\Framework\MockObject\MockObject;
  17. use Psr\Log\LoggerInterface;
  18. use Test\TestCase;
  19. class User_ProxyTest extends TestCase {
  20. /** @var Helper|MockObject */
  21. protected $helper;
  22. /** @var ILDAPWrapper|MockObject */
  23. private $ldapWrapper;
  24. /** @var AccessFactory|MockObject */
  25. private $accessFactory;
  26. /** @var IConfig|MockObject */
  27. private $config;
  28. /** @var INotificationManager|MockObject */
  29. private $notificationManager;
  30. /** @var IUserSession|MockObject */
  31. private $userSession;
  32. /** @var User_Proxy|MockObject */
  33. private $proxy;
  34. /** @var UserPluginManager|MockObject */
  35. private $userPluginManager;
  36. /** @var LoggerInterface|MockObject */
  37. protected $logger;
  38. /** @var DeletedUsersIndex|MockObject */
  39. protected $deletedUsersIndex;
  40. protected function setUp(): void {
  41. parent::setUp();
  42. $this->helper = $this->createMock(Helper::class);
  43. $this->ldapWrapper = $this->createMock(ILDAPWrapper::class);
  44. $this->accessFactory = $this->createMock(AccessFactory::class);
  45. $this->config = $this->createMock(IConfig::class);
  46. $this->notificationManager = $this->createMock(INotificationManager::class);
  47. $this->userSession = $this->createMock(IUserSession::class);
  48. $this->userPluginManager = $this->createMock(UserPluginManager::class);
  49. $this->logger = $this->createMock(LoggerInterface::class);
  50. $this->deletedUsersIndex = $this->createMock(DeletedUsersIndex::class);
  51. $this->proxy = $this->getMockBuilder(User_Proxy::class)
  52. ->setConstructorArgs([
  53. $this->helper,
  54. $this->ldapWrapper,
  55. $this->accessFactory,
  56. $this->config,
  57. $this->notificationManager,
  58. $this->userSession,
  59. $this->userPluginManager,
  60. $this->logger,
  61. $this->deletedUsersIndex,
  62. ])
  63. ->setMethods(['handleRequest'])
  64. ->getMock();
  65. }
  66. public function testSetPassword() {
  67. $this->proxy
  68. ->expects($this->once())
  69. ->method('handleRequest')
  70. ->with('MyUid', 'setPassword', ['MyUid', 'MyPassword'])
  71. ->willReturn(true);
  72. $this->assertTrue($this->proxy->setPassword('MyUid', 'MyPassword'));
  73. }
  74. public function testSetDisplayName() {
  75. $this->proxy
  76. ->expects($this->once())
  77. ->method('handleRequest')
  78. ->with('MyUid', 'setDisplayName', ['MyUid', 'MyPassword'])
  79. ->willReturn(true);
  80. $this->assertTrue($this->proxy->setDisplayName('MyUid', 'MyPassword'));
  81. }
  82. public function testCreateUser() {
  83. $this->proxy
  84. ->expects($this->once())
  85. ->method('handleRequest')
  86. ->with('MyUid', 'createUser', ['MyUid', 'MyPassword'])
  87. ->willReturn(true);
  88. $this->assertTrue($this->proxy->createUser('MyUid', 'MyPassword'));
  89. }
  90. }