IntegrationTestPaging.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\User_LDAP\Tests\Integration\Lib;
  27. use OCA\User_LDAP\Mapping\UserMapping;
  28. use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
  29. use OCA\User_LDAP\User\DeletedUsersIndex;
  30. use OCA\User_LDAP\User_LDAP;
  31. use OCA\User_LDAP\UserPluginManager;
  32. use Psr\Log\LoggerInterface;
  33. require_once __DIR__ . '/../Bootstrap.php';
  34. class IntegrationTestPaging extends AbstractIntegrationTest {
  35. /** @var UserMapping */
  36. protected $mapping;
  37. /** @var User_LDAP */
  38. protected $backend;
  39. /** @var int */
  40. protected $pagingSize = 2;
  41. /**
  42. * prepares the LDAP environment and sets up a test configuration for
  43. * the LDAP backend.
  44. */
  45. public function init() {
  46. require(__DIR__ . '/../setup-scripts/createExplicitUsers.php');
  47. parent::init();
  48. $this->backend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->get(UserPluginManager::class), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DeletedUsersIndex::class));
  49. }
  50. public function initConnection() {
  51. parent::initConnection();
  52. $this->connection->setConfiguration([
  53. 'ldapPagingSize' => $this->pagingSize
  54. ]);
  55. }
  56. /**
  57. * fetch first three, afterwards all users
  58. *
  59. * @return bool
  60. */
  61. protected function case1() {
  62. $filter = 'objectclass=inetorgperson';
  63. $attributes = ['cn', 'dn'];
  64. $result = $this->access->searchUsers($filter, $attributes, 4);
  65. // beware, under circumstances, the result set can be larger then
  66. // the specified limit! In this case, if we specify a limit of 3,
  67. // the result will be 4, because the highest possible paging size
  68. // is 2 (as configured).
  69. // But also with more than one search base, the limit can be outpaced.
  70. if (count($result) !== 4) {
  71. return false;
  72. }
  73. $result = $this->access->searchUsers($filter, $attributes);
  74. if (count($result) !== 7) {
  75. return false;
  76. }
  77. return true;
  78. }
  79. }
  80. /** @var string $host */
  81. /** @var int $port */
  82. /** @var string $adn */
  83. /** @var string $apwd */
  84. /** @var string $bdn */
  85. $test = new IntegrationTestPaging($host, $port, $adn, $apwd, $bdn);
  86. $test->init();
  87. $test->run();