]> source.dussan.org Git - nextcloud-server.git/commitdiff
unit test on getHome in combination with OfflineUser
authorArthur Schiwon <blizzz@owncloud.com>
Fri, 11 Dec 2015 16:25:57 +0000 (17:25 +0100)
committerArthur Schiwon <blizzz@owncloud.com>
Fri, 11 Dec 2015 16:25:57 +0000 (17:25 +0100)
apps/user_ldap/tests/user_ldap.php

index b08706c71d9e94d8b1b6e4d327fc1a4ec65d8ca8..3aec2a5ce57fcd35cbb8c49cfad9b6a6c68e46ed 100644 (file)
@@ -70,14 +70,26 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
                                                                        array($lw, null, null));
 
                $this->configMock = $this->getMock('\OCP\IConfig');
-               $um = new \OCA\user_ldap\lib\user\Manager(
+
+               $offlineUser = $this->getMockBuilder('\OCA\user_ldap\lib\user\OfflineUser')
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $um = $this->getMockBuilder('\OCA\user_ldap\lib\user\Manager')
+                       ->setMethods(['getDeletedUser'])
+                       ->setConstructorArgs([
                                $this->configMock,
                                $this->getMock('\OCA\user_ldap\lib\FilesystemHelper'),
                                $this->getMock('\OCA\user_ldap\lib\LogWrapper'),
                                $this->getMock('\OCP\IAvatarManager'),
                                $this->getMock('\OCP\Image'),
                                $this->getMock('\OCP\IDBConnection')
-                       );
+                         ])
+                       ->getMock();
+
+               $um->expects($this->any())
+                       ->method('getDeletedUser')
+                       ->will($this->returnValue($offlineUser));
 
                $access = $this->getMock('\OCA\user_ldap\lib\Access',
                                                                 $accMethods,
@@ -661,6 +673,44 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
                $this->assertFalse($result);
        }
 
+       /**
+        * @expectedException \OC\User\NoUserException
+        */
+       public function testGetHomeDeletedUser() {
+               $access = $this->getAccessMock();
+               $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
+               $this->prepareMockForUserExists($access);
+
+               $access->connection->expects($this->any())
+                               ->method('__get')
+                               ->will($this->returnCallback(function($name) {
+                                       if($name === 'homeFolderNamingRule') {
+                                               return 'attr:testAttribute';
+                                       }
+                                       return null;
+                               }));
+
+               $access->expects($this->any())
+                               ->method('readAttribute')
+                               ->will($this->returnValue([]));
+
+               $userMapper = $this->getMockBuilder('\OCA\User_LDAP\Mapping\UserMapping')
+                               ->disableOriginalConstructor()
+                               ->getMock();
+
+               $access->expects($this->any())
+                               ->method('getUserMapper')
+                               ->will($this->returnValue($userMapper));
+
+               $this->configMock->expects($this->any())
+                       ->method('getUserValue')
+                       ->will($this->returnValue(true));
+
+               //no path at all – triggers OC default behaviour
+               $result = $backend->getHome('newyorker');
+               $this->assertFalse($result);
+       }
+
        private function prepareAccessForGetDisplayName(&$access) {
                $access->connection->expects($this->any())
                           ->method('__get')