1
0

User_ProxyTest.php 4.0 KB

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