SendEventTest.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. require_once 'Swift/Tests/SwiftUnitTestCase.php';
  3. require_once 'Swift/Events/SendEvent.php';
  4. require_once 'Swift/Mime/Message.php';
  5. require_once 'Swift/Transport.php';
  6. class Swift_Events_SendEventTest extends Swift_Tests_SwiftUnitTestCase
  7. {
  8. public function testMessageCanBeFetchedViaGetter()
  9. {
  10. $message = $this->_createMessage();
  11. $transport = $this->_createTransport();
  12. $evt = $this->_createEvent($transport, $message);
  13. $ref = $evt->getMessage();
  14. $this->assertReference($message, $ref,
  15. '%s: Message should be returned from getMessage()'
  16. );
  17. }
  18. public function testTransportCanBeFetchViaGetter()
  19. {
  20. $message = $this->_createMessage();
  21. $transport = $this->_createTransport();
  22. $evt = $this->_createEvent($transport, $message);
  23. $ref = $evt->getTransport();
  24. $this->assertReference($transport, $ref,
  25. '%s: Transport should be returned from getTransport()'
  26. );
  27. }
  28. public function testTransportCanBeFetchViaGetSource()
  29. {
  30. $message = $this->_createMessage();
  31. $transport = $this->_createTransport();
  32. $evt = $this->_createEvent($transport, $message);
  33. $ref = $evt->getSource();
  34. $this->assertReference($transport, $ref,
  35. '%s: Transport should be returned from getSource()'
  36. );
  37. }
  38. public function testResultCanBeSetAndGet()
  39. {
  40. $message = $this->_createMessage();
  41. $transport = $this->_createTransport();
  42. $evt = $this->_createEvent($transport, $message);
  43. $evt->setResult(
  44. Swift_Events_SendEvent::RESULT_SUCCESS | Swift_Events_SendEvent::RESULT_TENTATIVE
  45. );
  46. $this->assertTrue($evt->getResult() & Swift_Events_SendEvent::RESULT_SUCCESS);
  47. $this->assertTrue($evt->getResult() & Swift_Events_SendEvent::RESULT_TENTATIVE);
  48. }
  49. public function testFailedRecipientsCanBeSetAndGet()
  50. {
  51. $message = $this->_createMessage();
  52. $transport = $this->_createTransport();
  53. $evt = $this->_createEvent($transport, $message);
  54. $evt->setFailedRecipients(array('foo@bar', 'zip@button'));
  55. $this->assertEqual(array('foo@bar', 'zip@button'), $evt->getFailedRecipients(),
  56. '%s: FailedRecipients should be returned from getter'
  57. );
  58. }
  59. public function testFailedRecipientsGetsPickedUpCorrectly() {
  60. $message = $this->_createMessage();
  61. $transport = $this->_createTransport();
  62. $evt = $this->_createEvent($transport, $message);
  63. $this->assertEqual(array(), $evt->getFailedRecipients());
  64. }
  65. // -- Creation Methods
  66. private function _createEvent(Swift_Transport $source,
  67. Swift_Mime_Message $message)
  68. {
  69. return new Swift_Events_SendEvent($source, $message);
  70. }
  71. private function _createTransport()
  72. {
  73. return $this->_stub('Swift_Transport');
  74. }
  75. private function _createMessage()
  76. {
  77. return $this->_stub('Swift_Mime_Message');
  78. }
  79. }