From 537c60da5b30d9d7127b0c305fddbd8ce0577bc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Wrzeszcz?= Date: Mon, 2 Jan 2012 23:11:39 +0100 Subject: [PATCH 1/4] Updated test cases for addMany() fix. --- src/AddressList.php | 2 +- test/AddressListTest.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/AddressList.php b/src/AddressList.php index 8cef7f07..70383957 100644 --- a/src/AddressList.php +++ b/src/AddressList.php @@ -84,7 +84,7 @@ public function addMany(array $addresses) if (is_int($key) || is_numeric($key)) { $this->add($value); } elseif (is_string($key)) { - $this->add($key, value); + $this->add($key, $value); } else { throw new Exception\RuntimeException(sprintf( 'Invalid key type in provided addresses array ("%s")', diff --git a/test/AddressListTest.php b/test/AddressListTest.php index 640330a1..643c0644 100644 --- a/test/AddressListTest.php +++ b/test/AddressListTest.php @@ -98,7 +98,7 @@ public function testCanAddManyAddressesAtOnce() { $addresses = array( 'zf-devteam@zend.com', - 'ZF Contributors List' => 'zf-contributors@lists.zend.com', + 'zf-contributors@lists.zend.com' => 'ZF Contributors List', new Address('fw-announce@lists.zend.com', 'ZF Announce List'), ); $this->list->addMany($addresses); @@ -112,7 +112,6 @@ public function testDoesNotStoreDuplicatesAndFirstWins() { $addresses = array( 'zf-devteam@zend.com', - 'ZF DevTeam' => 'zf-devteam@zend.com', new Address('zf-devteam@zend.com', 'ZF DevTeam'), ); $this->list->addMany($addresses); From e5947b6fb43fe517a7a05d27b8a74e7eb0ddb3de Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 3 Jan 2012 14:21:41 -0600 Subject: [PATCH 2/4] Fixed tests to use proper key/value pairs for address lists --- test/MessageTest.php | 8 ++++---- test/Transport/SendmailTest.php | 2 +- test/Transport/SmtpTest.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/MessageTest.php b/test/MessageTest.php index 2003f94f..49b12817 100644 --- a/test/MessageTest.php +++ b/test/MessageTest.php @@ -230,7 +230,7 @@ public function testCanAddManyFromAddressesUsingArray() { $addresses = array( 'zf-devteam@zend.com', - 'ZF Contributors List' => 'zf-contributors@lists.zend.com', + 'zf-contributors@lists.zend.com' => 'ZF Contributors List', new Address('fw-announce@lists.zend.com', 'ZF Announce List'), ); $this->message->addFrom($addresses); @@ -294,7 +294,7 @@ public function testCanAddManyCcAddressesUsingArray() { $addresses = array( 'zf-devteam@zend.com', - 'ZF Contributors List' => 'zf-contributors@lists.zend.com', + 'zf-contributors@lists.zend.com' => 'ZF Contributors List', new Address('fw-announce@lists.zend.com', 'ZF Announce List'), ); $this->message->addCc($addresses); @@ -358,7 +358,7 @@ public function testCanAddManyBccAddressesUsingArray() { $addresses = array( 'zf-devteam@zend.com', - 'ZF Contributors List' => 'zf-contributors@lists.zend.com', + 'zf-contributors@lists.zend.com' => 'ZF Contributors List', new Address('fw-announce@lists.zend.com', 'ZF Announce List'), ); $this->message->addBcc($addresses); @@ -422,7 +422,7 @@ public function testCanAddManyReplyToAddressesUsingArray() { $addresses = array( 'zf-devteam@zend.com', - 'ZF Contributors List' => 'zf-contributors@lists.zend.com', + 'zf-contributors@lists.zend.com' => 'ZF Contributors List', new Address('fw-announce@lists.zend.com', 'ZF Announce List'), ); $this->message->addReplyTo($addresses); diff --git a/test/Transport/SendmailTest.php b/test/Transport/SendmailTest.php index fadd8e63..26e69775 100644 --- a/test/Transport/SendmailTest.php +++ b/test/Transport/SendmailTest.php @@ -74,7 +74,7 @@ public function getMessage() ->addBcc('zf-crteam@lists.zend.com', 'CR-Team, ZF Project') ->addFrom(array( 'zf-devteam@zend.com', - 'Matthew' => 'matthew@zend.com', + 'matthew@zend.com' => 'Matthew', )) ->setSender('ralph.schindler@zend.com', 'Ralph Schindler') ->setSubject('Testing Zend\Mail\Transport\Sendmail') diff --git a/test/Transport/SmtpTest.php b/test/Transport/SmtpTest.php index 9226e03f..3b51aa18 100644 --- a/test/Transport/SmtpTest.php +++ b/test/Transport/SmtpTest.php @@ -56,7 +56,7 @@ public function getMessage() ->addBcc('zf-crteam@lists.zend.com', 'CR-Team, ZF Project') ->addFrom(array( 'zf-devteam@zend.com', - 'Matthew' => 'matthew@zend.com', + 'matthew@zend.com' => 'Matthew', )) ->setSender('ralph.schindler@zend.com', 'Ralph Schindler') ->setSubject('Testing Zend\Mail\Transport\Sendmail') From 6340ccc6c80546d1f70c4945e1609de8c87da055 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 3 Jan 2012 14:34:00 -0600 Subject: [PATCH 3/4] Added word-separated plugin variants, and test - Added word-separated variants of plugin names - Created test case to ensure expected default plugins are present --- src/Headers.php | 30 +++++++++++++++++++----------- test/HeadersTest.php | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/Headers.php b/src/Headers.php index 6de694c0..2ad0be79 100644 --- a/src/Headers.php +++ b/src/Headers.php @@ -134,17 +134,25 @@ public function getPluginClassLoader() { if ($this->pluginClassLoader === null) { $this->pluginClassLoader = new PluginClassLoader(array( - 'bcc' => 'Zend\\Mail\\Header\\Bcc', - 'cc' => 'Zend\\Mail\\Header\\Cc', - 'contenttype' => 'Zend\\Mail\\Header\\ContentType', - 'from' => 'Zend\\Mail\\Header\\From', - 'mimeversion' => 'Zend\\Mail\\Header\\MimeVersion', - 'origdate' => 'Zend\\Mail\\Header\\OrigDate', - 'received' => 'Zend\\Mail\\Header\\Received', - 'replyto' => 'Zend\\Mail\\Header\\ReplyTo', - 'sender' => 'Zend\\Mail\\Header\\Sender', - 'subject' => 'Zend\\Mail\\Header\\Subject', - 'to' => 'Zend\\Mail\\Header\\To', + 'bcc' => 'Zend\Mail\Header\Bcc', + 'cc' => 'Zend\Mail\Header\Cc', + 'contenttype' => 'Zend\Mail\Header\ContentType', + 'content_type' => 'Zend\Mail\Header\ContentType', + 'content-type' => 'Zend\Mail\Header\ContentType', + 'from' => 'Zend\Mail\Header\From', + 'mimeversion' => 'Zend\Mail\Header\MimeVersion', + 'mime_version' => 'Zend\Mail\Header\MimeVersion', + 'mime-version' => 'Zend\Mail\Header\MimeVersion', + 'origdate' => 'Zend\Mail\Header\OrigDate', + 'orig_date' => 'Zend\Mail\Header\OrigDate', + 'orig-date' => 'Zend\Mail\Header\OrigDate', + 'received' => 'Zend\Mail\Header\Received', + 'replyto' => 'Zend\Mail\Header\ReplyTo', + 'reply_to' => 'Zend\Mail\Header\ReplyTo', + 'reply-to' => 'Zend\Mail\Header\ReplyTo', + 'sender' => 'Zend\Mail\Header\Sender', + 'subject' => 'Zend\Mail\Header\Subject', + 'to' => 'Zend\Mail\Header\To', )); } return $this->pluginClassLoader; diff --git a/test/HeadersTest.php b/test/HeadersTest.php index 1fec9f21..04e275d8 100644 --- a/test/HeadersTest.php +++ b/test/HeadersTest.php @@ -282,4 +282,40 @@ public function testCastingToStringReturnsAllMultiHeaderValues() $expected = implode("\r\n", $expected) . "\r\n"; $this->assertEquals($expected, $string); } + + public static function expectedHeaders() + { + return array( + array('bcc', 'Zend\Mail\Header\Bcc'), + array('cc', 'Zend\Mail\Header\Cc'), + array('contenttype', 'Zend\Mail\Header\ContentType'), + array('content_type', 'Zend\Mail\Header\ContentType'), + array('content-type', 'Zend\Mail\Header\ContentType'), + array('from', 'Zend\Mail\Header\From'), + array('mimeversion', 'Zend\Mail\Header\MimeVersion'), + array('mime_version', 'Zend\Mail\Header\MimeVersion'), + array('mime-version', 'Zend\Mail\Header\MimeVersion'), + array('origdate', 'Zend\Mail\Header\OrigDate'), + array('orig_date', 'Zend\Mail\Header\OrigDate'), + array('orig-date', 'Zend\Mail\Header\OrigDate'), + array('received', 'Zend\Mail\Header\Received'), + array('replyto', 'Zend\Mail\Header\ReplyTo'), + array('reply_to', 'Zend\Mail\Header\ReplyTo'), + array('reply-to', 'Zend\Mail\Header\ReplyTo'), + array('sender', 'Zend\Mail\Header\Sender'), + array('subject', 'Zend\Mail\Header\Subject'), + array('to', 'Zend\Mail\Header\To'), + ); + } + + /** + * @dataProvider expectedHeaders + */ + public function testDefaultPluginLoaderIsSeededWithHeaders($plugin, $class) + { + $headers = new Headers(); + $loader = $headers->getPluginClassLoader(); + $test = $loader->load($plugin); + $this->assertEquals($class, $test); + } } From 9666e658230ee4a6665fa11569ef2b2fa30ca79e Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 3 Jan 2012 14:39:35 -0600 Subject: [PATCH 4/4] Updated tests and header classes to use Date header - s/OrigDate/Date/g - s/orig-date/date/g --- src/Header/{OrigDate.php => Date.php} | 12 ++++++------ src/Headers.php | 4 +--- test/MessageTest.php | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-) rename src/Header/{OrigDate.php => Date.php} (91%) diff --git a/src/Header/OrigDate.php b/src/Header/Date.php similarity index 91% rename from src/Header/OrigDate.php rename to src/Header/Date.php index 24106a94..805c94b6 100644 --- a/src/Header/OrigDate.php +++ b/src/Header/Date.php @@ -31,7 +31,7 @@ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class OrigDate implements Header +class Date implements Header { /** * @var string @@ -49,7 +49,7 @@ class OrigDate implements Header * Factory: create header object from string * * @param string $headerLine - * @return OrigDate + * @return Date * @throws Exception\InvalidArgumentException */ public static function fromString($headerLine) @@ -57,8 +57,8 @@ public static function fromString($headerLine) list($name, $value) = preg_split('#: #', $headerLine, 2); // check to ensure proper header type for this factory - if (strtolower($name) !== 'orig-date') { - throw new Exception\InvalidArgumentException('Invalid header line for Orig-Date string'); + if (strtolower($name) !== 'date') { + throw new Exception\InvalidArgumentException('Invalid header line for Date string'); } $header = new static(); @@ -74,7 +74,7 @@ public static function fromString($headerLine) */ public function getFieldName() { - return 'Orig-Date'; + return 'Date'; } /** @@ -116,6 +116,6 @@ public function getEncoding() */ public function toString() { - return 'Orig-Date: ' . $this->getFieldValue(); + return 'Date: ' . $this->getFieldValue(); } } diff --git a/src/Headers.php b/src/Headers.php index 2ad0be79..0ecc27dc 100644 --- a/src/Headers.php +++ b/src/Headers.php @@ -139,13 +139,11 @@ public function getPluginClassLoader() 'contenttype' => 'Zend\Mail\Header\ContentType', 'content_type' => 'Zend\Mail\Header\ContentType', 'content-type' => 'Zend\Mail\Header\ContentType', + 'date' => 'Zend\Mail\Header\Date', 'from' => 'Zend\Mail\Header\From', 'mimeversion' => 'Zend\Mail\Header\MimeVersion', 'mime_version' => 'Zend\Mail\Header\MimeVersion', 'mime-version' => 'Zend\Mail\Header\MimeVersion', - 'origdate' => 'Zend\Mail\Header\OrigDate', - 'orig_date' => 'Zend\Mail\Header\OrigDate', - 'orig-date' => 'Zend\Mail\Header\OrigDate', 'received' => 'Zend\Mail\Header\Received', 'replyto' => 'Zend\Mail\Header\ReplyTo', 'reply_to' => 'Zend\Mail\Header\ReplyTo', diff --git a/test/MessageTest.php b/test/MessageTest.php index 49b12817..f2595efb 100644 --- a/test/MessageTest.php +++ b/test/MessageTest.php @@ -57,8 +57,8 @@ public function testSetsOrigDateHeaderByDefault() { $headers = $this->message->headers(); $this->assertInstanceOf('Zend\Mail\Headers', $headers); - $this->assertTrue($headers->has('orig-date')); - $header = $headers->get('orig-date'); + $this->assertTrue($headers->has('date')); + $header = $headers->get('date'); $date = date('r'); $date = substr($date, 0, 16); $test = $header->getFieldValue();