DateHeaderTest.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. require_once 'Swift/Tests/SwiftUnitTestCase.php';
  3. require_once 'Swift/Mime/Headers/DateHeader.php';
  4. require_once 'Swift/Mime/Grammar.php';
  5. class Swift_Mime_Headers_DateHeaderTest
  6. extends Swift_Tests_SwiftUnitTestCase
  7. {
  8. /* --
  9. The following tests refer to RFC 2822, section 3.6.1 and 3.3.
  10. */
  11. public function testTypeIsDateHeader()
  12. {
  13. $header = $this->_getHeader('Date');
  14. $this->assertEqual(Swift_Mime_Header::TYPE_DATE, $header->getFieldType());
  15. }
  16. public function testGetTimestamp()
  17. {
  18. $timestamp = time();
  19. $header = $this->_getHeader('Date');
  20. $header->setTimestamp($timestamp);
  21. $this->assertIdentical($timestamp, $header->getTimestamp());
  22. }
  23. public function testTimestampCanBeSetBySetter()
  24. {
  25. $timestamp = time();
  26. $header = $this->_getHeader('Date');
  27. $header->setTimestamp($timestamp);
  28. $this->assertIdentical($timestamp, $header->getTimestamp());
  29. }
  30. public function testIntegerTimestampIsConvertedToRfc2822Date()
  31. {
  32. $timestamp = time();
  33. $header = $this->_getHeader('Date');
  34. $header->setTimestamp($timestamp);
  35. $this->assertEqual(date('r', $timestamp), $header->getFieldBody());
  36. }
  37. public function testSetBodyModel()
  38. {
  39. $timestamp = time();
  40. $header = $this->_getHeader('Date');
  41. $header->setFieldBodyModel($timestamp);
  42. $this->assertEqual(date('r', $timestamp), $header->getFieldBody());
  43. }
  44. public function testGetBodyModel()
  45. {
  46. $timestamp = time();
  47. $header = $this->_getHeader('Date');
  48. $header->setTimestamp($timestamp);
  49. $this->assertEqual($timestamp, $header->getFieldBodyModel());
  50. }
  51. public function testToString()
  52. {
  53. $timestamp = time();
  54. $header = $this->_getHeader('Date');
  55. $header->setTimestamp($timestamp);
  56. $this->assertEqual('Date: ' . date('r', $timestamp) . "\r\n",
  57. $header->toString()
  58. );
  59. }
  60. // -- Private methods
  61. private function _getHeader($name)
  62. {
  63. return new Swift_Mime_Headers_DateHeader($name, new Swift_Mime_Grammar());
  64. }
  65. }