| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 | 
							- <?php
 - 
 - require_once 'Swift/Tests/SwiftUnitTestCase.php';
 - require_once 'Swift/Mime/Headers/MailboxHeader.php';
 - require_once 'Swift/Mime/HeaderEncoder.php';
 - require_once 'Swift/Mime/Grammar.php';
 - 
 - class Swift_Mime_Headers_MailboxHeaderTest
 -   extends Swift_Tests_SwiftUnitTestCase
 - {
 -   
 -   /* -- RFC 2822, 3.6.2 for all tests.
 -    */
 -   
 -   private $_charset = 'utf-8';
 -   
 -   public function testTypeIsMailboxHeader()
 -   {
 -     $header = $this->_getHeader('To', $this->_getEncoder('Q', true));
 -     $this->assertEqual(Swift_Mime_Header::TYPE_MAILBOX, $header->getFieldType());
 -   }
 -   
 -   public function testMailboxIsSetForAddress()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setAddresses('chris@swiftmailer.org');
 -     $this->assertEqual(array('chris@swiftmailer.org'),
 -       $header->getNameAddressStrings()
 -       );
 -   }
 -   
 -   public function testMailboxIsRenderedForNameAddress()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setNameAddresses(array('chris@swiftmailer.org' => 'Chris Corbyn'));
 -     $this->assertEqual(
 -       array('Chris Corbyn <chris@swiftmailer.org>'), $header->getNameAddressStrings()
 -       );
 -   }
 -   
 -   public function testAddressCanBeReturnedForAddress()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setAddresses('chris@swiftmailer.org');
 -     $this->assertEqual(array('chris@swiftmailer.org'), $header->getAddresses());
 -   }
 -   
 -   public function testAddressCanBeReturnedForNameAddress()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setNameAddresses(array('chris@swiftmailer.org' => 'Chris Corbyn'));
 -     $this->assertEqual(array('chris@swiftmailer.org'), $header->getAddresses());
 -   }
 -   
 -   public function testQuotesInNameAreQuoted()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setNameAddresses(array(
 -       'chris@swiftmailer.org' => 'Chris Corbyn, "DHE"'
 -       ));
 -     $this->assertEqual(
 -       array('"Chris Corbyn, \"DHE\"" <chris@swiftmailer.org>'),
 -       $header->getNameAddressStrings()
 -       );
 -   }
 -   
 -   public function testEscapeCharsInNameAreQuoted()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setNameAddresses(array(
 -       'chris@swiftmailer.org' => 'Chris Corbyn, \\escaped\\'
 -       ));
 -     $this->assertEqual(
 -       array('"Chris Corbyn, \\\\escaped\\\\" <chris@swiftmailer.org>'),
 -       $header->getNameAddressStrings()
 -       );
 -   }
 -   
 -   public function testGetMailboxesReturnsNameValuePairs()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setNameAddresses(array(
 -       'chris@swiftmailer.org' => 'Chris Corbyn, DHE'
 -       ));
 -     $this->assertEqual(
 -       array('chris@swiftmailer.org' => 'Chris Corbyn, DHE'), $header->getNameAddresses()
 -       );
 -   }
 -   
 -   public function testMultipleAddressesCanBeSetAndFetched()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setAddresses(array(
 -       'chris@swiftmailer.org', 'mark@swiftmailer.org'
 -       ));
 -     $this->assertEqual(
 -       array('chris@swiftmailer.org', 'mark@swiftmailer.org'),
 -       $header->getAddresses()
 -       );
 -   }
 -   
 -   public function testMultipleAddressesAsMailboxes()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setAddresses(array(
 -       'chris@swiftmailer.org', 'mark@swiftmailer.org'
 -       ));
 -     $this->assertEqual(
 -       array('chris@swiftmailer.org'=>null, 'mark@swiftmailer.org'=>null),
 -       $header->getNameAddresses()
 -       );
 -   }
 -   
 -   public function testMultipleAddressesAsMailboxStrings()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setAddresses(array(
 -       'chris@swiftmailer.org', 'mark@swiftmailer.org'
 -       ));
 -     $this->assertEqual(
 -       array('chris@swiftmailer.org', 'mark@swiftmailer.org'),
 -       $header->getNameAddressStrings()
 -       );
 -   }
 -   
 -   public function testMultipleNamedMailboxesReturnsMultipleAddresses()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setNameAddresses(array(
 -       'chris@swiftmailer.org' => 'Chris Corbyn',
 -       'mark@swiftmailer.org' => 'Mark Corbyn'
 -       ));
 -     $this->assertEqual(
 -       array('chris@swiftmailer.org', 'mark@swiftmailer.org'),
 -       $header->getAddresses()
 -       );
 -   }
 -   
 -   public function testMultipleNamedMailboxesReturnsMultipleMailboxes()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setNameAddresses(array(
 -       'chris@swiftmailer.org' => 'Chris Corbyn',
 -       'mark@swiftmailer.org' => 'Mark Corbyn'
 -       ));
 -     $this->assertEqual(array(
 -         'chris@swiftmailer.org' => 'Chris Corbyn',
 -         'mark@swiftmailer.org' => 'Mark Corbyn'
 -         ),
 -       $header->getNameAddresses()
 -       );
 -   }
 -   
 -   public function testMultipleMailboxesProducesMultipleMailboxStrings()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setNameAddresses(array(
 -       'chris@swiftmailer.org' => 'Chris Corbyn',
 -       'mark@swiftmailer.org' => 'Mark Corbyn'
 -       ));
 -     $this->assertEqual(array(
 -         'Chris Corbyn <chris@swiftmailer.org>',
 -         'Mark Corbyn <mark@swiftmailer.org>'
 -         ),
 -       $header->getNameAddressStrings()
 -       );
 -   }
 -   
 -   public function testSetAddressesOverwritesAnyMailboxes()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setNameAddresses(array(
 -       'chris@swiftmailer.org' => 'Chris Corbyn',
 -       'mark@swiftmailer.org' => 'Mark Corbyn'
 -       ));
 -     $this->assertEqual(
 -       array('chris@swiftmailer.org' => 'Chris Corbyn',
 -       'mark@swiftmailer.org' => 'Mark Corbyn'),
 -       $header->getNameAddresses()
 -       );
 -     $this->assertEqual(
 -       array('chris@swiftmailer.org', 'mark@swiftmailer.org'),
 -       $header->getAddresses()
 -       );
 -     
 -     $header->setAddresses(array('chris@swiftmailer.org', 'mark@swiftmailer.org'));
 -     
 -     $this->assertEqual(
 -       array('chris@swiftmailer.org' => null, 'mark@swiftmailer.org' => null),
 -       $header->getNameAddresses()
 -       );
 -     $this->assertEqual(
 -       array('chris@swiftmailer.org', 'mark@swiftmailer.org'),
 -       $header->getAddresses()
 -       );
 -   }
 -   
 -   public function testNameIsEncodedIfNonAscii()
 -   {
 -     $name = 'C' . pack('C', 0x8F) . 'rbyn';
 -     
 -     $encoder = $this->_getEncoder('Q');
 -     $this->_checking(Expectations::create()
 -       -> one($encoder)->encodeString($name, any(), any()) -> returns('C=8Frbyn')
 -       -> ignoring($encoder)
 -       );
 -     
 -     $header = $this->_getHeader('From', $encoder);
 -     $header->setNameAddresses(array('chris@swiftmailer.org'=>'Chris ' . $name));
 -     
 -     $addresses = $header->getNameAddressStrings();
 -     $this->assertEqual(
 -       'Chris =?' . $this->_charset . '?Q?C=8Frbyn?= <chris@swiftmailer.org>',
 -       array_shift($addresses)
 -       );
 -   }
 -   
 -   public function testEncodingLineLengthCalculations()
 -   {
 -     /* -- RFC 2047, 2.
 -     An 'encoded-word' may not be more than 75 characters long, including
 -     'charset', 'encoding', 'encoded-text', and delimiters.
 -     */
 -     
 -     $name = 'C' . pack('C', 0x8F) . 'rbyn';
 -     
 -     $encoder = $this->_getEncoder('Q');
 -     $this->_checking(Expectations::create()
 -       -> one($encoder)->encodeString($name, 6, 63) -> returns('C=8Frbyn')
 -       -> ignoring($encoder)
 -       );
 -     
 -     $header = $this->_getHeader('From', $encoder);
 -     $header->setNameAddresses(array('chris@swiftmailer.org'=>'Chris ' . $name));
 -     
 -     $header->getNameAddressStrings();
 -   }
 -   
 -   public function testGetValueReturnsMailboxStringValue()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setNameAddresses(array(
 -       'chris@swiftmailer.org' => 'Chris Corbyn'
 -       ));
 -     $this->assertEqual(
 -       'Chris Corbyn <chris@swiftmailer.org>', $header->getFieldBody()
 -       );
 -   }
 -   
 -   public function testGetValueReturnsMailboxStringValueForMultipleMailboxes()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setNameAddresses(array(
 -       'chris@swiftmailer.org' => 'Chris Corbyn',
 -       'mark@swiftmailer.org' => 'Mark Corbyn'
 -       ));
 -     $this->assertEqual(
 -       'Chris Corbyn <chris@swiftmailer.org>, Mark Corbyn <mark@swiftmailer.org>',
 -       $header->getFieldBody()
 -       );
 -   }
 -   
 -   public function testRemoveAddressesWithSingleValue()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setNameAddresses(array(
 -       'chris@swiftmailer.org' => 'Chris Corbyn',
 -       'mark@swiftmailer.org' => 'Mark Corbyn'
 -       ));
 -     $header->removeAddresses('chris@swiftmailer.org');
 -     $this->assertEqual(array('mark@swiftmailer.org'),
 -       $header->getAddresses()
 -       );
 -   }
 -   
 -   public function testRemoveAddressesWithList()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setNameAddresses(array(
 -       'chris@swiftmailer.org' => 'Chris Corbyn',
 -       'mark@swiftmailer.org' => 'Mark Corbyn'
 -       ));
 -     $header->removeAddresses(
 -       array('chris@swiftmailer.org', 'mark@swiftmailer.org')
 -       );
 -     $this->assertEqual(array(), $header->getAddresses());
 -   }
 -   
 -   public function testSetBodyModel()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setFieldBodyModel('chris@swiftmailer.org');
 -     $this->assertEqual(array('chris@swiftmailer.org'=>null), $header->getNameAddresses());
 -   }
 -   
 -   public function testGetBodyModel()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setAddresses(array('chris@swiftmailer.org'));
 -     $this->assertEqual(array('chris@swiftmailer.org'=>null), $header->getFieldBodyModel());
 -   }
 -   
 -   public function testToString()
 -   {
 -     $header = $this->_getHeader('From', $this->_getEncoder('Q', true));
 -     $header->setNameAddresses(array(
 -       'chris@swiftmailer.org' => 'Chris Corbyn',
 -       'mark@swiftmailer.org' => 'Mark Corbyn'
 -       ));
 -     $this->assertEqual(
 -       'From: Chris Corbyn <chris@swiftmailer.org>, ' .
 -       'Mark Corbyn <mark@swiftmailer.org>' . "\r\n",
 -       $header->toString()
 -       );
 -   }
 -   
 -   // -- Private methods
 -   
 -   private function _getHeader($name, $encoder)
 -   {
 -     $header = new Swift_Mime_Headers_MailboxHeader($name, $encoder, new Swift_Mime_Grammar());
 -     $header->setCharset($this->_charset);
 -     return $header;
 -   }
 -   
 -   private function _getEncoder($type, $stub = false)
 -   {
 -     $encoder = $this->_mock('Swift_Mime_HeaderEncoder');
 -     $this->_checking(Expectations::create()
 -       -> ignoring($encoder)->getName() -> returns($type)
 -       );
 -     if ($stub)
 -     {
 -       $this->_checking(Expectations::create()
 -         -> ignoring($encoder)
 -         );
 -     }
 -     return $encoder;
 -   }
 -   
 - }
 
 
  |