User_ProxyTest.php 3.6 KB

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