PopBeforeSmtpPluginTest.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. require_once 'Swift/Tests/SwiftUnitTestCase.php';
  3. require_once 'Swift/Plugins/AntiFloodPlugin.php';
  4. require_once 'Swift/Events/TransportChangeEvent.php';
  5. require_once 'Swift/Transport.php';
  6. class Swift_Plugins_PopBeforeSmtpPluginTest
  7. extends Swift_Tests_SwiftUnitTestCase
  8. {
  9. public function testPluginConnectsToPop3HostBeforeTransportStarts()
  10. {
  11. $connection = $this->_createConnection();
  12. $plugin = $this->_createPlugin('pop.host.tld', 110);
  13. $plugin->setConnection($connection);
  14. $transport = $this->_createTransport();
  15. $evt = $this->_createTransportChangeEvent($transport);
  16. $this->_checking(Expectations::create()
  17. -> one($connection)->connect()
  18. -> ignoring($connection)
  19. );
  20. $plugin->beforeTransportStarted($evt);
  21. }
  22. public function testPluginDisconnectsFromPop3HostBeforeTransportStarts()
  23. {
  24. $connection = $this->_createConnection();
  25. $plugin = $this->_createPlugin('pop.host.tld', 110);
  26. $plugin->setConnection($connection);
  27. $transport = $this->_createTransport();
  28. $evt = $this->_createTransportChangeEvent($transport);
  29. $this->_checking(Expectations::create()
  30. -> one($connection)->disconnect()
  31. -> ignoring($connection)
  32. );
  33. $plugin->beforeTransportStarted($evt);
  34. }
  35. public function testPluginDoesNotConnectToSmtpIfBoundToDifferentTransport()
  36. {
  37. $connection = $this->_createConnection();
  38. $smtp = $this->_createTransport();
  39. $plugin = $this->_createPlugin('pop.host.tld', 110);
  40. $plugin->setConnection($connection);
  41. $plugin->bindSmtp($smtp);
  42. $transport = $this->_createTransport();
  43. $evt = $this->_createTransportChangeEvent($transport);
  44. $this->_checking(Expectations::create()
  45. -> never($connection)
  46. );
  47. $plugin->beforeTransportStarted($evt);
  48. }
  49. public function testPluginCanBindToSpecificTransport()
  50. {
  51. $connection = $this->_createConnection();
  52. $smtp = $this->_createTransport();
  53. $plugin = $this->_createPlugin('pop.host.tld', 110);
  54. $plugin->setConnection($connection);
  55. $plugin->bindSmtp($smtp);
  56. $evt = $this->_createTransportChangeEvent($smtp);
  57. $this->_checking(Expectations::create()
  58. -> one($connection)->connect()
  59. -> ignoring($connection)
  60. );
  61. $plugin->beforeTransportStarted($evt);
  62. }
  63. // -- Creation Methods
  64. private function _createTransport()
  65. {
  66. return $this->_mock('Swift_Transport');
  67. }
  68. private function _createTransportChangeEvent($transport)
  69. {
  70. $evt = $this->_mock('Swift_Events_TransportChangeEvent');
  71. $this->_checking(Expectations::create()
  72. -> ignoring($evt)->getSource() -> returns($transport)
  73. -> ignoring($evt)->getTransport() -> returns($transport)
  74. );
  75. return $evt;
  76. }
  77. public function _createConnection()
  78. {
  79. return $this->_mock('Swift_Plugins_Pop_Pop3Connection');
  80. }
  81. public function _createPlugin($host, $port, $crypto = null)
  82. {
  83. return new Swift_Plugins_PopBeforeSmtpPlugin($host, $port, $crypto);
  84. }
  85. }