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