summaryrefslogtreecommitdiffstats
path: root/tests/Settings/Controller/MailSettingsControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Settings/Controller/MailSettingsControllerTest.php')
-rw-r--r--tests/Settings/Controller/MailSettingsControllerTest.php113
1 files changed, 50 insertions, 63 deletions
diff --git a/tests/Settings/Controller/MailSettingsControllerTest.php b/tests/Settings/Controller/MailSettingsControllerTest.php
index 1ac6bae69ea..2012de886c8 100644
--- a/tests/Settings/Controller/MailSettingsControllerTest.php
+++ b/tests/Settings/Controller/MailSettingsControllerTest.php
@@ -10,75 +10,60 @@
namespace Tests\Settings\Controller;
-use OC\Settings\Application;
+use OC\Mail\Message;
+use OC\Settings\Controller\MailSettingsController;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IRequest;
+use OCP\IUserSession;
+use OCP\Mail\IMailer;
/**
* @package Tests\Settings\Controller
*/
class MailSettingsControllerTest extends \Test\TestCase {
- private $container;
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
+ private $config;
+ /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
+ private $userSession;
+ /** @var IMailer|\PHPUnit_Framework_MockObject_MockObject */
+ private $mailer;
+ /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
+ private $l;
+
+ /** @var MailSettingsController */
+ private $mailController;
protected function setUp() {
parent::setUp();
- $app = new Application();
- $this->container = $app->getContainer();
- $this->container['Config'] = $this->getMockBuilder('\OCP\IConfig')
- ->disableOriginalConstructor()->getMock();
- $this->container['L10N'] = $this->getMockBuilder('\OCP\IL10N')
- ->disableOriginalConstructor()->getMock();
- $this->container['AppName'] = 'settings';
- $this->container['UserSession'] = $this->getMockBuilder('\OC\User\Session')
- ->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';
+ $this->l = $this->createMock(IL10N::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->userSession = $this->createMock(IUserSession::class);
+ $this->mailer = $this->createMock(IMailer::class);
+// $this->mailer = $this->getMockBuilder(IMailer::class)
+// ->setMethods(['send'])
+// ->getMock();
+ $this->mailController = new MailSettingsController(
+ 'settings',
+ $this->createMock(IRequest::class),
+ $this->l,
+ $this->config,
+ $this->userSession,
+ $this->mailer,
+ 'no-reply@owncloud.com'
+ );
}
public function testSetMailSettings() {
- $this->container['L10N']
+ $this->l
->expects($this->exactly(2))
->method('t')
->will($this->returnValue('Saved'));
- /**
- * FIXME: Use the following block once Jenkins uses PHPUnit >= 4.1
- */
- /*
- $this->container['Config']
- ->expects($this->exactly(15))
- ->method('setSystemValue')
- ->withConsecutive(
- array($this->equalTo('mail_domain'), $this->equalTo('owncloud.com')),
- array($this->equalTo('mail_from_address'), $this->equalTo('demo@owncloud.com')),
- array($this->equalTo('mail_smtpmode'), $this->equalTo('smtp')),
- array($this->equalTo('mail_smtpsecure'), $this->equalTo('ssl')),
- array($this->equalTo('mail_smtphost'), $this->equalTo('mx.owncloud.org')),
- array($this->equalTo('mail_smtpauthtype'), $this->equalTo('NTLM')),
- array($this->equalTo('mail_smtpauth'), $this->equalTo(1)),
- array($this->equalTo('mail_smtpport'), $this->equalTo('25')),
- array($this->equalTo('mail_domain'), $this->equalTo('owncloud.com')),
- array($this->equalTo('mail_from_address'), $this->equalTo('demo@owncloud.com')),
- array($this->equalTo('mail_smtpmode'), $this->equalTo('smtp')),
- array($this->equalTo('mail_smtpsecure'), $this->equalTo('ssl')),
- array($this->equalTo('mail_smtphost'), $this->equalTo('mx.owncloud.org')),
- array($this->equalTo('mail_smtpauthtype'), $this->equalTo('NTLM')),
- array($this->equalTo('mail_smtpport'), $this->equalTo('25'))
- );
- */
-
- /** @var \PHPUnit_Framework_MockObject_MockObject $config */
- $config = $this->container['Config'];
- $config->expects($this->exactly(2))
- ->method('setSystemValues');
- /**
- * FIXME: Use the following block once Jenkins uses PHPUnit >= 4.1
+ $this->config->expects($this->exactly(2))
+ ->method('setSystemValues')
->withConsecutive(
[[
'mail_domain' => 'owncloud.com',
@@ -103,10 +88,9 @@ class MailSettingsControllerTest extends \Test\TestCase {
'mail_smtppassword' => null,
]]
);
- */
// With authentication
- $response = $this->container['MailSettingsController']->setMailSettings(
+ $response = $this->mailController->setMailSettings(
'owncloud.com',
'demo@owncloud.com',
'smtp',
@@ -120,7 +104,7 @@ class MailSettingsControllerTest extends \Test\TestCase {
$this->assertSame($expectedResponse, $response);
// Without authentication (testing the deletion of the stored password)
- $response = $this->container['MailSettingsController']->setMailSettings(
+ $response = $this->mailController->setMailSettings(
'owncloud.com',
'demo@owncloud.com',
'smtp',
@@ -136,12 +120,12 @@ class MailSettingsControllerTest extends \Test\TestCase {
}
public function testStoreCredentials() {
- $this->container['L10N']
+ $this->l
->expects($this->once())
->method('t')
->will($this->returnValue('Saved'));
- $this->container['Config']
+ $this->config
->expects($this->once())
->method('setSystemValues')
->with([
@@ -149,7 +133,7 @@ class MailSettingsControllerTest extends \Test\TestCase {
'mail_smtppassword' => 'PasswordToStore',
]);
- $response = $this->container['MailSettingsController']->storeCredentials('UsernameToStore', 'PasswordToStore');
+ $response = $this->mailController->storeCredentials('UsernameToStore', 'PasswordToStore');
$expectedResponse = array('data' => array('message' =>'Saved'), 'status' => 'success');
$this->assertSame($expectedResponse, $response);
@@ -166,7 +150,7 @@ class MailSettingsControllerTest extends \Test\TestCase {
->method('getDisplayName')
->will($this->returnValue('Werner Brösel'));
- $this->container['L10N']
+ $this->l
->expects($this->any())
->method('t')
->will(
@@ -182,22 +166,25 @@ class MailSettingsControllerTest extends \Test\TestCase {
'If you received this email, the settings seem to be correct.')
)
));
- $this->container['UserSession']
+ $this->userSession
->expects($this->any())
->method('getUser')
->will($this->returnValue($user));
// Ensure that it fails when no mail address has been specified
- $response = $this->container['MailSettingsController']->sendTestMail();
+ $response = $this->mailController->sendTestMail();
$expectedResponse = array('data' => array('message' =>'You need to set your user email before being able to send test emails.'), 'status' => 'error');
$this->assertSame($expectedResponse, $response);
// If no exception is thrown it should work
- $this->container['Config']
+ $this->config
->expects($this->any())
->method('getUserValue')
->will($this->returnValue('mail@example.invalid'));
- $response = $this->container['MailSettingsController']->sendTestMail();
+ $this->mailer->expects($this->once())
+ ->method('createMessage')
+ ->willReturn($this->createMock(Message::class));
+ $response = $this->mailController->sendTestMail();
$expectedResponse = array('data' => array('message' =>'Email sent'), 'status' => 'success');
$this->assertSame($expectedResponse, $response);
}