Add testcases for pipe mode

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
This commit is contained in:
Daniel Kesselberg 2018-11-28 20:06:48 +01:00
parent 92675a606e
commit 4a2c56b714
No known key found for this signature in database
GPG Key ID: 36E3664E099D0614
3 changed files with 50 additions and 14 deletions

View File

@ -74,6 +74,7 @@ class MailSettingsControllerTest extends \Test\TestCase {
'mail_smtpauthtype' => 'NTLM', 'mail_smtpauthtype' => 'NTLM',
'mail_smtpauth' => 1, 'mail_smtpauth' => 1,
'mail_smtpport' => '25', 'mail_smtpport' => '25',
'mail_sendmailmode' => null,
]], ]],
[[ [[
'mail_domain' => 'nextcloud.com', 'mail_domain' => 'nextcloud.com',
@ -86,6 +87,7 @@ class MailSettingsControllerTest extends \Test\TestCase {
'mail_smtpport' => '25', 'mail_smtpport' => '25',
'mail_smtpname' => null, 'mail_smtpname' => null,
'mail_smtppassword' => null, 'mail_smtppassword' => null,
'mail_sendmailmode' => null,
]] ]]
); );
@ -98,7 +100,8 @@ class MailSettingsControllerTest extends \Test\TestCase {
'mx.nextcloud.org', 'mx.nextcloud.org',
'NTLM', 'NTLM',
1, 1,
'25' '25',
null
); );
$this->assertSame(Http::STATUS_OK, $response->getStatus()); $this->assertSame(Http::STATUS_OK, $response->getStatus());
@ -111,7 +114,8 @@ class MailSettingsControllerTest extends \Test\TestCase {
'mx.nextcloud.org', 'mx.nextcloud.org',
'NTLM', 'NTLM',
0, 0,
'25' '25',
null
); );
$this->assertSame(Http::STATUS_OK, $response->getStatus()); $this->assertSame(Http::STATUS_OK, $response->getStatus());

View File

@ -48,30 +48,54 @@ class MailerTest extends TestCase {
); );
} }
public function testGetSendMailInstanceSendMail() { /**
* @return array
*/
public function sendmailModeProvider(): array {
return [
'smtp' => ['smtp', ' -bs'],
'pipe' => ['pipe', ' -t'],
];
}
/**
* @dataProvider sendmailModeProvider
* @param $sendmailMode
* @param $binaryParam
*/
public function testGetSendmailInstanceSendMail($sendmailMode, $binaryParam) {
$this->config $this->config
->expects($this->once()) ->expects($this->exactly(2))
->method('getSystemValue') ->method('getSystemValue')
->with('mail_smtpmode', 'smtp') ->will($this->returnValueMap([
->will($this->returnValue('sendmail')); ['mail_smtpmode', 'smtp', 'sendmail'],
['mail_sendmailmode', 'smtp', $sendmailMode],
]));
$path = \OC_Helper::findBinaryPath('sendmail'); $path = \OC_Helper::findBinaryPath('sendmail');
if ($path === null) { if ($path === null) {
$path = '/usr/sbin/sendmail'; $path = '/usr/sbin/sendmail';
} }
$expected = new \Swift_SendmailTransport($path . ' -bs'); $expected = new \Swift_SendmailTransport($path . $binaryParam);
$this->assertEquals($expected, self::invokePrivate($this->mailer, 'getSendMailInstance')); $this->assertEquals($expected, self::invokePrivate($this->mailer, 'getSendMailInstance'));
} }
public function testGetSendMailInstanceSendMailQmail() { /**
* @dataProvider sendmailModeProvider
* @param $sendmailMode
* @param $binaryParam
*/
public function testGetSendmailInstanceSendMailQmail($sendmailMode, $binaryParam) {
$this->config $this->config
->expects($this->once()) ->expects($this->exactly(2))
->method('getSystemValue') ->method('getSystemValue')
->with('mail_smtpmode', 'smtp') ->will($this->returnValueMap([
->will($this->returnValue('qmail')); ['mail_smtpmode', 'smtp', 'qmail'],
['mail_sendmailmode', 'smtp', $sendmailMode],
]));
$this->assertEquals(new \Swift_SendmailTransport('/var/qmail/bin/sendmail -bs'), self::invokePrivate($this->mailer, 'getSendMailInstance')); $this->assertEquals(new \Swift_SendmailTransport('/var/qmail/bin/sendmail' . $binaryParam), self::invokePrivate($this->mailer, 'getSendMailInstance'));
} }
public function testGetInstanceDefault() { public function testGetInstanceDefault() {
@ -83,8 +107,10 @@ class MailerTest extends TestCase {
public function testGetInstanceSendmail() { public function testGetInstanceSendmail() {
$this->config $this->config
->method('getSystemValue') ->method('getSystemValue')
->with('mail_smtpmode', 'smtp') ->will($this->returnValueMap([
->willReturn('sendmail'); ['mail_smtpmode', 'smtp', 'sendmail'],
['mail_sendmailmode', 'smtp', 'smtp'],
]));
$mailer = self::invokePrivate($this->mailer, 'getInstance'); $mailer = self::invokePrivate($this->mailer, 'getInstance');
$this->assertInstanceOf(\Swift_Mailer::class, $mailer); $this->assertInstanceOf(\Swift_Mailer::class, $mailer);

View File

@ -95,6 +95,11 @@ class MailTest extends TestCase {
->method('getSystemValue') ->method('getSystemValue')
->with('mail_smtppassword', '') ->with('mail_smtppassword', '')
->willReturn('mypassword'); ->willReturn('mypassword');
$this->config
->expects($this->at(10))
->method('getSystemValue')
->with('mail_sendmailmode', 'smtp')
->willReturn('smtp');
$expected = new TemplateResponse( $expected = new TemplateResponse(
'settings', 'settings',
@ -111,6 +116,7 @@ class MailTest extends TestCase {
'mail_smtpauth' => true, 'mail_smtpauth' => true,
'mail_smtpname' => 'smtp.sender.com', 'mail_smtpname' => 'smtp.sender.com',
'mail_smtppassword' => '********', 'mail_smtppassword' => '********',
'mail_sendmailmode' => 'smtp',
], ],
'' ''
); );