IntegrationTestFetchUsersByLoginName.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\User_LDAP\Tests\Integration\Lib;
  26. use OCA\User_LDAP\Mapping\UserMapping;
  27. use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
  28. use OCA\User_LDAP\User_LDAP;
  29. use OCA\User_LDAP\UserPluginManager;
  30. require_once __DIR__ . '/../Bootstrap.php';
  31. class IntegrationTestFetchUsersByLoginName extends AbstractIntegrationTest {
  32. /** @var UserMapping */
  33. protected $mapping;
  34. /** @var User_LDAP */
  35. protected $backend;
  36. /**
  37. * prepares the LDAP environment and sets up a test configuration for
  38. * the LDAP backend.
  39. */
  40. public function init() {
  41. require(__DIR__ . '/../setup-scripts/createExplicitUsers.php');
  42. parent::init();
  43. $this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
  44. $this->mapping->clear();
  45. $this->access->setUserMapper($this->mapping);
  46. $this->backend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query(UserPluginManager::class));
  47. }
  48. /**
  49. * tests fetchUserByLoginName where it is expected that the login name does
  50. * not match any LDAP user
  51. *
  52. * @return bool
  53. */
  54. protected function case1() {
  55. $result = $this->access->fetchUsersByLoginName('nothere');
  56. return $result === [];
  57. }
  58. /**
  59. * tests fetchUserByLoginName where it is expected that the login name does
  60. * match one LDAP user
  61. *
  62. * @return bool
  63. */
  64. protected function case2() {
  65. $result = $this->access->fetchUsersByLoginName('alice');
  66. return count($result) === 1;
  67. }
  68. }
  69. /** @var string $host */
  70. /** @var int $port */
  71. /** @var string $adn */
  72. /** @var string $apwd */
  73. /** @var string $bdn */
  74. $test = new IntegrationTestFetchUsersByLoginName($host, $port, $adn, $apwd, $bdn);
  75. $test->init();
  76. $test->run();