*/
namespace OCA\DAV\CardDAV;
+use OCP\IUser;
+use OCP\IUserManager;
use Test\TestCase;
class SyncServiceTest extends TestCase {
$backend->expects($this->at(0))->method('getAddressBooksByUri')->willReturn(null);
$backend->expects($this->at(1))->method('getAddressBooksByUri')->willReturn([]);
- $ss = new SyncService($backend);
+ /** @var IUserManager $userManager */
+ $userManager = $this->getMockBuilder('OCP\IUserManager')->disableOriginalConstructor()->getMock();
+ $ss = new SyncService($backend, $userManager);
$book = $ss->ensureSystemAddressBookExists('principals/users/adam', 'contacts', []);
}
+ public function testUpdateAndDeleteUser() {
+ /** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $backend */
+ $backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDAVBackend')->disableOriginalConstructor()->getMock();
+
+ $backend->expects($this->once())->method('createCard');
+ $backend->expects($this->once())->method('updateCard');
+ $backend->expects($this->once())->method('deleteCard');
+
+ $backend->method('getCard')->willReturnOnConsecutiveCalls(false, [
+ 'carddata' => "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 3.4.8//EN\r\nUID:test-user\r\nFN:test-user\r\nN:test-user;;;;\r\nEND:VCARD\r\n\r\n"
+ ]);
+
+ /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject $userManager */
+ $userManager = $this->getMockBuilder('OCP\IUserManager')->disableOriginalConstructor()->getMock();
+
+ /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */
+ $user = $this->getMockBuilder('OCP\IUser')->disableOriginalConstructor()->getMock();
+ $user->method('getBackendClassName')->willReturn('unittest');
+ $user->method('getUID')->willReturn('test-user');
+
+ $ss = new SyncService($backend, $userManager);
+ $ss->updateUser($user);
+
+ $user->method('getDisplayName')->willReturn('A test user for unit testing');
+
+ $ss->updateUser($user);
+
+ $ss->deleteUser($user);
+ }
+
/**
* @param int $createCount
* @param int $updateCount