User_ProxyTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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\AccessFactory;
  31. use OCA\User_LDAP\Helper;
  32. use OCA\User_LDAP\ILDAPWrapper;
  33. use OCA\User_LDAP\User_Proxy;
  34. use OCA\User_LDAP\UserPluginManager;
  35. use OCP\IConfig;
  36. use OCP\IUserSession;
  37. use OCP\Notification\IManager as INotificationManager;
  38. use PHPUnit\Framework\MockObject\MockObject;
  39. use Test\TestCase;
  40. class User_ProxyTest extends TestCase {
  41. /** @var Helper|MockObject */
  42. protected $helper;
  43. /** @var ILDAPWrapper|MockObject */
  44. private $ldapWrapper;
  45. /** @var AccessFactory|MockObject */
  46. private $accessFactory;
  47. /** @var IConfig|MockObject */
  48. private $config;
  49. /** @var INotificationManager|MockObject */
  50. private $notificationManager;
  51. /** @var IUserSession|MockObject */
  52. private $userSession;
  53. /** @var User_Proxy|MockObject */
  54. private $proxy;
  55. /** @var UserPluginManager|MockObject */
  56. private $userPluginManager;
  57. protected function setUp(): void {
  58. parent::setUp();
  59. $this->helper = $this->createMock(Helper::class);
  60. $this->ldapWrapper = $this->createMock(ILDAPWrapper::class);
  61. $this->accessFactory = $this->createMock(AccessFactory::class);
  62. $this->config = $this->createMock(IConfig::class);
  63. $this->notificationManager = $this->createMock(INotificationManager::class);
  64. $this->userSession = $this->createMock(IUserSession::class);
  65. $this->userPluginManager = $this->createMock(UserPluginManager::class);
  66. $this->proxy = $this->getMockBuilder(User_Proxy::class)
  67. ->setConstructorArgs([
  68. $this->helper,
  69. $this->ldapWrapper,
  70. $this->accessFactory,
  71. $this->config,
  72. $this->notificationManager,
  73. $this->userSession,
  74. $this->userPluginManager
  75. ])
  76. ->setMethods(['handleRequest'])
  77. ->getMock();
  78. }
  79. public function testSetPassword() {
  80. $this->proxy
  81. ->expects($this->once())
  82. ->method('handleRequest')
  83. ->with('MyUid', 'setPassword', ['MyUid', 'MyPassword'])
  84. ->willReturn(true);
  85. $this->assertTrue($this->proxy->setPassword('MyUid', 'MyPassword'));
  86. }
  87. public function testSetDisplayName() {
  88. $this->proxy
  89. ->expects($this->once())
  90. ->method('handleRequest')
  91. ->with('MyUid', 'setDisplayName', ['MyUid', 'MyPassword'])
  92. ->willReturn(true);
  93. $this->assertTrue($this->proxy->setDisplayName('MyUid', 'MyPassword'));
  94. }
  95. public function testCreateUser() {
  96. $this->proxy
  97. ->expects($this->once())
  98. ->method('handleRequest')
  99. ->with('MyUid', 'createUser', ['MyUid', 'MyPassword'])
  100. ->willReturn(true);
  101. $this->assertTrue($this->proxy->createUser('MyUid', 'MyPassword'));
  102. }
  103. }