PathHeaderTest.php 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. {
  22. $header = $this->_getHeader('Return-Path');
  23. $header->setAddress('chr is@swiftmailer.org');
  24. $this->fail('Address must be valid according to RFC 2822 addr-spec grammar.');
  25. }
  26. catch (Exception $e)
  27. {
  28. $this->pass();
  29. }
  30. }
  31. public function testValueIsAngleAddrWithValidAddress()
  32. {
  33. /* -- RFC 2822, 3.6.7.
  34. return = "Return-Path:" path CRLF
  35. path = ([CFWS] "<" ([CFWS] / addr-spec) ">" [CFWS]) /
  36. obs-path
  37. */
  38. $header = $this->_getHeader('Return-Path');
  39. $header->setAddress('chris@swiftmailer.org');
  40. $this->assertEqual('<chris@swiftmailer.org>', $header->getFieldBody());
  41. }
  42. public function testValueIsEmptyAngleBracketsIfEmptyAddressSet()
  43. {
  44. $header = $this->_getHeader('Return-Path');
  45. $header->setAddress('');
  46. $this->assertEqual('<>', $header->getFieldBody());
  47. }
  48. public function testSetBodyModel()
  49. {
  50. $header = $this->_getHeader('Return-Path');
  51. $header->setFieldBodyModel('foo@bar.tld');
  52. $this->assertEqual('foo@bar.tld', $header->getAddress());
  53. }
  54. public function testGetBodyModel()
  55. {
  56. $header = $this->_getHeader('Return-Path');
  57. $header->setAddress('foo@bar.tld');
  58. $this->assertEqual('foo@bar.tld', $header->getFieldBodyModel());
  59. }
  60. public function testToString()
  61. {
  62. $header = $this->_getHeader('Return-Path');
  63. $header->setAddress('chris@swiftmailer.org');
  64. $this->assertEqual('Return-Path: <chris@swiftmailer.org>' . "\r\n",
  65. $header->toString()
  66. );
  67. }
  68. // -- Private methods
  69. private function _getHeader($name)
  70. {
  71. return new Swift_Mime_Headers_PathHeader($name, new Swift_Mime_Grammar());
  72. }
  73. }