* mail : the mail creator. Allow to create complete mails easily
$mail = new mail ();
$mail->setFrom ("sender@example.com","Sender Example Com");
$mail->addTo ("recipient1@example.com","Recipient1 Example Com");
$mail->addTo ("recipient2@example.com","Recipient2 Example Com");
$mail->setBodyText ("Content of TextBody part");
$mail->addAttachment ("file0.text", "File content");
$contentID1 = $mail->addAttachmentInline ("file2.jpg", "qcqscqs");
$mail->setBodyHTML ("<p>Content of HTMLBody part with inline
<img src='cid:$contentID1'></p>");
echo $mail->getMail ();
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2709 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
136
Tests/mailTest.php
Normal file
136
Tests/mailTest.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/** DomFramework - Tests
|
||||
@package domframework
|
||||
@author Dominique Fournier <dominique@fournier38.fr> */
|
||||
|
||||
/** Test the mail.php file */
|
||||
class test_mail extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_setBodyText1 ()
|
||||
{
|
||||
$mail = new mail ();
|
||||
$mail->setBodyText ("TEST");
|
||||
$res = $mail->getMail ();
|
||||
$this->assertRegExp ("#TEST\r\n$#", $res);
|
||||
}
|
||||
|
||||
public function test_setBodyHTML1 ()
|
||||
{
|
||||
$mail = new mail ();
|
||||
$mail->setBodyHTML ("TEST");
|
||||
$res = $mail->getMail ();
|
||||
$this->assertRegExp ("#^\r\nTEST\r$#m", $res);
|
||||
}
|
||||
|
||||
public function test_setGetBodyText1 ()
|
||||
{
|
||||
$mail = new mail ();
|
||||
$mail->setBodyText ("TEST");
|
||||
$res = $mail->getBodyText ();
|
||||
$this->assertSame ("TEST", $res);
|
||||
}
|
||||
|
||||
public function test_setGetBodyHtml1 ()
|
||||
{
|
||||
$mail = new mail ();
|
||||
$mail->setBodyHtml ("TEST");
|
||||
$res = $mail->getBodyHtml ();
|
||||
$this->assertSame ("TEST", $res);
|
||||
}
|
||||
|
||||
public function test_setFrom1 ()
|
||||
{
|
||||
$mail = new mail ();
|
||||
$mail->setFrom ("test@example.com", "Test Exa1mple Com");
|
||||
$res = $mail->getFrom ();
|
||||
$this->assertSame ("Test Exa1mple Com <test@example.com>\r\n", $res);
|
||||
}
|
||||
|
||||
public function test_addTo1 ()
|
||||
{
|
||||
$mail = new mail ();
|
||||
$mail->addTo ("test@example.com", "Test Exa1mple Com");
|
||||
$res = $mail->getTo ();
|
||||
$this->assertSame ("Test Exa1mple Com <test@example.com>\r\n", $res);
|
||||
}
|
||||
|
||||
public function test_addTo2 ()
|
||||
{
|
||||
$mail = new mail ();
|
||||
$mail->addTo ("test@example.com", "Test Exa1mple Com");
|
||||
$res = $mail->getMail ();
|
||||
$this->assertRegexp ("#^To: Test Exa1mple Com <test@example.com>\r$#m", $res);
|
||||
}
|
||||
|
||||
public function test_setDateTimestamp1 ()
|
||||
{
|
||||
$mail = new mail ();
|
||||
$time = time ();
|
||||
$mail->setDateTimestamp ($time);
|
||||
$res = $mail->getDateTimestamp ();
|
||||
$this->assertSame ($res, $time);
|
||||
}
|
||||
|
||||
public function test_setDateTimestamp2 ()
|
||||
{
|
||||
$mail = new mail ();
|
||||
$time = time ();
|
||||
$mail->setDateTimestamp ($time);
|
||||
$res = $mail->getMail ();
|
||||
$this->assertRegexp ("#^Date: ".preg_quote (date ("r", $time))."\r$#m", $res);
|
||||
}
|
||||
|
||||
public function test_convertPeopleToArray1 ()
|
||||
{
|
||||
$mail = new mail ();
|
||||
$res = $mail->convertPeopleToArray ("toto toto <toto@toto.com>");
|
||||
$this->assertSame ($res, array (array ("name"=>"toto toto",
|
||||
"mail"=>"toto@toto.com")));
|
||||
}
|
||||
|
||||
public function test_convertPeopleToArray2 ()
|
||||
{
|
||||
$mail = new mail ();
|
||||
$res = $mail->convertPeopleToArray ("<toto@toto.com>");
|
||||
$this->assertSame ($res, array (array ("name"=>"",
|
||||
"mail"=>"toto@toto.com")));
|
||||
}
|
||||
|
||||
public function test_convertPeopleToArray3 ()
|
||||
{
|
||||
$mail = new mail ();
|
||||
$res = $mail->convertPeopleToArray ("toto@toto.com,titi@titi.com");
|
||||
$this->assertSame ($res, array (array ("name" => "",
|
||||
"mail" => "toto@toto.com"),
|
||||
array ("name" => "",
|
||||
"mail" => "titi@titi.com")));
|
||||
}
|
||||
|
||||
public function test_convertPeopleToArray4 ()
|
||||
{
|
||||
$mail = new mail ();
|
||||
$res = $mail->convertPeopleToArray ("toto@toto.com");
|
||||
$this->assertSame ($res, array (array ("name"=>"",
|
||||
"mail"=>"toto@toto.com")));
|
||||
}
|
||||
|
||||
public function test_convertPeopleToArray5 ()
|
||||
{
|
||||
$mail = new mail ();
|
||||
$res = $mail->convertPeopleToArray (" <toto@toto.com> , <titi@titi.com>");
|
||||
$this->assertSame ($res, array (array ("name" => "",
|
||||
"mail" => "toto@toto.com"),
|
||||
array ("name" => "",
|
||||
"mail" => "titi@titi.com")));
|
||||
}
|
||||
|
||||
public function test_convertPeopleToArray6 ()
|
||||
{
|
||||
$mail = new mail ();
|
||||
$res = $mail->convertPeopleToArray ("ToTo <toto@toto.com> , <titi@titi.com>");
|
||||
$this->assertSame ($res, array (array ("name" => "ToTo",
|
||||
"mail" => "toto@toto.com"),
|
||||
array ("name" => "",
|
||||
"mail" => "titi@titi.com")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user