PathHeaderTest.php 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. require_once 'Swift/Tests/SwiftUnitTestCase.php';
  3. require_once 'Swift/Mime/Headers/PathHeader.php';
  4. require_once 'Swift/Mime/Grammar.php';
  5. class Swift_Mime_Headers_PathHeaderTest extends Swift_Tests_SwiftUnitTestCase
  6. {
  7. public function testTypeIsPathHeader()
  8. {
  9. $header = $this->_getHeader('Return-Path');
  10. $this->assertEqual(Swift_Mime_Header::TYPE_PATH, $header->getFieldType());
  11. }
  12. public function testSingleAddressCanBeSetAndFetched()
  13. {
  14. $header = $this->_getHeader('Return-Path');
  15. $header->setAddress('chris@swiftmailer.org');
  16. $this->assertEqual('chris@swiftmailer.org', $header->getAddress());
  17. }
  18. public function testAddressMustComplyWithRfc2822()
  19. {
  20. try {
  21. $header = $this->_getHeader('Return-Path');
  22. $header->setAddress('chr is@swiftmailer.org');
  23. $this->fail('Address must be valid according to RFC 2822 addr-spec grammar.');
  24. } catch (Exception $e) {
  25. $this->pass();
  26. }
  27. }
  28. public function testValueIsAngleAddrWithValidAddress()
  29. {
  30. /* -- RFC 2822, 3.6.7.
  31. return = "Return-Path:" path CRLF
  32. path = ([CFWS] "<" ([CFWS] / addr-spec) ">" [CFWS]) /
  33. obs-path
  34. */
  35. $header = $this->_getHeader('Return-Path');
  36. $header->setAddress('chris@swiftmailer.org');
  37. $this->assertEqual('<chris@swiftmailer.org>', $header->getFieldBody());
  38. }
  39. public function testValueIsEmptyAngleBracketsIfEmptyAddressSet()
  40. {
  41. $header = $this->_getHeader('Return-Path');
  42. $header->setAddress('');
  43. $this->assertEqual('<>', $header->getFieldBody());
  44. }
  45. public function testSetBodyModel()
  46. {
  47. $header = $this->_getHeader('Return-Path');
  48. $header->setFieldBodyModel('foo@bar.tld');
  49. $this->assertEqual('foo@bar.tld', $header->getAddress());
  50. }
  51. public function testGetBodyModel()
  52. {
  53. $header = $this->_getHeader('Return-Path');
  54. $header->setAddress('foo@bar.tld');
  55. $this->assertEqual('foo@bar.tld', $header->getFieldBodyModel());
  56. }
  57. public function testToString()
  58. {
  59. $header = $this->_getHeader('Return-Path');
  60. $header->setAddress('chris@swiftmailer.org');
  61. $this->assertEqual('Return-Path: <chris@swiftmailer.org>' . "\r\n",
  62. $header->toString()
  63. );
  64. }
  65. // -- Private methods
  66. private function _getHeader($name)
  67. {
  68. return new Swift_Mime_Headers_PathHeader($name, new Swift_Mime_Grammar());
  69. }
  70. }