diff options
author | Lukas Reschke <lukas@owncloud.com> | 2015-03-17 11:15:39 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2015-03-17 11:15:39 +0100 |
commit | b1c19f74a1d245bd8a4a807e73bbe58860d55314 (patch) | |
tree | 250b6b85573a01ee5677b1c99d73d0e2d13d32bd /tests/core | |
parent | 65259114391eaeab1f6ceb44e52e2c0a5efa9027 (diff) | |
parent | 7a70fffa6cd1597e588111cd39054b80adf296c0 (diff) | |
download | nextcloud-server-b1c19f74a1d245bd8a4a807e73bbe58860d55314.tar.gz nextcloud-server-b1c19f74a1d245bd8a4a807e73bbe58860d55314.zip |
Merge pull request #12085 from owncloud/add-swift-mailer
Migrate OC_Mail to SwiftMailer
Diffstat (limited to 'tests/core')
-rw-r--r-- | tests/core/lostpassword/controller/lostcontrollertest.php | 101 |
1 files changed, 92 insertions, 9 deletions
diff --git a/tests/core/lostpassword/controller/lostcontrollertest.php b/tests/core/lostpassword/controller/lostcontrollertest.php index b03cbd7c42f..f82fc1ba3ff 100644 --- a/tests/core/lostpassword/controller/lostcontrollertest.php +++ b/tests/core/lostpassword/controller/lostcontrollertest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com> + * Copyright (c) 2014-2015 Lukas Reschke <lukas@owncloud.com> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -43,6 +43,8 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase { ->disableOriginalConstructor()->getMock(); $this->container['URLGenerator'] = $this->getMockBuilder('\OCP\IURLGenerator') ->disableOriginalConstructor()->getMock(); + $this->container['Mailer'] = $this->getMockBuilder('\OCP\Mail\IMailer') + ->disableOriginalConstructor()->getMock(); $this->container['SecureRandom'] = $this->getMockBuilder('\OCP\Security\ISecureRandom') ->disableOriginalConstructor()->getMock(); $this->container['IsEncryptionEnabled'] = true; @@ -103,14 +105,6 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase { } public function testEmailSuccessful() { - /** - * FIXME: Disable test for systems where no sendmail is available since code is static. - * @link https://github.com/owncloud/core/pull/12085 - */ - if (is_null(\OC_Helper::findBinaryPath('sendmail'))) { - $this->markTestSkipped('sendmail is not available'); - } - $randomToken = $this->container['SecureRandom']; $this->container['SecureRandom'] ->expects($this->once()) @@ -140,12 +134,101 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase { ->method('linkToRouteAbsolute') ->with('core.lost.resetform', array('userId' => 'ExistingUser', 'token' => 'ThisIsMaybeANotSoSecretToken!')) ->will($this->returnValue('https://ownCloud.com/index.php/lostpassword/')); + $message = $this->getMockBuilder('\OC\Mail\Message') + ->disableOriginalConstructor()->getMock(); + $message + ->expects($this->at(0)) + ->method('setTo') + ->with(['test@example.com' => 'ExistingUser']); + $message + ->expects($this->at(1)) + ->method('setSubject') + ->with(' password reset'); + $message + ->expects($this->at(2)) + ->method('setPlainBody') + ->with('Use the following link to reset your password: https://ownCloud.com/index.php/lostpassword/'); + $message + ->expects($this->at(3)) + ->method('setFrom') + ->with(['lostpassword-noreply@localhost' => null]); + $this->container['Mailer'] + ->expects($this->at(0)) + ->method('createMessage') + ->will($this->returnValue($message)); + $this->container['Mailer'] + ->expects($this->at(1)) + ->method('send') + ->with($message); $response = $this->lostController->email('ExistingUser'); $expectedResponse = array('status' => 'success'); $this->assertSame($expectedResponse, $response); } + public function testEmailCantSendException() { + $randomToken = $this->container['SecureRandom']; + $this->container['SecureRandom'] + ->expects($this->once()) + ->method('generate') + ->with('21') + ->will($this->returnValue('ThisIsMaybeANotSoSecretToken!')); + $this->container['UserManager'] + ->expects($this->once()) + ->method('userExists') + ->with('ExistingUser') + ->will($this->returnValue(true)); + $this->container['Config'] + ->expects($this->once()) + ->method('getUserValue') + ->with('ExistingUser', 'settings', 'email') + ->will($this->returnValue('test@example.com')); + $this->container['SecureRandom'] + ->expects($this->once()) + ->method('getMediumStrengthGenerator') + ->will($this->returnValue($randomToken)); + $this->container['Config'] + ->expects($this->once()) + ->method('setUserValue') + ->with('ExistingUser', 'owncloud', 'lostpassword', 'ThisIsMaybeANotSoSecretToken!'); + $this->container['URLGenerator'] + ->expects($this->once()) + ->method('linkToRouteAbsolute') + ->with('core.lost.resetform', array('userId' => 'ExistingUser', 'token' => 'ThisIsMaybeANotSoSecretToken!')) + ->will($this->returnValue('https://ownCloud.com/index.php/lostpassword/')); + $message = $this->getMockBuilder('\OC\Mail\Message') + ->disableOriginalConstructor()->getMock(); + $message + ->expects($this->at(0)) + ->method('setTo') + ->with(['test@example.com' => 'ExistingUser']); + $message + ->expects($this->at(1)) + ->method('setSubject') + ->with(' password reset'); + $message + ->expects($this->at(2)) + ->method('setPlainBody') + ->with('Use the following link to reset your password: https://ownCloud.com/index.php/lostpassword/'); + $message + ->expects($this->at(3)) + ->method('setFrom') + ->with(['lostpassword-noreply@localhost' => null]); + $this->container['Mailer'] + ->expects($this->at(0)) + ->method('createMessage') + ->will($this->returnValue($message)); + $this->container['Mailer'] + ->expects($this->at(1)) + ->method('send') + ->with($message) + ->will($this->throwException(new \Exception())); + + $response = $this->lostController->email('ExistingUser'); + $expectedResponse = ['status' => 'error', 'msg' => 'Couldn\'t send reset email. Please contact your administrator.']; + $this->assertSame($expectedResponse, $response); + } + public function testSetPasswordUnsuccessful() { $this->container['Config'] ->expects($this->once()) |