]> source.dussan.org Git - nextcloud-server.git/commitdiff
Show more detailed error message
authorLukas Reschke <lukas@owncloud.com>
Thu, 19 Feb 2015 20:55:02 +0000 (21:55 +0100)
committerLukas Reschke <lukas@owncloud.com>
Mon, 16 Mar 2015 11:47:06 +0000 (12:47 +0100)
lib/private/mail/mailer.php
settings/controller/mailsettingscontroller.php
tests/lib/mail/mailer.php
tests/settings/controller/mailsettingscontrollertest.php

index 92e6b91ce1c6511d05c6bc72db0592617ef99709..83dd050edbcf841a09c27eb16b770f8b3890baa5 100644 (file)
@@ -149,6 +149,7 @@ class Mailer implements IMailer {
                if (!empty($smtpSecurity)) {
                        $transport->setEncryption($smtpSecurity);
                }
+               $transport->start();
                return $transport;
        }
 
index 43715b82237cac44a1ee5bd12de7a582fb72ecf3..53365cf253bd463f02233cebd6679a2c335d875f 100644 (file)
@@ -135,19 +135,19 @@ class MailSettingsController extends Controller {
                $email = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'email', '');
                if (!empty($email)) {
                        try {
-                               $this->mail->send($email, $this->userSession->getUser()->getDisplayName(),
-                                       $this->l10n->t('test email settings'),
-                                       $this->l10n->t('If you received this email, the settings seem to be correct.'),
-                                       $this->defaultMailAddress,
-                                       $this->defaults->getName()
-                               );
+                               $message = $this->mailer->createMessage();
+                               $message->setTo([$email => $this->userSession->getUser()->getDisplayName()]);
+                               $message->setFrom([$this->defaultMailAddress]);
+                               $message->setSubject($this->l10n->t('test email settings'));
+                               $message->setPlainBody('If you received this email, the settings seem to be correct.');
+                               $this->mailer->send($message);
                        } catch (\Exception $e) {
-                               return array('data' =>
-                                       array('message' =>
-                                               (string) $this->l10n->t('A problem occurred while sending the email. Please revise your settings.'),
-                                       ),
-                                       'status' => 'error'
-                               );
+                               return [
+                                       'data' => [
+                                               'message' => (string) $this->l10n->t('A problem occurred while sending the email. Please revise your settings. (Error: %s)', [$e->getMessage()]),
+                                       ],
+                                       'status' => 'error',
+                               ];
                        }
 
                        return array('data' =>
index 2cb4c5cfde352142061744d9dcee516e747f91dc..8929bfdf99d90b335f614da2468bb17fd34db8f9 100644 (file)
@@ -53,20 +53,6 @@ class MailerTest extends TestCase {
                $this->assertEquals(\Swift_SendmailTransport::newInstance('/var/qmail/bin/sendmail -bs'), \Test_Helper::invokePrivate($this->mailer, 'getSendMailInstance'));
        }
 
-       public function testGetSmtpInstanceDefaults() {
-               $expected = \Swift_SmtpTransport::newInstance();
-               $expected->setHost('127.0.0.1');
-               $expected->setTimeout(10);
-               $expected->setPort(25);
-
-               $this->config
-                       ->expects($this->any())
-                       ->method('getSystemValue')
-                       ->will($this->returnArgument(1));
-
-               $this->assertEquals($expected, \Test_Helper::invokePrivate($this->mailer, 'getSmtpInstance'));
-       }
-
        public function testGetInstanceDefault() {
                $this->assertInstanceOf('\Swift_MailTransport', \Test_Helper::invokePrivate($this->mailer, 'getInstance'));
        }
@@ -80,15 +66,6 @@ class MailerTest extends TestCase {
                $this->assertInstanceOf('\Swift_MailTransport', \Test_Helper::invokePrivate($this->mailer, 'getInstance'));
        }
 
-       public function testGetInstanceSmtp() {
-               $this->config
-                       ->expects($this->any())
-                       ->method('getSystemValue')
-                       ->will($this->returnValue('smtp'));
-
-               $this->assertInstanceOf('\Swift_SmtpTransport', \Test_Helper::invokePrivate($this->mailer, 'getInstance'));
-       }
-
        public function testGetInstanceSendmail() {
                $this->config
                        ->expects($this->any())
index 84432f656bf3f8893fb944c224dae3affb7eb656..cc25fda52f7a7014ec88413ec66ef6ed0c05ef3e 100644 (file)
@@ -32,6 +32,9 @@ class MailSettingsControllerTest extends \Test\TestCase {
                        ->disableOriginalConstructor()->getMock();
                $this->container['MailMessage'] = $this->getMockBuilder('\OCP\Mail\IMessage')
                        ->disableOriginalConstructor()->getMock();
+               $this->container['Mailer'] = $this->getMockBuilder('\OC\Mail\Mailer')
+                       ->setMethods(['send'])
+                       ->disableOriginalConstructor()->getMock();
                $this->container['Defaults'] = $this->getMockBuilder('\OC_Defaults')
                        ->disableOriginalConstructor()->getMock();
                $this->container['DefaultMailAddress'] = 'no-reply@owncloud.com';