From 9af3089b9e9c6e89adccaf584cdcbf6e2e65bd7f Mon Sep 17 00:00:00 2001 From: Denis Sokolov Date: Wed, 9 Apr 2014 02:20:12 +0200 Subject: [PATCH 1/2] Mail TransferEncoding test refactor --- test/Header/ContentTransferEncodingTest.php | 70 ++++++++++++++------- 1 file changed, 46 insertions(+), 24 deletions(-) diff --git a/test/Header/ContentTransferEncodingTest.php b/test/Header/ContentTransferEncodingTest.php index 738b9287..cec64a94 100644 --- a/test/Header/ContentTransferEncodingTest.php +++ b/test/Header/ContentTransferEncodingTest.php @@ -16,18 +16,41 @@ */ class ContentTransferEncodingTest extends \PHPUnit_Framework_TestCase { + public function dataValidEncodings() + { + return array( + array('7bit'), + array('8bit'), + array('quoted-printable'), + ); + } + + public function dataInvalidEncodings() + { + return array( + array('9bit'), + array('binary'), + array('x-something'), + ); + } - public function testContentTransferEncodingFromStringCreatesValidContentTransferEncodingHeader() + /** + * @dataProvider dataValidEncodings + */ + public function testContentTransferEncodingFromStringCreatesValidContentTransferEncodingHeader($encoding) { - $contentTransferEncodingHeader = ContentTransferEncoding::fromString('Content-Transfer-Encoding: 7bit'); + $contentTransferEncodingHeader = ContentTransferEncoding::fromString('Content-Transfer-Encoding: '.$encoding); $this->assertInstanceOf('Zend\Mail\Header\HeaderInterface', $contentTransferEncodingHeader); $this->assertInstanceOf('Zend\Mail\Header\ContentTransferEncoding', $contentTransferEncodingHeader); } - public function testContentTransferEncodingFromStringCreateExcaption() + /** + * @dataProvider dataInvalidEncodings + */ + public function testContentTransferEncodingFromStringCreateExcaption($encoding) { $this->setExpectedException('Zend\Mail\Header\Exception\InvalidArgumentException'); - $contentTransferEncodingHeader = ContentTransferEncoding::fromString('Content-Transfer-Encoding: 9bit'); + $contentTransferEncodingHeader = ContentTransferEncoding::fromString('Content-Transfer-Encoding: '.$encoding); } public function testContentTransferEncodingGetFieldNameReturnsHeaderName() @@ -36,34 +59,33 @@ public function testContentTransferEncodingGetFieldNameReturnsHeaderName() $this->assertEquals('Content-Transfer-Encoding', $contentTransferEncodingHeader->getFieldName()); } - public function testContentTransferEncodingGetFieldValueReturnsProperValue() + /** + * @dataProvider dataValidEncodings + */ + public function testContentTransferEncodingGetFieldValueReturnsProperValue($encoding) { $contentTransferEncodingHeader = new ContentTransferEncoding(); - $contentTransferEncodingHeader->setTransferEncoding('7bit'); - $this->assertEquals('7bit', $contentTransferEncodingHeader->getFieldValue()); + $contentTransferEncodingHeader->setTransferEncoding($encoding); + $this->assertEquals($encoding, $contentTransferEncodingHeader->getFieldValue()); } - public function testContentTransferEncodingHandlesCaseInsensitivity() + /** + * @dataProvider dataValidEncodings + */ + public function testContentTransferEncodingHandlesCaseInsensitivity($encoding) { - $encoding = new ContentTransferEncoding(); - $encoding->setTransferEncoding('quOtED-printAble'); - $this->assertEquals('quoted-printable', strtolower($encoding->getFieldValue())); + $header = new ContentTransferEncoding(); + $header->setTransferEncoding(strtoupper(substr($encoding, 0, 4)).substr($encoding, 4)); + $this->assertEquals(strtolower($encoding), strtolower($header->getFieldValue())); } - public function testContentTransferEncodingToStringReturnsHeaderFormattedString() + /** + * @dataProvider dataValidEncodings + */ + public function testContentTransferEncodingToStringReturnsHeaderFormattedString($encoding) { $contentTransferEncodingHeader = new ContentTransferEncoding(); - $contentTransferEncodingHeader->setTransferEncoding('8bit'); - $this->assertEquals("Content-Transfer-Encoding: 8bit", $contentTransferEncodingHeader->toString()); + $contentTransferEncodingHeader->setTransferEncoding($encoding); + $this->assertEquals("Content-Transfer-Encoding: ".$encoding, $contentTransferEncodingHeader->toString()); } - - public function testProvidingParametersIntroducesHeaderFolding() - { - $header = new ContentTransferEncoding(); - $header->setTransferEncoding('quoted-printable'); - $string = $header->toString(); - - $this->assertContains("Content-Transfer-Encoding: quoted-printable", $string); - } - } From 97be6df053b33b0cd0c49dcc9b3b6d5a120e1f2b Mon Sep 17 00:00:00 2001 From: Denis Sokolov Date: Wed, 9 Apr 2014 02:21:04 +0200 Subject: [PATCH 2/2] Mail TransferEncoding allow binary --- src/Header/ContentTransferEncoding.php | 2 +- test/Header/ContentTransferEncodingTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Header/ContentTransferEncoding.php b/src/Header/ContentTransferEncoding.php index 3d72e706..34ff2879 100644 --- a/src/Header/ContentTransferEncoding.php +++ b/src/Header/ContentTransferEncoding.php @@ -22,9 +22,9 @@ class ContentTransferEncoding implements HeaderInterface '8bit', 'quoted-printable', 'base64', + 'binary', /* * not implemented: - * 'binary', * x-token: 'X-' */ ); diff --git a/test/Header/ContentTransferEncodingTest.php b/test/Header/ContentTransferEncodingTest.php index cec64a94..e1b0dc9a 100644 --- a/test/Header/ContentTransferEncodingTest.php +++ b/test/Header/ContentTransferEncodingTest.php @@ -21,6 +21,7 @@ public function dataValidEncodings() return array( array('7bit'), array('8bit'), + array('binary'), array('quoted-printable'), ); } @@ -29,7 +30,6 @@ public function dataInvalidEncodings() { return array( array('9bit'), - array('binary'), array('x-something'), ); }