]> source.dussan.org Git - nextcloud-server.git/commitdiff
Unit tests for updateUser and deleteUser
authorThomas Müller <thomas.mueller@tmit.eu>
Thu, 14 Jan 2016 12:01:10 +0000 (13:01 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Thu, 14 Jan 2016 12:01:10 +0000 (13:01 +0100)
apps/dav/tests/unit/carddav/syncservicetest.php

index d66383461bbe1e3fd707935a9692534c822542c7..a6af98f7e8c9cae811f5dbc10654ff83125e2c51 100644 (file)
@@ -20,6 +20,8 @@
  */
 namespace OCA\DAV\CardDAV;
 
+use OCP\IUser;
+use OCP\IUserManager;
 use Test\TestCase;
 
 class SyncServiceTest extends TestCase {
@@ -64,10 +66,42 @@ 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