nextcloud/apps/user_ldap/tests/jobs/cleanup.php

136 lines
3.6 KiB
PHP
Raw Normal View History

LDAP User Cleanup: Port from stable7 without further adjustements LDAP User Cleanup background job for user clean up adjust user backend for clean up register background job remove dead code dependency injection make Helper non-static for proper testing check whether it is OK to run clean up job. Do not forget to pass arguments. use correct method to get the config from server methods can be private, proper indirect testing is given no automatic user deletion make limit readable for test purposes make method less complex add first tests let preferences accept limit and offset for getUsersForValue DI via constructor does not work for background jobs after detecting, now we have retrieving deleted users and their details we need this method to be public for now finalize export method, add missing getter clean up namespaces and get rid of unnecessary files helper is not static anymore cleanup according to scrutinizer add cli tool to show deleted users uses are necessary after recent namespace change also remove user from mappings table on deletion add occ command to delete users fix use statement improve output big fixes / improvements PHP doc return true in userExists early for cleaning up deleted users bump version control state and interval with one config.php setting, now ldapUserCleanupInterval. 0 will disable it. enabled by default. improve doc rename cli method to be consistent with others introduce ldapUserCleanupInterval in sample config don't show last login as unix epoche start when no login happend less log output consistent namespace for OfflineUser rename GarbageCollector to DeletedUsersIndex and move it to user subdir fix unit tests add tests for deleteUser more test adjustements Conflicts: apps/user_ldap/ajax/clearMappings.php apps/user_ldap/appinfo/app.php apps/user_ldap/lib/access.php apps/user_ldap/lib/helper.php apps/user_ldap/tests/helper.php core/register_command.php lib/private/preferences.php lib/private/user.php add ldap:check-user to check user existance on the fly Conflicts: apps/user_ldap/lib/helper.php forgotten file PHPdoc fixes, no code change and don't forget to adjust tests
2014-08-21 19:59:13 +04:00
<?php
/**
* Copyright (c) 2014 Arthur Schiwon <blizzz@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OCA\user_ldap\tests;
class Test_CleanUp extends \PHPUnit_Framework_TestCase {
public function getMocks() {
$mocks = array();
$mocks['userBackend'] =
$this->getMockBuilder('\OCA\user_ldap\User_Proxy')
->disableOriginalConstructor()
->getMock();
2014-12-20 19:08:26 +03:00
$mocks['deletedUsersIndex'] =
$this->getMockBuilder('\OCA\user_ldap\lib\user\deletedUsersIndex')
->disableOriginalConstructor()
->getMock();
LDAP User Cleanup: Port from stable7 without further adjustements LDAP User Cleanup background job for user clean up adjust user backend for clean up register background job remove dead code dependency injection make Helper non-static for proper testing check whether it is OK to run clean up job. Do not forget to pass arguments. use correct method to get the config from server methods can be private, proper indirect testing is given no automatic user deletion make limit readable for test purposes make method less complex add first tests let preferences accept limit and offset for getUsersForValue DI via constructor does not work for background jobs after detecting, now we have retrieving deleted users and their details we need this method to be public for now finalize export method, add missing getter clean up namespaces and get rid of unnecessary files helper is not static anymore cleanup according to scrutinizer add cli tool to show deleted users uses are necessary after recent namespace change also remove user from mappings table on deletion add occ command to delete users fix use statement improve output big fixes / improvements PHP doc return true in userExists early for cleaning up deleted users bump version control state and interval with one config.php setting, now ldapUserCleanupInterval. 0 will disable it. enabled by default. improve doc rename cli method to be consistent with others introduce ldapUserCleanupInterval in sample config don't show last login as unix epoche start when no login happend less log output consistent namespace for OfflineUser rename GarbageCollector to DeletedUsersIndex and move it to user subdir fix unit tests add tests for deleteUser more test adjustements Conflicts: apps/user_ldap/ajax/clearMappings.php apps/user_ldap/appinfo/app.php apps/user_ldap/lib/access.php apps/user_ldap/lib/helper.php apps/user_ldap/tests/helper.php core/register_command.php lib/private/preferences.php lib/private/user.php add ldap:check-user to check user existance on the fly Conflicts: apps/user_ldap/lib/helper.php forgotten file PHPdoc fixes, no code change and don't forget to adjust tests
2014-08-21 19:59:13 +04:00
$mocks['ocConfig'] = $this->getMock('\OCP\IConfig');
$mocks['db'] = $this->getMock('\OCP\IDBConnection');
$mocks['helper'] = $this->getMock('\OCA\user_ldap\lib\Helper');
return $mocks;
}
/**
* clean up job must not run when there are disabled configurations
*/
public function test_runNotAllowedByDisabledConfigurations() {
$args = $this->getMocks();
$args['helper']->expects($this->once())
->method('haveDisabledConfigurations')
->will($this->returnValue(true) );
$args['ocConfig']->expects($this->never())
->method('getSystemValue');
$bgJob = new \OCA\User_LDAP\Jobs\CleanUp();
$bgJob->setArguments($args);
$result = $bgJob->isCleanUpAllowed();
$this->assertSame(false, $result);
}
/**
* clean up job must not run when LDAP Helper is broken i.e.
* returning unexpected results
*/
public function test_runNotAllowedByBrokenHelper() {
$args = $this->getMocks();
$args['helper']->expects($this->once())
->method('haveDisabledConfigurations')
->will($this->throwException(new \Exception()));
$args['ocConfig']->expects($this->never())
->method('getSystemValue');
$bgJob = new \OCA\User_LDAP\Jobs\CleanUp();
$bgJob->setArguments($args);
$result = $bgJob->isCleanUpAllowed();
$this->assertSame(false, $result);
}
/**
* clean up job must not run when it is not enabled
*/
public function test_runNotAllowedBySysConfig() {
$args = $this->getMocks();
$args['helper']->expects($this->once())
->method('haveDisabledConfigurations')
->will($this->returnValue(false));
$args['ocConfig']->expects($this->once())
->method('getSystemValue')
->will($this->returnValue(false));
$bgJob = new \OCA\User_LDAP\Jobs\CleanUp();
$bgJob->setArguments($args);
$result = $bgJob->isCleanUpAllowed();
$this->assertSame(false, $result);
}
/**
* clean up job is allowed to run
*/
public function test_runIsAllowed() {
$args = $this->getMocks();
$args['helper']->expects($this->once())
->method('haveDisabledConfigurations')
->will($this->returnValue(false));
$args['ocConfig']->expects($this->once())
->method('getSystemValue')
->will($this->returnValue(true));
$bgJob = new \OCA\User_LDAP\Jobs\CleanUp();
$bgJob->setArguments($args);
$result = $bgJob->isCleanUpAllowed();
$this->assertSame(true, $result);
}
/**
* check whether offset will be reset when it needs to
*/
public function test_OffsetResetIsNecessary() {
$args = $this->getMocks();
$bgJob = new \OCA\User_LDAP\Jobs\CleanUp();
$bgJob->setArguments($args);
$result = $bgJob->isOffsetResetNecessary($bgJob->getChunkSize() - 1);
$this->assertSame(true, $result);
}
/**
* make sure offset is not reset when it is not due
*/
public function test_OffsetResetIsNotNecessary() {
$args = $this->getMocks();
$bgJob = new \OCA\User_LDAP\Jobs\CleanUp();
$bgJob->setArguments($args);
$result = $bgJob->isOffsetResetNecessary($bgJob->getChunkSize());
$this->assertSame(false, $result);
}
}