diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2018-01-08 13:08:18 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2018-01-08 13:08:59 +0100 |
commit | b17c5fec40769ffc0b96c42618048046beb8f85e (patch) | |
tree | 0b536c980ba17bf90f27534f6e6fda6a9084c27e /apps | |
parent | e4310648dfcc57618c4a0d61ae73f889e08f3b53 (diff) | |
download | nextcloud-server-b17c5fec40769ffc0b96c42618048046beb8f85e.tar.gz nextcloud-server-b17c5fec40769ffc0b96c42618048046beb8f85e.zip |
add unit test for qualifies to run
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps')
-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)); + } + } |