diff options
-rw-r--r-- | apps/user_ldap/lib/Jobs/Sync.php | 4 | ||||
-rw-r--r-- | apps/user_ldap/tests/Jobs/SyncTest.php | 22 |
2 files changed, 21 insertions, 5 deletions
diff --git a/apps/user_ldap/lib/Jobs/Sync.php b/apps/user_ldap/lib/Jobs/Sync.php index 38eba5ca4bf..7a1f7703e5c 100644 --- a/apps/user_ldap/lib/Jobs/Sync.php +++ b/apps/user_ldap/lib/Jobs/Sync.php @@ -118,7 +118,7 @@ class Sync extends TimedJob { /** * @param array $argument */ - protected function run($argument) { + public function run($argument) { $this->setArgument($argument); $isBackgroundJobModeAjax = $this->config @@ -252,7 +252,7 @@ class Sync extends TimedJob { * @param $cycleData * @return bool */ - protected function qualifiesToRun($cycleData) { + public function qualifiesToRun($cycleData) { $lastChange = $this->config->getAppValue('user_ldap', $cycleData['prefix'] . '_lastChange', 0); if((time() - $lastChange) > 60 * 30) { return true; diff --git a/apps/user_ldap/tests/Jobs/SyncTest.php b/apps/user_ldap/tests/Jobs/SyncTest.php index 338b1210a98..68a7887c12b 100644 --- a/apps/user_ldap/tests/Jobs/SyncTest.php +++ b/apps/user_ldap/tests/Jobs/SyncTest.php @@ -197,11 +197,15 @@ class SyncTest extends TestCase { } public function cycleDataProvider() { - $cycle1 = ['prefix' => 's01', 'offset' => 1000]; + $lastCycle = ['prefix' => 's01', 'offset' => 1000]; + $lastCycle2 = ['prefix' => '', 'offset' => 1000]; return [ [ null, ['s01'], ['prefix' => 's01', 'offset' => 0] ], - [ $cycle1, ['s01', 's02'], ['prefix' => 's02', 'offset' => 0] ], - [ $cycle1, [], null ], + [ null, [''], ['prefix' => '', 'offset' => 0] ], + [ $lastCycle, ['s01', 's02'], ['prefix' => 's02', 'offset' => 0] ], + [ $lastCycle, [''], ['prefix' => '', 'offset' => 0] ], + [ $lastCycle2, ['', 's01'], ['prefix' => 's01', 'offset' => 0] ], + [ $lastCycle, [], null ], ]; } @@ -237,4 +241,16 @@ class SyncTest extends TestCase { } } + public function testQualifiesToRun() { + $cycleData = ['prefix' => 's01']; + + $this->config->expects($this->exactly(2)) + ->method('getAppValue') + ->willReturnOnConsecutiveCalls(time() - 60*40, time() - 60*20); + + $this->sync->setArgument($this->arguments); + $this->assertTrue($this->sync->qualifiesToRun($cycleData)); + $this->assertFalse($this->sync->qualifiesToRun($cycleData)); + } + } |