From 82da4fde1843a682562ed34fb1de5dc55e32d4f5 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon <blizzz@arthur-schiwon.de>
Date: Fri, 5 Jan 2018 14:27:36 +0100
Subject: create failing test for this case

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
---
 apps/user_ldap/tests/Jobs/SyncTest.php | 55 ++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

(limited to 'apps/user_ldap/tests/Jobs')

diff --git a/apps/user_ldap/tests/Jobs/SyncTest.php b/apps/user_ldap/tests/Jobs/SyncTest.php
index f8a44de87e8..686455f5ac6 100644
--- a/apps/user_ldap/tests/Jobs/SyncTest.php
+++ b/apps/user_ldap/tests/Jobs/SyncTest.php
@@ -23,6 +23,10 @@
 
 namespace OCA\User_LDAP\Tests\Jobs;
 
+use OCA\User_LDAP\Access;
+use OCA\User_LDAP\AccessFactory;
+use OCA\User_LDAP\Connection;
+use OCA\User_LDAP\ConnectionFactory;
 use OCA\User_LDAP\Helper;
 use OCA\User_LDAP\Jobs\Sync;
 use OCA\User_LDAP\LDAP;
@@ -59,6 +63,10 @@ class SyncTest extends TestCase {
 	protected $ncUserManager;
 	/** @var  IManager|\PHPUnit_Framework_MockObject_MockObject */
 	protected $notificationManager;
+	/** @var ConnectionFactory|\PHPUnit_Framework_MockObject_MockObject */
+	protected $connectionFactory;
+	/** @var AccessFactory|\PHPUnit_Framework_MockObject_MockObject */
+	protected $accessFactory;
 
 	public function setUp() {
 		parent::setUp();
@@ -72,6 +80,8 @@ class SyncTest extends TestCase {
 		$this->dbc = $this->createMock(IDBConnection::class);
 		$this->ncUserManager = $this->createMock(IUserManager::class);
 		$this->notificationManager = $this->createMock(IManager::class);
+		$this->connectionFactory = $this->createMock(ConnectionFactory::class);
+		$this->accessFactory = $this->createMock(AccessFactory::class);
 
 		$this->arguments = [
 			'helper' => $this->helper,
@@ -83,6 +93,8 @@ class SyncTest extends TestCase {
 			'dbc' => $this->dbc,
 			'ncUserManager' => $this->ncUserManager,
 			'notificationManager' => $this->notificationManager,
+			'connectionFactory' => $this->connectionFactory,
+			'accessFactory' => $this->accessFactory,
 		];
 
 		$this->sync = new Sync();
@@ -141,4 +153,47 @@ class SyncTest extends TestCase {
 		$this->sync->updateInterval();
 	}
 
+	public function moreResultsProvider() {
+		return [
+			[ 3, 3, true ],
+			[ 3, 5, true ],
+			[ 3, 2, false]
+		];
+	}
+
+	/**
+	 * @dataProvider moreResultsProvider
+	 */
+	public function testMoreResults($pagingSize, $results, $expected) {
+		$connection = $this->createMock(Connection::class);
+		$this->connectionFactory->expects($this->any())
+			->method('get')
+			->willReturn($connection);
+		$connection->expects($this->any())
+			->method('__get')
+			->willReturnCallback(function ($key) use ($pagingSize) {
+				if($key === 'ldapPagingSize') {
+					return $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([], $results, 'someUser'));
+		$access->connection = $connection;
+		$access->userManager = $this->userManager;
+
+		$this->sync->setArgument($this->arguments);
+		$hasMoreResults = $this->sync->runCycle(['prefix' => 's01', 'offset' => 100]);
+		$this->assertSame($expected, $hasMoreResults);
+	}
+
 }
-- 
cgit v1.2.3