ReporterPluginTest.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. require_once 'Swift/Tests/SwiftUnitTestCase.php';
  3. require_once 'Swift/Plugins/ReporterPlugin.php';
  4. require_once 'Swift/Plugins/Reporter.php';
  5. require_once 'Swift/Mime/Message.php';
  6. require_once 'Swift/Events/SendEvent.php';
  7. class Swift_Plugins_ReporterPluginTest extends Swift_Tests_SwiftUnitTestCase
  8. {
  9. public function testReportingPasses()
  10. {
  11. $message = $this->_createMessage();
  12. $evt = $this->_createSendEvent();
  13. $reporter = $this->_createReporter();
  14. $this->_checking(Expectations::create()
  15. -> allowing($message)->getTo() -> returns(array('foo@bar.tld' => 'Foo'))
  16. -> allowing($evt)->getMessage() -> returns($message)
  17. -> allowing($evt)->getFailedRecipients() -> returns(array())
  18. -> one($reporter)->notify($message, 'foo@bar.tld', Swift_Plugins_Reporter::RESULT_PASS)
  19. -> ignoring($message)
  20. -> ignoring($evt)
  21. );
  22. $plugin = new Swift_Plugins_ReporterPlugin($reporter);
  23. $plugin->sendPerformed($evt);
  24. }
  25. public function testReportingFailedTo()
  26. {
  27. $message = $this->_createMessage();
  28. $evt = $this->_createSendEvent();
  29. $reporter = $this->_createReporter();
  30. $this->_checking(Expectations::create()
  31. -> allowing($message)->getTo() -> returns(array(
  32. 'foo@bar.tld' => 'Foo', 'zip@button' => 'Zip'
  33. ))
  34. -> allowing($evt)->getMessage() -> returns($message)
  35. -> allowing($evt)->getFailedRecipients() -> returns(array('zip@button'))
  36. -> one($reporter)->notify($message, 'foo@bar.tld', Swift_Plugins_Reporter::RESULT_PASS)
  37. -> one($reporter)->notify($message, 'zip@button', Swift_Plugins_Reporter::RESULT_FAIL)
  38. -> ignoring($message)
  39. -> ignoring($evt)
  40. );
  41. $plugin = new Swift_Plugins_ReporterPlugin($reporter);
  42. $plugin->sendPerformed($evt);
  43. }
  44. public function testReportingFailedCc()
  45. {
  46. $message = $this->_createMessage();
  47. $evt = $this->_createSendEvent();
  48. $reporter = $this->_createReporter();
  49. $this->_checking(Expectations::create()
  50. -> allowing($message)->getTo() -> returns(array(
  51. 'foo@bar.tld' => 'Foo'
  52. ))
  53. -> allowing($message)->getCc() -> returns(array(
  54. 'zip@button' => 'Zip', 'test@test.com' => 'Test'
  55. ))
  56. -> allowing($evt)->getMessage() -> returns($message)
  57. -> allowing($evt)->getFailedRecipients() -> returns(array('zip@button'))
  58. -> one($reporter)->notify($message, 'foo@bar.tld', Swift_Plugins_Reporter::RESULT_PASS)
  59. -> one($reporter)->notify($message, 'zip@button', Swift_Plugins_Reporter::RESULT_FAIL)
  60. -> one($reporter)->notify($message, 'test@test.com', Swift_Plugins_Reporter::RESULT_PASS)
  61. -> ignoring($message)
  62. -> ignoring($evt)
  63. );
  64. $plugin = new Swift_Plugins_ReporterPlugin($reporter);
  65. $plugin->sendPerformed($evt);
  66. }
  67. public function testReportingFailedBcc()
  68. {
  69. $message = $this->_createMessage();
  70. $evt = $this->_createSendEvent();
  71. $reporter = $this->_createReporter();
  72. $this->_checking(Expectations::create()
  73. -> allowing($message)->getTo() -> returns(array(
  74. 'foo@bar.tld' => 'Foo'
  75. ))
  76. -> allowing($message)->getBcc() -> returns(array(
  77. 'zip@button' => 'Zip', 'test@test.com' => 'Test'
  78. ))
  79. -> allowing($evt)->getMessage() -> returns($message)
  80. -> allowing($evt)->getFailedRecipients() -> returns(array('zip@button'))
  81. -> one($reporter)->notify($message, 'foo@bar.tld', Swift_Plugins_Reporter::RESULT_PASS)
  82. -> one($reporter)->notify($message, 'zip@button', Swift_Plugins_Reporter::RESULT_FAIL)
  83. -> one($reporter)->notify($message, 'test@test.com', Swift_Plugins_Reporter::RESULT_PASS)
  84. -> ignoring($message)
  85. -> ignoring($evt)
  86. );
  87. $plugin = new Swift_Plugins_ReporterPlugin($reporter);
  88. $plugin->sendPerformed($evt);
  89. }
  90. // -- Creation Methods
  91. private function _createMessage()
  92. {
  93. return $this->_mock('Swift_Mime_Message');
  94. }
  95. private function _createSendEvent()
  96. {
  97. return $this->_mock('Swift_Events_SendEvent');
  98. }
  99. private function _createReporter()
  100. {
  101. return $this->_mock('Swift_Plugins_Reporter');
  102. }
  103. }