Commit 7e2b987c authored by Carsten  Rose's avatar Carsten Rose
Browse files

Fixed Unit Tests

parent f0e6e4d6
......@@ -21,59 +21,70 @@ class SendMailTest extends \PHPUnit_Framework_TestCase {
*/
private $sendMail = null;
public function parseStringToArray() {
public function testParseStringToArray() {
$this->sendMail = new SendMail();
// Minimal setup
$result = $this->sendMail->parseStringToArray('');
$expect = [''];
$expect = [];
$this->assertEquals($expect, $result);
// Simple 'fixed position' DEPRECATED - not sure if it's ok that the array is not fillled up to the maximum.
$result = $this->sendMail->parseStringToArray('john@doe.com|jane@miller.com|Latest|Dear John');
$expect = ['john@doe.com', 'jane@miller.com', 'Latest', 'Dear John'];
$this->assertEquals($expect, $result);
// $result = $this->sendMail->parseStringToArray('john@doe.com|jane@miller.com|Latest|Dear John');
// $expect = ['john@doe.com', 'jane@miller.com', 'Latest', 'Dear John'];
// $this->assertEquals($expect, $result);
// Simple 'token based'
$result = $this->sendMail->parseStringToArray('t:john@doe.com|f:jane@miller.com|s:Latest|b:Dear John');
$expect = ['john@doe.com', 'jane@miller.com', 'Latest', 'Dear John', '', '', '', '', '', '', '', '', '', '', '', '', ''];
$expect = [SENDMAIL_TOKEN_RECEIVER => 'john@doe.com', SENDMAIL_TOKEN_SENDER => 'jane@miller.com',
SENDMAIL_TOKEN_SUBJECT => 'Latest', SENDMAIL_TOKEN_BODY => 'Dear John'];
$this->assertEquals($expect, $result);
// All (but attachment) 'token based'
$result = $this->sendMail->parseStringToArray('t:john@doe.com|f:jane@miller.com|s:Latest|b:Dear John|r:reply@doe.com|A:on|g:123|x:234|c:july@doe.com,steve@doe.com|B:ceo@doe.com|h:Auto-Submit: fake|y:345|z:456|S:test.php');
$expect = ['john@doe.com', 'jane@miller.com', 'Latest', 'Dear John', 'reply@doe.com', 'on', '123', '234', 'july@doe.com,steve@doe.com', 'ceo@doe.com', '', 'Auto-Submit: fake', '345', '456', 'test.php', '', ''];
$expect = [SENDMAIL_TOKEN_RECEIVER => 'john@doe.com', SENDMAIL_TOKEN_SENDER => 'jane@miller.com',
SENDMAIL_TOKEN_SUBJECT => 'Latest', SENDMAIL_TOKEN_BODY => 'Dear John', SENDMAIL_TOKEN_REPLY_TO => 'reply@doe.com',
SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT => 'on', SENDMAIL_TOKEN_GR_ID => '123', SENDMAIL_TOKEN_X_ID => '234',
SENDMAIL_TOKEN_RECEIVER_CC => 'july@doe.com,steve@doe.com', SENDMAIL_TOKEN_RECEIVER_BCC => 'ceo@doe.com',
SENDMAIL_TOKEN_HEADER => 'Auto-Submit: fake', SENDMAIL_TOKEN_X_ID2 => '345', SENDMAIL_TOKEN_X_ID3 => '456', SENDMAIL_TOKEN_SRC => 'test.php'];
$this->assertEquals($expect, $result);
// Single attachment 'token based'
$attach = [['F:fileadmin/test1.pdf']];
$result = $this->sendMail->parseStringToArray('t:john@doe.com|f:jane@miller.com|s:Latest|b:Dear John|F:fileadmin/test1.pdf');
$expect = ['john@doe.com', 'jane@miller.com', 'Latest', 'Dear John', '', '', '', '', '', '', $attach, '', '', '', '', '', ''];
$expect = [SENDMAIL_TOKEN_RECEIVER => 'john@doe.com', SENDMAIL_TOKEN_SENDER => 'jane@miller.com',
SENDMAIL_TOKEN_SUBJECT => 'Latest', SENDMAIL_TOKEN_BODY => 'Dear John', SENDMAIL_TOKEN_ATTACHMENT => $attach];
$this->assertEquals($expect, $result);
// Three individual attachment 'token based'
// $attach = [ [ [ 'F' => 'fileadmin/test1.pdf' ], [ 'F' => 'fileadmin/test2.pdf' ], [ 'F' => 'fileadmin/test3.pdf' ] ] ] ;
$attach = [['F:fileadmin/test1.pdf'], ['F:fileadmin/test2.pdf'], ['F:fileadmin/test3.pdf']];
$result = $this->sendMail->parseStringToArray('t:john@doe.com|f:jane@miller.com|s:Latest|b:Dear John|F:fileadmin/test1.pdf|F:fileadmin/test2.pdf|F:fileadmin/test3.pdf');
$expect = ['john@doe.com', 'jane@miller.com', 'Latest', 'Dear John', '', '', '', '', '', '', $attach, '', '', '', '', '', ''];
$expect = [SENDMAIL_TOKEN_RECEIVER => 'john@doe.com', SENDMAIL_TOKEN_SENDER => 'jane@miller.com',
SENDMAIL_TOKEN_SUBJECT => 'Latest', SENDMAIL_TOKEN_BODY => 'Dear John', SENDMAIL_TOKEN_ATTACHMENT => $attach];
$this->assertEquals($expect, $result);
// One individual attachment, one dual combined attachment
$attach = [['F:fileadmin/test1.pdf'], ['F:fileadmin/test2.pdf', 'F:fileadmin/test3.pdf']];
$result = $this->sendMail->parseStringToArray('t:john@doe.com|f:jane@miller.com|s:Latest|b:Dear John|F:fileadmin/test1.pdf|C|F:fileadmin/test2.pdf|F:fileadmin/test3.pdf');
$expect = ['john@doe.com', 'jane@miller.com', 'Latest', 'Dear John', '', '', '', '', '', '', $attach, '', '', '', '', '', ''];
$expect = [SENDMAIL_TOKEN_RECEIVER => 'john@doe.com', SENDMAIL_TOKEN_SENDER => 'jane@miller.com',
SENDMAIL_TOKEN_SUBJECT => 'Latest', SENDMAIL_TOKEN_BODY => 'Dear John', SENDMAIL_TOKEN_ATTACHMENT => $attach];
$this->assertEquals($expect, $result);
// One individual attachment, one quad combined attachment
$attach = [['F:fileadmin/test1.pdf'], ['F:fileadmin/test2.pdf', 'F:fileadmin/test3.pdf', 'u:http://nzz.ch', 'U:export&a=100']];
$result = $this->sendMail->parseStringToArray('t:john@doe.com|f:jane@miller.com|s:Latest|b:Dear John|F:fileadmin/test1.pdf|C|F:fileadmin/test2.pdf|F:fileadmin/test3.pdf|u:http://nzz.ch|U:export&a=100');
$expect = ['john@doe.com', 'jane@miller.com', 'Latest', 'Dear John', '', '', '', '', '', '', $attach, '', '', '', '', '', ''];
$expect = [SENDMAIL_TOKEN_RECEIVER => 'john@doe.com', SENDMAIL_TOKEN_SENDER => 'jane@miller.com',
SENDMAIL_TOKEN_SUBJECT => 'Latest', SENDMAIL_TOKEN_BODY => 'Dear John', SENDMAIL_TOKEN_ATTACHMENT => $attach];
$this->assertEquals($expect, $result);
// Two quad combined attachments
$attach = [['d:output1.pdf', 'F:fileadmin/test11.pdf', 'F:fileadmin/test12.pdf', 'u:http://nzz.ch.1', 'U:export1&a=100'], ['d:output2.pdf', 'F:fileadmin/test21.pdf', 'F:fileadmin/test22.pdf', 'u:http://nzz.ch.2', 'U:export2&a=100']];
$result = $this->sendMail->parseStringToArray('t:john@doe.com|f:jane@miller.com|s:Latest|b:Dear John|C|d:output1.pdf|F:fileadmin/test11.pdf|F:fileadmin/test12.pdf|u:http://nzz.ch.1|U:export1&a=100|C|d:output2.pdf|F:fileadmin/test21.pdf|F:fileadmin/test22.pdf|u:http://nzz.ch.2|U:export2&a=100');
$expect = ['john@doe.com', 'jane@miller.com', 'Latest', 'Dear John', '', '', '', '', '', '', $attach, '', '', '', '', '', ''];
$expect = [SENDMAIL_TOKEN_RECEIVER => 'john@doe.com', SENDMAIL_TOKEN_SENDER => 'jane@miller.com',
SENDMAIL_TOKEN_SUBJECT => 'Latest', SENDMAIL_TOKEN_BODY => 'Dear John', SENDMAIL_TOKEN_ATTACHMENT => $attach];
$this->assertEquals($expect, $result);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment