aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2018-01-08 13:44:45 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2018-01-08 13:44:45 +0100
commit0d3f945209f70905e4125fd62501b5adad8901d3 (patch)
tree80a89c4e1a6e8e1aa8b6f1b9926450f07ca22397 /apps/user_ldap
parentb17c5fec40769ffc0b96c42618048046beb8f85e (diff)
downloadnextcloud-server-0d3f945209f70905e4125fd62501b5adad8901d3.tar.gz
nextcloud-server-0d3f945209f70905e4125fd62501b5adad8901d3.zip
add tests for whole run command
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/tests/Jobs/SyncTest.php104
1 files changed, 104 insertions, 0 deletions
diff --git a/apps/user_ldap/tests/Jobs/SyncTest.php b/apps/user_ldap/tests/Jobs/SyncTest.php
index 68a7887c12b..62f15472138 100644
--- a/apps/user_ldap/tests/Jobs/SyncTest.php
+++ b/apps/user_ldap/tests/Jobs/SyncTest.php
@@ -37,6 +37,7 @@ use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IUserManager;
use OCP\Notification\IManager;
+use function Sodium\memcmp;
use Test\TestCase;
class SyncTest extends TestCase {
@@ -253,4 +254,107 @@ class SyncTest extends TestCase {
$this->assertFalse($this->sync->qualifiesToRun($cycleData));
}
+ public function runDataProvider() {
+ return [
+ #0 - one LDAP server, reset
+ [[
+ 'prefixes' => [''],
+ 'scheduledCycle' => ['prefix' => '', 'offset' => '4500'],
+ 'pagingSize' => 500,
+ 'usersThisCycle' => 0,
+ 'expectedNextCycle' => ['prefix' => '', 'offset' => '0'],
+ 'mappedUsers' => 123,
+ ]],
+ #0 - 2 LDAP servers, next prefix
+ [[
+ 'prefixes' => ['', 's01'],
+ 'scheduledCycle' => ['prefix' => '', 'offset' => '4500'],
+ 'pagingSize' => 500,
+ 'usersThisCycle' => 0,
+ 'expectedNextCycle' => ['prefix' => 's01', 'offset' => '0'],
+ 'mappedUsers' => 123,
+ ]],
+ ];
+ }
+
+ /**
+ * @dataProvider runDataProvider
+ */
+ public function testRun($runData) {
+ $this->config->expects($this->any())
+ ->method('getAppValue')
+ ->willReturnCallback(function($app, $key, $default) use ($runData) {
+ if($app === 'core' && $key === 'backgroundjobs_mode') {
+ return 'cron';
+ }
+ if($app = 'user_ldap') {
+ // for getCycle()
+ if($key === 'background_sync_prefix') {
+ return $runData['scheduledCycle']['prefix'];
+ }
+ if($key === 'background_sync_offset') {
+ return $runData['scheduledCycle']['offset'];
+ }
+ // for qualifiesToRun()
+ if($key === $runData['scheduledCycle']['prefix'] . '_lastChange') {
+ return time() - 60*40;
+ }
+ // for getMinPagingSize
+ if($key === $runData['scheduledCycle']['prefix'] . 'ldap_paging_size') {
+ return $runData['pagingSize'];
+ }
+ }
+
+ return $default;
+ });
+ $this->config->expects($this->exactly(3))
+ ->method('setAppValue')
+ ->withConsecutive(
+ ['user_ldap', 'background_sync_prefix', $runData['expectedNextCycle']['prefix']],
+ ['user_ldap', 'background_sync_offset', $runData['expectedNextCycle']['offset']],
+ ['user_ldap', 'background_sync_interval', $this->anything()]
+ );
+ $this->config->expects($this->any())
+ ->method('getAppKeys')
+ ->with('user_ldap')
+ ->willReturn([$runData['scheduledCycle']['prefix'] . 'ldap_paging_size']);
+
+ $this->helper->expects($this->any())
+ ->method('getServerConfigurationPrefixes')
+ ->with(true)
+ ->willReturn($runData['prefixes']);
+
+ $connection = $this->createMock(Connection::class);
+ $this->connectionFactory->expects($this->any())
+ ->method('get')
+ ->willReturn($connection);
+ $connection->expects($this->any())
+ ->method('__get')
+ ->willReturnCallback(function ($key) use ($runData) {
+ if($key === 'ldapPagingSize') {
+ return $runData['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([], $runData['usersThisCycle'], 'someUser'));
+ $access->connection = $connection;
+ $access->userManager = $this->userManager;
+
+ $this->mapper->expects($this->any())
+ ->method('count')
+ ->willReturn($runData['mappedUsers']);
+
+ $this->sync->run($this->arguments);
+ }
+
}