diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2015-05-05 12:57:15 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2015-05-05 13:53:00 +0200 |
commit | d36d14366b1d174cf3a2ea53b38f0955dc48ffd2 (patch) | |
tree | 8d23af203229e525565cf1009504115e0f55cc70 /tests/settings | |
parent | 5fd849f5457cd7f9d47c6fa5019ff0f79fcbc6af (diff) | |
download | nextcloud-server-d36d14366b1d174cf3a2ea53b38f0955dc48ffd2.tar.gz nextcloud-server-d36d14366b1d174cf3a2ea53b38f0955dc48ffd2.zip |
Add test for setEmailAddress
Diffstat (limited to 'tests/settings')
-rw-r--r-- | tests/settings/controller/userscontrollertest.php | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/settings/controller/userscontrollertest.php b/tests/settings/controller/userscontrollertest.php index 25c935bef58..b9d45d786ec 100644 --- a/tests/settings/controller/userscontrollertest.php +++ b/tests/settings/controller/userscontrollertest.php @@ -1388,4 +1388,74 @@ class UsersControllerTest extends \Test\TestCase { $this->assertEquals($expectedResult, $result); } + public function setEmailAddressData() { + return [ + ['', true, false, true], + ['foobar@localhost', true, true, false], + ['foo@bar@localhost', false, false, false], + ]; + } + + /** + * @dataProvider setEmailAddressData + * + * @param string $mailAddress + * @param bool $isValid + * @param bool $expectsUpdate + * @param bool $expectsDelete + */ + public function testSetEmailAddress($mailAddress, $isValid, $expectsUpdate, $expectsDelete) { + $this->container['IsAdmin'] = true; + + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $user + ->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('foo')); + $this->container['UserSession'] + ->expects($this->atLeastOnce()) + ->method('getUser') + ->will($this->returnValue($user)); + $this->container['Mailer'] + ->expects($this->any()) + ->method('validateMailAddress') + ->with($mailAddress) + ->willReturn($isValid); + + if ($isValid) { + $user->expects($this->atLeastOnce()) + ->method('canChangeDisplayName') + ->willReturn(true); + + $this->container['UserManager'] + ->expects($this->atLeastOnce()) + ->method('get') + ->with('foo') + ->will($this->returnValue($user)); + } + + $this->container['Config'] + ->expects(($expectsUpdate) ? $this->once() : $this->never()) + ->method('setUserValue') + ->with( + $this->equalTo($user->getUID()), + $this->equalTo('settings'), + $this->equalTo('email'), + $this->equalTo($mailAddress) + + ); + $this->container['Config'] + ->expects(($expectsDelete) ? $this->once() : $this->never()) + ->method('deleteUserValue') + ->with( + $this->equalTo($user->getUID()), + $this->equalTo('settings'), + $this->equalTo('email') + + ); + + $this->container['UsersController']->setMailAddress($user->getUID(), $mailAddress); + } + } |