summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2018-01-08 12:57:14 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2018-01-08 12:57:14 +0100
commite4310648dfcc57618c4a0d61ae73f889e08f3b53 (patch)
treea2e870ab7835f980adb9868fea6cf83b5c5270bf
parenta565bf0b9f9d81d46ff705498b66b676fe9a628a (diff)
downloadnextcloud-server-e4310648dfcc57618c4a0d61ae73f889e08f3b53.tar.gz
nextcloud-server-e4310648dfcc57618c4a0d61ae73f889e08f3b53.zip
add unit test for determining next cycle
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
-rw-r--r--apps/user_ldap/tests/Jobs/SyncTest.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/apps/user_ldap/tests/Jobs/SyncTest.php b/apps/user_ldap/tests/Jobs/SyncTest.php
index 686455f5ac6..338b1210a98 100644
--- a/apps/user_ldap/tests/Jobs/SyncTest.php
+++ b/apps/user_ldap/tests/Jobs/SyncTest.php
@@ -196,4 +196,45 @@ class SyncTest extends TestCase {
$this->assertSame($expected, $hasMoreResults);
}
+ public function cycleDataProvider() {
+ $cycle1 = ['prefix' => 's01', 'offset' => 1000];
+ return [
+ [ null, ['s01'], ['prefix' => 's01', 'offset' => 0] ],
+ [ $cycle1, ['s01', 's02'], ['prefix' => 's02', 'offset' => 0] ],
+ [ $cycle1, [], null ],
+ ];
+ }
+
+ /**
+ * @dataProvider cycleDataProvider
+ */
+ public function testDetermineNextCycle($cycleData, $prefixes, $expectedCycle) {
+ $this->helper->expects($this->any())
+ ->method('getServerConfigurationPrefixes')
+ ->with(true)
+ ->willReturn($prefixes);
+
+ if(is_array($expectedCycle)) {
+ $this->config->expects($this->exactly(2))
+ ->method('setAppValue')
+ ->withConsecutive(
+ ['user_ldap', 'background_sync_prefix', $expectedCycle['prefix']],
+ ['user_ldap', 'background_sync_offset', $expectedCycle['offset']]
+ );
+ } else {
+ $this->config->expects($this->never())
+ ->method('setAppValue');
+ }
+
+ $this->sync->setArgument($this->arguments);
+ $nextCycle = $this->sync->determineNextCycle($cycleData);
+
+ if($expectedCycle === null) {
+ $this->assertNull($nextCycle);
+ } else {
+ $this->assertSame($expectedCycle['prefix'], $nextCycle['prefix']);
+ $this->assertSame($expectedCycle['offset'], $nextCycle['offset']);
+ }
+ }
+
}