Skip to content

Commit

Permalink
Added test for content transfer encoding for iso-2022-jp. Thanks @suzuki
Browse files Browse the repository at this point in the history
  • Loading branch information
predominant committed Oct 19, 2011
1 parent cef441c commit e389858
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,19 @@ public function testMessage() {
$message = $this->CakeEmail->message();
$this->assertTrue(in_array('Content-Type: text/plain; charset=UTF-8', $message));
$this->assertTrue(in_array('Content-Type: text/html; charset=UTF-8', $message));

// UTF-8 is 8bit
$this->assertTrue($this->checkContentTransferEncoding($message, '8bit'));


$this->CakeEmail->charset = 'ISO-2022-JP';
$this->CakeEmail->send();
$message = $this->CakeEmail->message();
$this->assertTrue(in_array('Content-Type: text/plain; charset=ISO-2022-JP', $message));
$this->assertTrue(in_array('Content-Type: text/html; charset=ISO-2022-JP', $message));

// ISO-2022-JP is 7bit
$this->assertTrue($this->checkContentTransferEncoding($message, '7bit'));
}

/**
Expand Down Expand Up @@ -1201,4 +1214,30 @@ public function testBodyEncoding() {
$this->assertContains('Content-Type: text/plain; charset=iso-2022-jp', $result['headers']);
$this->assertContains('ってテーブルを作ってやってたらう', $result['message']);
}

private function checkContentTransferEncoding($message, $charset) {
$boundary = '--alt-' . $this->CakeEmail->getBoundary();
$result['text'] = false;
$result['html'] = false;
for ($i = 0; $i < count($message); ++$i) {
if ($message[$i] == $boundary) {
$flag = false;
$type = '';
while (!preg_match('/^$/', $message[$i])) {
if (preg_match('/^Content-Type: text\/plain/', $message[$i])) {
$type = 'text';
}
if (preg_match('/^Content-Type: text\/html/', $message[$i])) {
$type = 'html';
}
if ($message[$i] === 'Content-Transfer-Encoding: ' . $charset) {
$flag = true;
}
++$i;
}
$result[$type] = $flag;
}
}
return $result['text'] && $result['html'];
}
}

0 comments on commit e389858

Please sign in to comment.