User_ProxyTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Roger Szabo <roger.szabo@web.de>
  9. * @author Vinicius Cubas Brand <vinicius@eita.org.br>
  10. *
  11. * @license GNU AGPL version 3 or any later version
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. */
  27. namespace OCA\User_LDAP\Tests;
  28. use OCA\User_LDAP\ILDAPWrapper;
  29. use OCA\User_LDAP\User_Proxy;
  30. use OCA\User_LDAP\UserPluginManager;
  31. use OCP\IConfig;
  32. use OCP\IUserSession;
  33. use OCP\Notification\IManager as INotificationManager;
  34. use Test\TestCase;
  35. class User_ProxyTest extends TestCase {
  36. /** @var ILDAPWrapper|\PHPUnit_Framework_MockObject_MockObject */
  37. private $ldapWrapper;
  38. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  39. private $config;
  40. /** @var INotificationManager|\PHPUnit_Framework_MockObject_MockObject */
  41. private $notificationManager;
  42. /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
  43. private $userSession;
  44. /** @var User_Proxy|\PHPUnit_Framework_MockObject_MockObject */
  45. private $proxy;
  46. /** @var UserPluginManager|\PHPUnit_Framework_MockObject_MockObject */
  47. private $userPluginManager;
  48. protected function setUp(): void {
  49. parent::setUp();
  50. $this->ldapWrapper = $this->createMock(ILDAPWrapper::class);
  51. $this->config = $this->createMock(IConfig::class);
  52. $this->notificationManager = $this->createMock(INotificationManager::class);
  53. $this->userSession = $this->createMock(IUserSession::class);
  54. $this->userPluginManager = $this->createMock(UserPluginManager::class);
  55. $this->proxy = $this->getMockBuilder(User_Proxy::class)
  56. ->setConstructorArgs([
  57. [],
  58. $this->ldapWrapper,
  59. $this->config,
  60. $this->notificationManager,
  61. $this->userSession,
  62. $this->userPluginManager
  63. ])
  64. ->setMethods(['handleRequest'])
  65. ->getMock();
  66. }
  67. public function testSetPassword() {
  68. $this->proxy
  69. ->expects($this->once())
  70. ->method('handleRequest')
  71. ->with('MyUid', 'setPassword', ['MyUid', 'MyPassword'])
  72. ->willReturn(true);
  73. $this->assertTrue($this->proxy->setPassword('MyUid', 'MyPassword'));
  74. }
  75. public function testSetDisplayName() {
  76. $this->proxy
  77. ->expects($this->once())
  78. ->method('handleRequest')
  79. ->with('MyUid', 'setDisplayName', ['MyUid', 'MyPassword'])
  80. ->willReturn(true);
  81. $this->assertTrue($this->proxy->setDisplayName('MyUid', 'MyPassword')); }
  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. }