Skip to content

Instantly share code, notes, and snippets.

@k1LoW
Created May 21, 2012 05:38
Show Gist options
  • Select an option

  • Save k1LoW/2760672 to your computer and use it in GitHub Desktop.

Select an option

Save k1LoW/2760672 to your computer and use it in GitHub Desktop.
CakeEmailTest.php.diff
diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
index 6d429af..82acb72 100644
--- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
+++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
@@ -1451,6 +1451,54 @@ class CakeEmailTest extends CakeTestCase {
$this->assertContains(mb_convert_encoding('ってテーブルを作ってやってたらう','ISO-2022-JP'), $result['message']);
}
+/**
+ * Tests that the body is encoded using the configured charset
+ *
+ * @return void
+ */
+ public function testBodyEncodingIso2022Jp() {
+ $this->skipIf(!function_exists('mb_convert_encoding'));
+ $email = new CakeEmail(array(
+ 'charset' => 'iso-2022-jp',
+ 'headerCharset' => 'iso-2022-jp',
+ 'transport' => 'Debug'
+ ));
+ $email->subject('あれ?もしかしての前と');
+ $headers = $email->getHeaders(array('subject'));
+ $expected = "?ISO-2022-JP?B?GyRCJCIkbCEpJGIkNyQrJDckRiROQTAkSBsoQg==?=";
+ $this->assertContains($expected, $headers['Subject']);
+
+ $email->to('someone@example.com')->from('someone@example.com');
+ $result = $email->send('①㈱');
+ $this->assertTextContains("Content-Type: text/plain; charset=iso-2022-jp", $result['headers']);
+ $this->assertTextNotContains("Content-Type: text/plain; charset=iso-2022-jp-ms", $result['headers']); // not charset=iso-2022-jp-ms
+ $this->assertTextNotContains(mb_convert_encoding('①㈱','ISO-2022-JP-MS'), $result['message']);
+ }
+
+/**
+ * Tests that the body is encoded using the configured charset
+ *
+ * @return void
+ */
+ public function testBodyEncodingIso2022JpMs() {
+ $this->skipIf(!function_exists('mb_convert_encoding'));
+ $email = new CakeEmail(array(
+ 'charset' => 'iso-2022-jp-ms',
+ 'headerCharset' => 'iso-2022-jp-ms',
+ 'transport' => 'Debug'
+ ));
+ $email->subject('あれ?もしかしての前と');
+ $headers = $email->getHeaders(array('subject'));
+ $expected = "?ISO-2022-JP?B?GyRCJCIkbCEpJGIkNyQrJDckRiROQTAkSBsoQg==?=";
+ $this->assertContains($expected, $headers['Subject']);
+
+ $email->to('someone@example.com')->from('someone@example.com');
+ $result = $email->send('①㈱');
+ $this->assertTextContains("Content-Type: text/plain; charset=iso-2022-jp", $result['headers']);
+ $this->assertTextNotContains("Content-Type: text/plain; charset=iso-2022-jp-ms", $result['headers']); // not charset=iso-2022-jp-ms
+ $this->assertContains(mb_convert_encoding('①㈱','ISO-2022-JP-MS'), $result['message']);
+ }
+
protected function _checkContentTransferEncoding($message, $charset) {
$boundary = '--alt-' . $this->CakeEmail->getBoundary();
$result['text'] = false;
@k1LoW
Copy link
Copy Markdown
Author

k1LoW commented May 21, 2012

testBodyEncodingIso2022JpMs() line 53 Failed...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment