Use multibyte text in tests
Add explicit test for UTF-8 with embedded images, see #279 and #377 Add ISO-8859-1 test
This commit is contained in:
parent
947415c73a
commit
50eac8739f
|
|
@ -631,7 +631,7 @@ class SMTP
|
|||
if ($in_headers and $line == '') {
|
||||
$in_headers = false;
|
||||
}
|
||||
//We need to break this line up into several smaller lines
|
||||
//Break this line up into several smaller lines if it's too long
|
||||
//Micro-optimisation: isset($str[$len]) is faster than (strlen($str) > $len),
|
||||
while (isset($line[self::MAX_LINE_LENGTH])) {
|
||||
//Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<title>PHPMailer Test</title>
|
||||
</head>
|
||||
<body>
|
||||
<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;">
|
||||
<h1>This is a test of PHPMailer.</h1>
|
||||
<div align="center">
|
||||
<a href="https://github.com/PHPMailer/PHPMailer/"><img src="images/phpmailer.png" height="90" width="340" alt="PHPMailer rocks"></a>
|
||||
</div>
|
||||
<p>This example uses <strong>HTML</strong>.</p>
|
||||
<p>The PHPMailer image at the top has been embedded automatically.</p>
|
||||
<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;">
|
||||
<h1>This is a test of PHPMailer.</h1>
|
||||
<div align="center">
|
||||
<a href="https://github.com/PHPMailer/PHPMailer/"><img src="images/phpmailer.png" height="90" width="340" alt="PHPMailer rocks"></a>
|
||||
</div>
|
||||
<p>This example uses <strong>HTML</strong>.</p>
|
||||
<p>ISO-8859-1 text: éèîüçÅñæß</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>PHPMailer Test</title>
|
||||
</head>
|
||||
<body>
|
||||
<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;">
|
||||
<h1>This is a test of PHPMailer.</h1>
|
||||
<div align="center">
|
||||
<a href="https://github.com/PHPMailer/PHPMailer/"><img src="images/phpmailer.png" height="90" width="340" alt="PHPMailer rocks"></a>
|
||||
</div>
|
||||
<p>This example uses <strong>HTML</strong>.</p>
|
||||
<p>Chinese text: 郵件內容為空</p>
|
||||
<p>Russian text: Пустое тело сообщения</p>
|
||||
<p>Armenian text: Հաղորդագրությունը դատարկ է</p>
|
||||
<p>Czech text: Prázdné tělo zprávy</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -149,7 +149,7 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase
|
|||
$eol = "<br>\r\n";
|
||||
$bullet_start = '<li>';
|
||||
$bullet_end = "</li>\r\n";
|
||||
$list_start = '<ul>\r\n';
|
||||
$list_start = "<ul>\r\n";
|
||||
$list_end = "</ul>\r\n";
|
||||
} else {
|
||||
$eol = "\r\n";
|
||||
|
|
@ -166,6 +166,7 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase
|
|||
$ReportBody .= '---------------------' . $eol;
|
||||
$ReportBody .= 'phpmailer version: ' . $this->Mail->Version . $eol;
|
||||
$ReportBody .= 'Content Type: ' . $this->Mail->ContentType . $eol;
|
||||
$ReportBody .= 'CharSet: ' . $this->Mail->CharSet . $eol;
|
||||
|
||||
if (strlen($this->Mail->Host) > 0) {
|
||||
$ReportBody .= 'Host: ' . $this->Mail->Host . $eol;
|
||||
|
|
@ -210,7 +211,7 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
// Re-attach the original body
|
||||
$this->Mail->Body .= $eol . $eol . $ReportBody;
|
||||
$this->Mail->Body .= $eol . $ReportBody;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -800,6 +801,29 @@ EOT;
|
|||
$this->assertNotContains("\r\n\r\nMIME-Version:", $msg, 'Incorrect MIME headers');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message containing ISO-8859-1 text.
|
||||
*/
|
||||
public function testHtmlIso8859()
|
||||
{
|
||||
$this->Mail->isHTML(false);
|
||||
$this->Mail->Subject .= ": ISO-8859-1 HTML";
|
||||
$this->Mail->CharSet = 'iso-8859-1';
|
||||
|
||||
//This file is in ISO-8859-1 charset
|
||||
//Needs to be external because this file is in UTF-8
|
||||
$content = file_get_contents('../examples/contents.html');
|
||||
//Make sure it really is in ISO-8859-1!
|
||||
$this->Mail->Body =
|
||||
mb_convert_encoding(
|
||||
$content,
|
||||
"ISO-8859-1",
|
||||
mb_detect_encoding($content, "UTF-8, ISO-8859-1, ISO-8859-15", true)
|
||||
);
|
||||
$this->buildBody();
|
||||
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message containing multilingual UTF-8 text.
|
||||
*/
|
||||
|
|
@ -812,6 +836,7 @@ EOT;
|
|||
$this->Mail->Body = <<<EOT
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>HTML email test</title>
|
||||
</head>
|
||||
<body>
|
||||
|
|
@ -828,6 +853,41 @@ EOT;
|
|||
$this->assertNotContains("\r\n\r\nMIME-Version:", $msg, 'Incorrect MIME headers');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message containing multilingual UTF-8 text with an embedded image.
|
||||
*/
|
||||
public function testUtf8WithEmbeddedImage()
|
||||
{
|
||||
$this->Mail->isHTML(true);
|
||||
$this->Mail->Subject .= ": UTF-8 with embedded image";
|
||||
$this->Mail->CharSet = 'UTF-8';
|
||||
|
||||
$this->Mail->Body = <<<EOT
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>HTML email test</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Chinese text: 郵件內容為空</p>
|
||||
<p>Russian text: Пустое тело сообщения</p>
|
||||
<p>Armenian text: Հաղորդագրությունը դատարկ է</p>
|
||||
<p>Czech text: Prázdné tělo zprávy</p>
|
||||
Embedded Image: <img alt="phpmailer" src="cid:my-attach">
|
||||
</body>
|
||||
</html>
|
||||
EOT;
|
||||
$this->Mail->addEmbeddedImage(
|
||||
'../examples/images/phpmailer.png',
|
||||
'my-attach',
|
||||
'phpmailer.png',
|
||||
'base64',
|
||||
'image/png'
|
||||
);
|
||||
$this->buildBody();
|
||||
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message containing multilingual UTF-8 text.
|
||||
*/
|
||||
|
|
@ -854,7 +914,7 @@ EOT;
|
|||
*/
|
||||
public function testMsgHTML()
|
||||
{
|
||||
$message = file_get_contents('../examples/contents.html');
|
||||
$message = file_get_contents('../examples/contentsutf8.html');
|
||||
$this->Mail->CharSet = 'utf-8';
|
||||
$this->Mail->Body = '';
|
||||
$this->Mail->AltBody = '';
|
||||
|
|
@ -904,7 +964,7 @@ EOT;
|
|||
public function testEmbeddedImage()
|
||||
{
|
||||
$this->Mail->Body = 'Embedded Image: <img alt="phpmailer" src="cid:my-attach">' .
|
||||
'Here is an image!</a>';
|
||||
'Here is an image!';
|
||||
$this->Mail->Subject .= ': Embedded Image';
|
||||
$this->Mail->isHTML(true);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue