]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix unit tests
authorBjoern Schiessle <bjoern@schiessle.org>
Thu, 17 Nov 2016 17:51:59 +0000 (18:51 +0100)
committerRoeland Jago Douma <roeland@famdouma.nl>
Mon, 21 Nov 2016 10:30:00 +0000 (11:30 +0100)
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
settings/Controller/UsersController.php
tests/Settings/Controller/UsersControllerTest.php

index 08d97a0f581e3e89f716f62015deac8c9474ee3e..94f97a356130fb116b55862f55cb36aceec6a722 100644 (file)
@@ -603,8 +603,9 @@ class UsersController extends Controller {
 
                // keep the user back-end up-to-date with the latest display name and email
                // address
-               if (isset($data['displayName']['value'])  && $user->getDisplayName() !== $data['displayName']['value']) {
-                       $result = $user->setDisplayName($data['displayName']['value']);
+               $oldDisplayName = $user->getDisplayName();
+               if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value'])  && $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value']) {
+                       $result = $user->setDisplayName($data[AccountManager::PROPERTY_DISPLAYNAME]['value']);
                        if ($result === false) {
                                throw new ForbiddenException($this->l10n->t('Unable to change full name'));
                        }
index e2b13b24b8cad3100920983f7e7b9db20e2da3cc..ec92479b40e38a1b3f5050e877b1ab226dbf70d9 100644 (file)
@@ -10,6 +10,7 @@
 
 namespace Tests\Settings\Controller;
 
+use OC\Accounts\AccountManager;
 use OC\Group\Manager;
 use OC\Settings\Controller\UsersController;
 use OCP\App\IAppManager;
@@ -57,6 +58,8 @@ class UsersControllerTest extends \Test\TestCase {
        private $avatarManager;
        /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
        private $l;
+       /** @var  AccountManager | \PHPUnit_Framework_MockObject_MockObject */
+       private $accountManager;
 
        protected function setUp() {
                parent::setUp();
@@ -71,6 +74,7 @@ class UsersControllerTest extends \Test\TestCase {
                $this->urlGenerator = $this->createMock(IURLGenerator::class);
                $this->appManager = $this->createMock(IAppManager::class);
                $this->avatarManager = $this->createMock(IAvatarManager::class);
+               $this->accountManager = $this->createMock(AccountManager::class);
                $this->l = $this->createMock(IL10N::class);
                $this->l->method('t')
                        ->will($this->returnCallback(function ($text, $parameters = []) {
@@ -117,7 +121,8 @@ class UsersControllerTest extends \Test\TestCase {
                        'no-reply@owncloud.com',
                        $this->urlGenerator,
                        $this->appManager,
-                       $this->avatarManager
+                       $this->avatarManager,
+                       $this->accountManager
                );
        }
 
@@ -1760,74 +1765,6 @@ class UsersControllerTest extends \Test\TestCase {
                $this->assertEquals($expectedResult, $result);
        }
 
-       /**
-        * @return array
-        */
-       public function setEmailAddressData() {
-               return [
-                       /* mailAddress,    isValid, expectsUpdate, canChangeDisplayName, responseCode */
-                       [ '',              true,    true,          true,                 Http::STATUS_OK ],
-                       [ 'foo@local',     true,    true,          true,                 Http::STATUS_OK],
-                       [ 'foo@bar@local', false,   false,         true,                 Http::STATUS_UNPROCESSABLE_ENTITY],
-                       [ 'foo@local',     true,    false,         false,                Http::STATUS_FORBIDDEN],
-               ];
-       }
-
-       /**
-        * @dataProvider setEmailAddressData
-        *
-        * @param string $mailAddress
-        * @param bool $isValid
-        * @param bool $expectsUpdate
-        * @param bool $expectsDelete
-        */
-       public function testSetEmailAddress($mailAddress, $isValid, $expectsUpdate, $canChangeDisplayName, $responseCode) {
-               $controller = $this->getController(true);
-
-               $user = $this->getMockBuilder('\OC\User\User')
-                       ->disableOriginalConstructor()->getMock();
-               $user
-                       ->expects($this->any())
-                       ->method('getUID')
-                       ->will($this->returnValue('foo'));
-               $user
-                       ->expects($this->any())
-                       ->method('canChangeDisplayName')
-                       ->will($this->returnValue($canChangeDisplayName));
-               $user
-                       ->expects($expectsUpdate ? $this->once() : $this->never())
-                       ->method('setEMailAddress')
-                       ->with(
-                               $this->equalTo($mailAddress)
-                       );
-
-               $this->userSession
-                       ->expects($this->atLeastOnce())
-                       ->method('getUser')
-                       ->will($this->returnValue($user));
-               $this->mailer
-                       ->expects($this->any())
-                       ->method('validateMailAddress')
-                       ->with($mailAddress)
-                       ->willReturn($isValid);
-
-               if ($isValid) {
-                       $user->expects($this->atLeastOnce())
-                               ->method('canChangeDisplayName')
-                               ->willReturn(true);
-
-                       $this->userManager
-                               ->expects($this->atLeastOnce())
-                               ->method('get')
-                               ->with('foo')
-                               ->will($this->returnValue($user));
-               }
-
-               $response = $controller->setMailAddress($user->getUID(), $mailAddress);
-
-               $this->assertSame($responseCode, $response->getStatus());
-       }
-
        public function testStatsAdmin() {
                $controller = $this->getController(true);
 
@@ -1976,6 +1913,7 @@ class UsersControllerTest extends \Test\TestCase {
                        ->method('get')
                        ->with($editUser->getUID())
                        ->willReturn($editUser);
+               $this->accountManager->expects($this->any())->method('getUser')->willReturn([]);
 
                $subadmin = $this->getMockBuilder('\OC\SubAdmin')
                        ->disableOriginalConstructor()
@@ -1994,10 +1932,6 @@ class UsersControllerTest extends \Test\TestCase {
                        ->willReturn($isAdmin);
 
                if ($valid === true) {
-                       $editUser->expects($this->once())
-                               ->method('setDisplayName')
-                               ->with('newDisplayName')
-                               ->willReturn(true);
                        $expectedResponse = new DataResponse(
                                [
                                        'status' => 'success',
@@ -2009,7 +1943,6 @@ class UsersControllerTest extends \Test\TestCase {
                                ]
                        );
                } else {
-                       $editUser->expects($this->never())->method('setDisplayName');
                        $expectedResponse = new DataResponse(
                                [
                                        'status' => 'error',