create failing test for this case
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
62656dc5c2
commit
82da4fde18
|
@ -7,6 +7,7 @@ $baseDir = $vendorDir;
|
|||
|
||||
return array(
|
||||
'OCA\\User_LDAP\\Access' => $baseDir . '/../lib/Access.php',
|
||||
'OCA\\User_LDAP\\AccessFactory' => $baseDir . '/../lib/AccessFactory.php',
|
||||
'OCA\\User_LDAP\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
|
||||
'OCA\\User_LDAP\\BackendUtility' => $baseDir . '/../lib/BackendUtility.php',
|
||||
'OCA\\User_LDAP\\Command\\CheckUser' => $baseDir . '/../lib/Command/CheckUser.php',
|
||||
|
@ -19,6 +20,7 @@ return array(
|
|||
'OCA\\User_LDAP\\Command\\TestConfig' => $baseDir . '/../lib/Command/TestConfig.php',
|
||||
'OCA\\User_LDAP\\Configuration' => $baseDir . '/../lib/Configuration.php',
|
||||
'OCA\\User_LDAP\\Connection' => $baseDir . '/../lib/Connection.php',
|
||||
'OCA\\User_LDAP\\ConnectionFactory' => $baseDir . '/../lib/ConnectionFactory.php',
|
||||
'OCA\\User_LDAP\\Controller\\ConfigAPIController' => $baseDir . '/../lib/Controller/ConfigAPIController.php',
|
||||
'OCA\\User_LDAP\\Controller\\RenewPasswordController' => $baseDir . '/../lib/Controller/RenewPasswordController.php',
|
||||
'OCA\\User_LDAP\\Exceptions\\ConstraintViolationException' => $baseDir . '/../lib/Exceptions/ConstraintViolationException.php',
|
||||
|
|
|
@ -19,6 +19,7 @@ class ComposerStaticInitUser_LDAP
|
|||
|
||||
public static $classMap = array (
|
||||
'OCA\\User_LDAP\\Access' => __DIR__ . '/..' . '/../lib/Access.php',
|
||||
'OCA\\User_LDAP\\AccessFactory' => __DIR__ . '/..' . '/../lib/AccessFactory.php',
|
||||
'OCA\\User_LDAP\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
|
||||
'OCA\\User_LDAP\\BackendUtility' => __DIR__ . '/..' . '/../lib/BackendUtility.php',
|
||||
'OCA\\User_LDAP\\Command\\CheckUser' => __DIR__ . '/..' . '/../lib/Command/CheckUser.php',
|
||||
|
@ -31,6 +32,7 @@ class ComposerStaticInitUser_LDAP
|
|||
'OCA\\User_LDAP\\Command\\TestConfig' => __DIR__ . '/..' . '/../lib/Command/TestConfig.php',
|
||||
'OCA\\User_LDAP\\Configuration' => __DIR__ . '/..' . '/../lib/Configuration.php',
|
||||
'OCA\\User_LDAP\\Connection' => __DIR__ . '/..' . '/../lib/Connection.php',
|
||||
'OCA\\User_LDAP\\ConnectionFactory' => __DIR__ . '/..' . '/../lib/ConnectionFactory.php',
|
||||
'OCA\\User_LDAP\\Controller\\ConfigAPIController' => __DIR__ . '/..' . '/../lib/Controller/ConfigAPIController.php',
|
||||
'OCA\\User_LDAP\\Controller\\RenewPasswordController' => __DIR__ . '/..' . '/../lib/Controller/RenewPasswordController.php',
|
||||
'OCA\\User_LDAP\\Exceptions\\ConstraintViolationException' => __DIR__ . '/..' . '/../lib/Exceptions/ConstraintViolationException.php',
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\User_LDAP;
|
||||
|
||||
|
||||
use OCA\User_LDAP\User\Manager;
|
||||
use OCP\IConfig;
|
||||
|
||||
class AccessFactory {
|
||||
/** @var ILDAPWrapper */
|
||||
protected $ldap;
|
||||
/** @var Manager */
|
||||
protected $userManager;
|
||||
/** @var Helper */
|
||||
protected $helper;
|
||||
/** @var IConfig */
|
||||
protected $config;
|
||||
|
||||
public function __construct(
|
||||
ILDAPWrapper $ldap,
|
||||
Manager $userManager,
|
||||
Helper $helper,
|
||||
IConfig $config)
|
||||
{
|
||||
$this->ldap = $ldap;
|
||||
$this->userManager = $userManager;
|
||||
$this->helper = $helper;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function get(Connection $connection) {
|
||||
return new Access(
|
||||
$connection,
|
||||
$this->ldap,
|
||||
$this->userManager,
|
||||
$this->helper,
|
||||
$this->config
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\User_LDAP;
|
||||
|
||||
|
||||
class ConnectionFactory {
|
||||
/** @var ILDAPWrapper */
|
||||
private $ldap;
|
||||
|
||||
public function __construct(ILDAPWrapper $ldap) {
|
||||
$this->ldap = $ldap;
|
||||
}
|
||||
|
||||
public function get($prefix) {
|
||||
return new Connection($this->ldap, $prefix, 'user_ldap');
|
||||
}
|
||||
}
|
|
@ -26,8 +26,10 @@ namespace OCA\User_LDAP\Jobs;
|
|||
use OC\BackgroundJob\TimedJob;
|
||||
use OC\ServerNotAvailableException;
|
||||
use OCA\User_LDAP\Access;
|
||||
use OCA\User_LDAP\AccessFactory;
|
||||
use OCA\User_LDAP\Configuration;
|
||||
use OCA\User_LDAP\Connection;
|
||||
use OCA\User_LDAP\ConnectionFactory;
|
||||
use OCA\User_LDAP\FilesystemHelper;
|
||||
use OCA\User_LDAP\Helper;
|
||||
use OCA\User_LDAP\LDAP;
|
||||
|
@ -62,6 +64,10 @@ class Sync extends TimedJob {
|
|||
protected $ncUserManager;
|
||||
/** @var IManager */
|
||||
protected $notificationManager;
|
||||
/** @var ConnectionFactory */
|
||||
protected $connectionFactory;
|
||||
/** @var AccessFactory */
|
||||
protected $accessFactory;
|
||||
|
||||
public function __construct() {
|
||||
$this->setInterval(
|
||||
|
@ -153,8 +159,8 @@ class Sync extends TimedJob {
|
|||
* @return bool whether more results are expected from the same configuration
|
||||
*/
|
||||
public function runCycle($cycleData) {
|
||||
$connection = new Connection($this->ldap, $cycleData['prefix']);
|
||||
$access = new Access($connection, $this->ldap, $this->userManager, $this->ldapHelper, $this->config);
|
||||
$connection = $this->connectionFactory->get($cycleData['prefix']);
|
||||
$access = $this->accessFactory->get($connection);
|
||||
$access->setUserMapper($this->mapper);
|
||||
|
||||
$filter = $access->combineFilterWithAnd(array(
|
||||
|
@ -358,5 +364,22 @@ class Sync extends TimedJob {
|
|||
} else {
|
||||
$this->mapper = new UserMapping($this->dbc);
|
||||
}
|
||||
|
||||
if(isset($argument['connectionFactory'])) {
|
||||
$this->connectionFactory = $argument['connectionFactory'];
|
||||
} else {
|
||||
$this->connectionFactory = new ConnectionFactory($this->ldap);
|
||||
}
|
||||
|
||||
if(isset($argument['accessFactory'])) {
|
||||
$this->accessFactory = $argument['accessFactory'];
|
||||
} else {
|
||||
$this->accessFactory = new AccessFactory(
|
||||
$this->ldap,
|
||||
$this->userManager,
|
||||
$this->ldapHelper,
|
||||
$this->config
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
|
||||
namespace OCA\User_LDAP\Tests\Jobs;
|
||||
|
||||
use OCA\User_LDAP\Access;
|
||||
use OCA\User_LDAP\AccessFactory;
|
||||
use OCA\User_LDAP\Connection;
|
||||
use OCA\User_LDAP\ConnectionFactory;
|
||||
use OCA\User_LDAP\Helper;
|
||||
use OCA\User_LDAP\Jobs\Sync;
|
||||
use OCA\User_LDAP\LDAP;
|
||||
|
@ -59,6 +63,10 @@ class SyncTest extends TestCase {
|
|||
protected $ncUserManager;
|
||||
/** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $notificationManager;
|
||||
/** @var ConnectionFactory|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $connectionFactory;
|
||||
/** @var AccessFactory|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $accessFactory;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
@ -72,6 +80,8 @@ class SyncTest extends TestCase {
|
|||
$this->dbc = $this->createMock(IDBConnection::class);
|
||||
$this->ncUserManager = $this->createMock(IUserManager::class);
|
||||
$this->notificationManager = $this->createMock(IManager::class);
|
||||
$this->connectionFactory = $this->createMock(ConnectionFactory::class);
|
||||
$this->accessFactory = $this->createMock(AccessFactory::class);
|
||||
|
||||
$this->arguments = [
|
||||
'helper' => $this->helper,
|
||||
|
@ -83,6 +93,8 @@ class SyncTest extends TestCase {
|
|||
'dbc' => $this->dbc,
|
||||
'ncUserManager' => $this->ncUserManager,
|
||||
'notificationManager' => $this->notificationManager,
|
||||
'connectionFactory' => $this->connectionFactory,
|
||||
'accessFactory' => $this->accessFactory,
|
||||
];
|
||||
|
||||
$this->sync = new Sync();
|
||||
|
@ -141,4 +153,47 @@ class SyncTest extends TestCase {
|
|||
$this->sync->updateInterval();
|
||||
}
|
||||
|
||||
public function moreResultsProvider() {
|
||||
return [
|
||||
[ 3, 3, true ],
|
||||
[ 3, 5, true ],
|
||||
[ 3, 2, false]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider moreResultsProvider
|
||||
*/
|
||||
public function testMoreResults($pagingSize, $results, $expected) {
|
||||
$connection = $this->createMock(Connection::class);
|
||||
$this->connectionFactory->expects($this->any())
|
||||
->method('get')
|
||||
->willReturn($connection);
|
||||
$connection->expects($this->any())
|
||||
->method('__get')
|
||||
->willReturnCallback(function ($key) use ($pagingSize) {
|
||||
if($key === 'ldapPagingSize') {
|
||||
return $pagingSize;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
/** @var Access|\PHPUnit_Framework_MockObject_MockObject $access */
|
||||
$access = $this->createMock(Access::class);
|
||||
$this->accessFactory->expects($this->any())
|
||||
->method('get')
|
||||
->with($connection)
|
||||
->willReturn($access);
|
||||
|
||||
$access->expects($this->once())
|
||||
->method('fetchListOfUsers')
|
||||
->willReturn(array_pad([], $results, 'someUser'));
|
||||
$access->connection = $connection;
|
||||
$access->userManager = $this->userManager;
|
||||
|
||||
$this->sync->setArgument($this->arguments);
|
||||
$hasMoreResults = $this->sync->runCycle(['prefix' => 's01', 'offset' => 100]);
|
||||
$this->assertSame($expected, $hasMoreResults);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue