fixed tests

This commit is contained in:
Andreas Gohr
2020-02-24 15:03:57 +01:00
parent e07bbff94a
commit 210e2f5d95
3 changed files with 38 additions and 33 deletions

View File

@ -2,6 +2,7 @@
language: php
php:
- "7.4"
- "7.3"
- "7.2"
- "7.1"

View File

@ -1,49 +1,53 @@
<?php
/**
* General tests for the smtp plugin
*
* @group plugin_smtp
* @group plugins
*/
class message_plugin_smtp_test extends DokuWikiTest {
public function setUp() {
class message_plugin_smtp_test extends DokuWikiTest
{
public function setUp()
{
parent::setUp();
require_once __DIR__ . '/../loader.php';
}
public function test_body() {
$input = trim('
X-Mailer: DokuWiki
X-Dokuwiki-User: admin
X-Dokuwiki-Title: Test Wiki
X-Dokuwiki-Server: localhost.localhost
From: a@example.com
To: b@example.com
Bcc: c@example.com, d@example.com,
d@example.com
Subject: A test
public function test_body()
{
$input = join("\r\n", [
'X-Mailer: DokuWiki',
'X-Dokuwiki-User: admin',
'X-Dokuwiki-Title: Test Wiki',
'X-Dokuwiki-Server: localhost.localhost',
'From: a@example.com',
'To: b@example.com',
'Bcc: c@example.com, d@example.com,',
' d@example.com',
'Subject: A test',
'',
'This is the body of the mail',
'Bcc: this is not a header line',
'end of message',
]);
This is the body of the mail
Bcc: this is not a header line
end of message
');
$expect = trim('
X-Mailer: DokuWiki
X-Dokuwiki-User: admin
X-Dokuwiki-Title: Test Wiki
X-Dokuwiki-Server: localhost.localhost
From: a@example.com
To: b@example.com
Subject: A test
This is the body of the mail
Bcc: this is not a header line
end of message
');
$expect = join("\r\n", [
'X-Mailer: DokuWiki',
'X-Dokuwiki-User: admin',
'X-Dokuwiki-Title: Test Wiki',
'X-Dokuwiki-Server: localhost.localhost',
'From: a@example.com',
'To: b@example.com',
'Subject: A test',
'',
'This is the body of the mail',
'Bcc: this is not a header line',
'end of message',
]);
$expect .= "\r\n\r\n.\r\n";
$message = new \splitbrain\dokuwiki\plugin\smtp\Message('','',$input);
$message = new \splitbrain\dokuwiki\plugin\smtp\Message('', '', $input);
$this->assertEquals($expect, $message->toString());

View File

@ -73,7 +73,7 @@ class Message extends \Tx\Mailer\Message {
*/
public function toString() {
// we need to remove the BCC header here
$lines = explode("\n", $this->body);
$lines = preg_split('/\r?\n/', $this->body);
$count = count($lines);
for($i=0; $i<$count; $i++) {
if(trim($lines[$i]) === '') break; // end of headers, we're done