Skip to content

Commit

Permalink
Improved unit test for MIME encoding/decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Sep 29, 2014
1 parent b3d8c09 commit 035beb3
Showing 1 changed file with 64 additions and 10 deletions.
74 changes: 64 additions & 10 deletions framework/Mime/test/Horde/Mime/MimeTest.php
Expand Up @@ -20,25 +20,79 @@
*/
class Horde_Mime_MimeTest extends PHPUnit_Framework_TestCase
{
public function testDecode()
/**
* @dataProvider decodeProvider
*/
public function testDecode($data, $expected)
{
$this->assertEquals(
' François Xavier. XXXXXX <foo@example.com>',
Horde_Mime::decode('=?utf-8?Q?_Fran=C3=A7ois_Xavier=2E_XXXXXX_?= <foo@example.com>')
$expected,
Horde_Mime::decode($data)
);
}

/* Not MIME encoded. */
$this->assertEquals(
'=? required=?',
Horde_Mime::decode('=? required=?')
public function decodeProvider()
{
return array(
array(
'=?utf-8?Q?_Fran=C3=A7ois_Xavier=2E_XXXXXX_?= <foo@example.com>',
' François Xavier. XXXXXX <foo@example.com>'
),

/* Adapted from Dovecot's
* src/lib-mail/test-message-header-decode.c. */
array(
" \t=?utf-8?q?=c3=a4?= =?utf-8?q?=c3=a4?= b \t\r\n ",
" \tää b \t\r\n "
),
array(
"a =?utf-8?q?=c3=a4?= b",
"a ä b"
),
array(
"a =?utf-8?q?=c3=a4?=\t\t\r\n =?utf-8?q?=c3=a4?= b",
"a ää b"
),
array(
"a =?utf-8?q?=c3=a4?= x =?utf-8?q?=c3=a4?= b",
"a ä x ä b"
),
array(
"a =?utf-8?b?w6TDpCDDpA==?= b",
"a ää ä b"
), array(
"=?utf-8?b?w6Qgw6Q=?=",
"ä ä"
),

/* Not MIME encoded. */
array(
'=? required=?',
'=? required=?'
)
);
}

public function testNullCharacterInEncodeOutput()
/**
* @dataProvider encodeProvider
*/
public function testEncode($data, $charset, $expected)
{
$this->assertEquals(
'=?utf-16le?b?AAA=?=',
Horde_Mime::encode("\x00", 'UTF-16LE')
$expected,
Horde_Mime::encode($data, $charset)
);
}

public function encodeProvider()
{
return array(
/* Null character in encode output. */
array(
"\x00",
'UTF-16LE',
'=?utf-16le?b?AAA=?='
)
);
}

Expand Down

0 comments on commit 035beb3

Please sign in to comment.