IntegrationTestFetchUsersByLoginName.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Vinicius Cubas Brand <vinicius@eita.org.br>
  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. require_once __DIR__ . '/../Bootstrap.php';
  30. class IntegrationTestFetchUsersByLoginName extends AbstractIntegrationTest {
  31. /** @var UserMapping */
  32. protected $mapping;
  33. /** @var User_LDAP */
  34. protected $backend;
  35. /**
  36. * prepares the LDAP environment and sets up a test configuration for
  37. * the LDAP backend.
  38. */
  39. public function init() {
  40. require(__DIR__ . '/../setup-scripts/createExplicitUsers.php');
  41. parent::init();
  42. $this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
  43. $this->mapping->clear();
  44. $this->access->setUserMapper($this->mapping);
  45. $this->backend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query('LDAPUserPluginManager'));
  46. }
  47. /**
  48. * tests fetchUserByLoginName where it is expected that the login name does
  49. * not match any LDAP user
  50. *
  51. * @return bool
  52. */
  53. protected function case1() {
  54. $result = $this->access->fetchUsersByLoginName('nothere');
  55. return $result === [];
  56. }
  57. /**
  58. * tests fetchUserByLoginName where it is expected that the login name does
  59. * match one LDAP user
  60. *
  61. * @return bool
  62. */
  63. protected function case2() {
  64. $result = $this->access->fetchUsersByLoginName('alice');
  65. return count($result) === 1;
  66. }
  67. }
  68. /** @var string $host */
  69. /** @var int $port */
  70. /** @var string $adn */
  71. /** @var string $apwd */
  72. /** @var string $bdn */
  73. $test = new IntegrationTestFetchUsersByLoginName($host, $port, $adn, $apwd, $bdn);
  74. $test->init();
  75. $test->run();