Modified: trunk/Mail/tests/transports/transport_pop3_test.php
==============================================================================
--- trunk/Mail/tests/transports/transport_pop3_test.php [iso-8859-1] (original)
+++ trunk/Mail/tests/transports/transport_pop3_test.php [iso-8859-1] Mon Jul  2 
13:22:39 2007
@@ -8,6 +8,8 @@
  * @subpackage Tests
  */
 
+include_once( 'wrappers/pop3_wrapper.php' );
+
 /**
  * @package Mail
  * @subpackage Tests
@@ -16,6 +18,234 @@
 {
     private static $ids = array();
 
+    private static $server = 'dolly.ez.no';
+    private static $serverSSL = 'ezctest.ez.no';
+    private static $port = 110;
+    private static $portSSL = 955;
+    private static $user = 'ezcomponents';
+    private static $password = 'ezcomponents';
+    private static $userSSL = 'as';
+    private static $passwordSSL = 'wee123';
+
+    public function testWrapperMockConnectionConstructResponseNotOk()
+    {
+        try
+        {
+            $pop3 = $this->getMock( 'ezcMailPop3TransportWrapper', array( 
'isPositiveResponse' ), array( self::$server, self::$port ) );
+            $pop3->expects( $this->any() )
+                 ->method( 'isPositiveResponse' )
+                 ->will( $this->returnValue( false ) );
+            $this->fail( 'Expected exception was not thrown.' );
+        }
+        catch ( ezcMailTransportException $e )
+        {
+            $this->assertEquals( "An error occured while sending or receiving 
mail. The connection to the POP3 server is ok, but a negative response from 
server was received: '+OK Welcome'. Try again later.", str_replace( array( 
"\n", "\r" ), '', $e->getMessage() ) );
+        }
+    }
+
+    public function testWrapperMockConnectionAuthenticateResponseNotOk()
+    {
+        $connection = $this->getMock( 'ezcMailTransportConnection', array(), 
array( self::$server, self::$port ) );
+        $connection->expects( $this->any() )
+                   ->method( 'getLine' )
+                   ->will( $this->returnValue( 'custom response' ) );
+        $pop3 = new ezcMailPop3TransportWrapper( self::$server, self::$port );
+        $pop3->setConnection( $connection );
+
+        try
+        {
+            $pop3->authenticate( self::$user, self::$password );
+            $this->fail( 'Expected exception was not thrown.' );
+        }
+        catch ( ezcMailTransportException $e )
+        {
+            $this->assertEquals( "An error occured while sending or receiving 
mail. The POP3 server did not accept the username: custom response.", 
$e->getMessage() );
+        }
+        $pop3->setStatus( ezcMailPop3Transport::STATE_NOT_CONNECTED );
+    }
+
+    public function testWrapperMockConnectionAuthenticateApopFail()
+    {
+        $connection = $this->getMock( 'ezcMailTransportConnection', array(), 
array( self::$server, self::$port ) );
+        $connection->expects( $this->any() )
+                   ->method( 'getLine' )
+                   ->will( $this->returnValue( 'custom response' ) );
+        $pop3 = new ezcMailPop3TransportWrapper( self::$server, self::$port );
+        $pop3->setConnection( $connection );
+        $pop3->setGreeting( '+OK POP3 server ready <[EMAIL PROTECTED]>');
+
+        try
+        {
+            $pop3->authenticate( self::$user, self::$password, 
ezcMailPop3Transport::AUTH_APOP );
+            $this->fail( 'Expected exception was not thrown.' );
+        }
+        catch ( ezcMailTransportException $e )
+        {
+            $this->assertEquals( "An error occured while sending or receiving 
mail. The POP3 server did not accept the APOP login: custom response.", 
$e->getMessage() );
+        }
+        $pop3->setStatus( ezcMailPop3Transport::STATE_NOT_CONNECTED );
+    }
+
+    public function testWrapperMockConnectionAuthenticateApopOk()
+    {
+        $connection = $this->getMock( 'ezcMailTransportConnection', array(), 
array( self::$server, self::$port ) );
+        $connection->expects( $this->any() )
+                   ->method( 'getLine' )
+                   ->will( $this->returnValue( '+OK custom response' ) );
+        $pop3 = new ezcMailPop3TransportWrapper( self::$server, self::$port );
+        $pop3->setConnection( $connection );
+        $pop3->setGreeting( '+OK POP3 server ready <[EMAIL PROTECTED]>');
+        $pop3->authenticate( self::$user, self::$password, 
ezcMailPop3Transport::AUTH_APOP );
+        $this->assertEquals( ezcMailPop3Transport::STATE_TRANSACTION, 
$pop3->getStatus() );
+        $pop3->disconnect();
+        $this->assertEquals( ezcMailPop3Transport::STATE_NOT_CONNECTED, 
$pop3->getStatus() );
+    }
+
+    public function testWrapperMockConnectionAuthenticateFailInvalidMethod()
+    {
+        $pop3 = new ezcMailPop3TransportWrapper( self::$server, self::$port );
+
+        try
+        {
+            $pop3->authenticate( self::$user, self::$password, 'wrong method' 
);
+            $this->fail( 'Expected exception was not thrown.' );
+        }
+        catch ( ezcMailTransportException $e )
+        {
+            $this->assertEquals( "An error occured while sending or receiving 
mail. Invalid authentication method provided.", $e->getMessage() );
+        }
+        $pop3->setStatus( ezcMailPop3Transport::STATE_NOT_CONNECTED );
+    }
+
+    public function testWrapperMockConnectionDeleteOk()
+    {
+        $connection = $this->getMock( 'ezcMailTransportConnection', array(), 
array( self::$server, self::$port ) );
+        $connection->expects( $this->any() )
+                   ->method( 'getLine' )
+                   ->will( $this->returnValue( '+OK custom response' ) );
+        $pop3 = new ezcMailPop3TransportWrapper( self::$server, self::$port );
+        $pop3->setConnection( $connection );
+        $pop3->authenticate( self::$user, self::$password );
+        $this->assertEquals( ezcMailPop3Transport::STATE_TRANSACTION, 
$pop3->getStatus() );
+        $pop3->delete( 1000 );
+        $pop3->setStatus( ezcMailPop3Transport::STATE_NOT_CONNECTED );
+    }
+
+    public function testWrapperMockConnectionAuthenticateOkListMessagesFail()
+    {
+        $connection = $this->getMock( 'ezcMailTransportConnection', array(), 
array( self::$server, self::$port ) );
+        $connection->expects( $this->any() )
+                   ->method( 'getLine' )
+                   ->will( $this->returnValue( 'custom response' ) );
+        $pop3 = new ezcMailPop3TransportWrapper( self::$server, self::$port );
+        $pop3->authenticate( self::$user, self::$password );
+        $this->assertEquals( ezcMailPop3Transport::STATE_TRANSACTION, 
$pop3->getStatus() );
+        $pop3->setConnection( $connection );
+
+        try
+        {
+            $pop3->listMessages();
+            $this->fail( 'Expected exception was not thrown.' );
+        }
+        catch ( ezcMailTransportException $e )
+        {
+            $this->assertEquals( "An error occured while sending or receiving 
mail. The POP3 server sent a negative response to the LIST command: custom 
response.", $e->getMessage() );
+        }
+        $pop3->setStatus( ezcMailPop3Transport::STATE_NOT_CONNECTED );
+    }
+
+    public function 
testWrapperMockConnectionAuthenticateOkListUniqueIdentifiersFail()
+    {
+        $connection = $this->getMock( 'ezcMailTransportConnection', array(), 
array( self::$server, self::$port ) );
+        $connection->expects( $this->any() )
+                   ->method( 'getLine' )
+                   ->will( $this->returnValue( 'custom response' ) );
+        $pop3 = new ezcMailPop3TransportWrapper( self::$server, self::$port );
+        $pop3->authenticate( self::$user, self::$password );
+        $this->assertEquals( ezcMailPop3Transport::STATE_TRANSACTION, 
$pop3->getStatus() );
+        $pop3->setConnection( $connection );
+
+        try
+        {
+            $pop3->listUniqueIdentifiers();
+            $this->fail( 'Expected exception was not thrown.' );
+        }
+        catch ( ezcMailTransportException $e )
+        {
+            $this->assertEquals( "An error occured while sending or receiving 
mail. The POP3 server sent a negative response to the UIDL command: custom 
response.", $e->getMessage() );
+        }
+        $pop3->setStatus( ezcMailPop3Transport::STATE_NOT_CONNECTED );
+    }
+
+    public function 
testWrapperMockConnectionAuthenticateOkListUniqueIdentifiersSingleFail()
+    {
+        $connection = $this->getMock( 'ezcMailTransportConnection', array(), 
array( self::$server, self::$port ) );
+        $connection->expects( $this->any() )
+                   ->method( 'getLine' )
+                   ->will( $this->returnValue( 'custom response' ) );
+        $pop3 = new ezcMailPop3TransportWrapper( self::$server, self::$port );
+        $pop3->authenticate( self::$user, self::$password );
+        $this->assertEquals( ezcMailPop3Transport::STATE_TRANSACTION, 
$pop3->getStatus() );
+        $pop3->setConnection( $connection );
+
+        try
+        {
+            $pop3->listUniqueIdentifiers( 1 );
+            $this->fail( 'Expected exception was not thrown.' );
+        }
+        catch ( ezcMailTransportException $e )
+        {
+            $this->assertEquals( "An error occured while sending or receiving 
mail. The POP3 server sent a negative response to the UIDL command: custom 
response.", $e->getMessage() );
+        }
+        $pop3->setStatus( ezcMailPop3Transport::STATE_NOT_CONNECTED );
+    }
+
+    public function testWrapperMockConnectionAuthenticateOkStatusFail()
+    {
+        $connection = $this->getMock( 'ezcMailTransportConnection', array(), 
array( self::$server, self::$port ) );
+        $connection->expects( $this->any() )
+                   ->method( 'getLine' )
+                   ->will( $this->returnValue( 'custom response' ) );
+        $pop3 = new ezcMailPop3TransportWrapper( self::$server, self::$port );
+        $pop3->authenticate( self::$user, self::$password );
+        $this->assertEquals( ezcMailPop3Transport::STATE_TRANSACTION, 
$pop3->getStatus() );
+        $pop3->setConnection( $connection );
+
+        try
+        {
+            $pop3->status( $numMessages, $sizeMessages );
+            $this->fail( 'Expected exception was not thrown.' );
+        }
+        catch ( ezcMailTransportException $e )
+        {
+            $this->assertEquals( "An error occured while sending or receiving 
mail. The POP3 server did not respond with a status message: custom response.", 
$e->getMessage() );
+        }
+        $pop3->setStatus( ezcMailPop3Transport::STATE_NOT_CONNECTED );
+    }
+
+    public function testWrapperMockConnectionAuthenticateOkNoopFail()
+    {
+        $connection = $this->getMock( 'ezcMailTransportConnection', array(), 
array( self::$server, self::$port ) );
+        $connection->expects( $this->any() )
+                   ->method( 'getLine' )
+                   ->will( $this->returnValue( 'custom response' ) );
+        $pop3 = new ezcMailPop3TransportWrapper( self::$server, self::$port );
+        $pop3->authenticate( self::$user, self::$password );
+        $this->assertEquals( ezcMailPop3Transport::STATE_TRANSACTION, 
$pop3->getStatus() );
+        $pop3->setConnection( $connection );
+
+        try
+        {
+            $pop3->noop();
+            $this->fail( 'Expected exception was not thrown.' );
+        }
+        catch ( ezcMailTransportException $e )
+        {
+            $this->assertEquals( "An error occured while sending or receiving 
mail. The POP3 server sent a negative response to the NOOP command: custom 
response.", $e->getMessage() );
+        }
+        $pop3->setStatus( ezcMailPop3Transport::STATE_NOT_CONNECTED );
+    }
+
     public function testInvalidServer()
     {
         try
@@ -32,7 +262,7 @@
     {
         try
         {
-            $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
+            $pop3 = new ezcMailPop3Transport( self::$server );
             $pop3->authenticate( "no_such_user", "ezcomponents" );
             $this->fail( "Didn't get exception when expected" );
         }
@@ -45,7 +275,7 @@
     {
         try
         {
-            $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
+            $pop3 = new ezcMailPop3Transport( self::$server );
             $pop3->authenticate( "ezcomponents", "no_such_password" );
             $this->fail( "Didn't get exception when expected" );
         }
@@ -56,7 +286,7 @@
 
     public function testInvalidCallListMessages()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
         $pop3->disconnect();
         try
         {
@@ -70,7 +300,7 @@
 
     public function testInvalidCallTop()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
         $pop3->disconnect();
         try
         {
@@ -84,7 +314,7 @@
 
     public function testInvalidCallStatus()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
         $pop3->disconnect();
         try
         {
@@ -98,7 +328,7 @@
 
     public function testInvalidCallDelete()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
         $pop3->disconnect();
         try
         {
@@ -112,11 +342,11 @@
 
     public function testLoginAuthenticated()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
-        try
-        {
-            $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
+        try
+        {
+            $pop3->authenticate( self::$user, self::$password );
             $this->fail( "Didn't get exception when expected" );
         }
         catch ( ezcMailTransportException $e )
@@ -126,7 +356,7 @@
 
     public function testInvalidCallListUniqueMessages()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
         $pop3->disconnect();
         try
         {
@@ -140,8 +370,8 @@
 
     public function testFetchMail()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         $set = $pop3->fetchAll();
         $parser = new ezcMailParser();
         $mail = $parser->parseMail( $set );
@@ -150,16 +380,16 @@
 
     public function testListMessages()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         $list = $pop3->listMessages();
         $this->assertEquals( array( 1 => '1542', 2 => '1539', 3 => '1383', 4 
=> '63913' ), $list );
     }
 
     public function testFetchByMessageNr1()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         try
         {
             $message = $pop3->fetchByMessageNr( -1 );
@@ -173,8 +403,8 @@
 
     public function testFetchByMessageNr2()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         try
         {
             $message = $pop3->fetchByMessageNr( 0 );
@@ -188,8 +418,8 @@
 
     public function testFetchByMessageNr3()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         $message = $pop3->fetchByMessageNr( 1 );
         $parser = new ezcMailParser();
         $mail = $parser->parseMail( $message );
@@ -200,8 +430,8 @@
     
     public function testfetchFromOffset1()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         try
         {
             $set = $pop3->fetchFromOffset( -1, 10 );
@@ -215,8 +445,8 @@
 
     public function testfetchFromOffset2()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         try
         {
             $set = $pop3->fetchFromOffset( 10, 1 );
@@ -230,8 +460,8 @@
 
     public function testfetchFromOffset3()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         try
         {
             $set = $pop3->fetchFromOffset( 0, -1 );
@@ -245,8 +475,8 @@
 
     public function testfetchFromOffset4()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         $set = $pop3->fetchFromOffset( 1, 4 );
         $parser = new ezcMailParser();
         $mail = $parser->parseMail( $set );
@@ -256,8 +486,8 @@
 
     public function testfetchFromOffset5()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         $set = $pop3->fetchFromOffset( 1, 0 );
         $parser = new ezcMailParser();
         $mail = $parser->parseMail( $set );
@@ -267,8 +497,8 @@
 
     public function testStatus()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         $pop3->status( $num, $size );
         $this->assertEquals( 4, $num );
         $this->assertEquals( 68377, $size );
@@ -276,8 +506,8 @@
 
     public function testTop()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         $list = $pop3->top( 1, 1 );
         // we do a simple test here.. Any non-single line reply here is 99.9% 
certainly a good reply
         $this->assertEquals( true, count( explode( "\n", $list ) ) > 1 );
@@ -285,8 +515,8 @@
 
     public function testInvalidTop()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         try
         {
             $pop3->top( 1000, 1 );
@@ -299,8 +529,8 @@
 
     public function testDelete()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         try
         {
             $pop3->delete( 1000 );
@@ -313,15 +543,15 @@
     
     public function testListUniqueIdentifiersSingle()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         $this->assertEquals( array( 1 => self::$ids[0] ), 
$pop3->listUniqueIdentifiers( 1 ) );
     }
 
     public function testListUniqueIdentifiersMultiple()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         $this->assertEquals(
             array(
                 1 => self::$ids[0],
@@ -337,8 +567,8 @@
     {
         try
         {
-            $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-            $pop3->authenticate( "ezcomponents", "ezcomponents", 
ezcMailPop3Transport::AUTH_APOP );
+            $pop3 = new ezcMailPop3Transport( self::$server );
+            $pop3->authenticate( self::$user, self::$password, 
ezcMailPop3Transport::AUTH_APOP );
             $this->fail( "Did not get excepted exception" );
         }
         catch ( ezcMailTransportException $e )
@@ -348,16 +578,16 @@
 
     public function testDisconnect()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         $pop3->disconnect();
         $pop3->disconnect();
     }
 
     public function testGetMessageNumbersFromSet()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         $set = $pop3->fetchAll();
         $messageNumbers = $set->getMessageNumbers();
         $this->assertEquals( array( 1, 2, 3, 4 ), $messageNumbers );
@@ -365,14 +595,14 @@
 
     public function testNoop()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         $pop3->noop();
     }
 
     public function testNoopNotConnected()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
         $pop3->disconnect();
         try
         {
@@ -386,8 +616,8 @@
 
     public function testMessageSize()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
-        $pop3->authenticate( "ezcomponents", "ezcomponents" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
+        $pop3->authenticate( self::$user, self::$password );
         $set = $pop3->fetchAll();
         $parser = new ezcMailParser();
         $mail = $parser->parseMail( $set );
@@ -402,7 +632,7 @@
 
     public function testTransportProperties()
     {
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
+        $pop3 = new ezcMailPop3Transport( self::$server );
         $this->assertEquals( true, isset( $pop3->options ) );
         $this->assertEquals( false, isset( $pop3->no_such_property ) );
 
@@ -446,12 +676,12 @@
     public function testTransportPropertiesBefore()
     {
         $options = array( 'authenticationMethod' => 
ezcMailPop3Transport::AUTH_PLAIN_TEXT );
-        $pop3 = new ezcMailPop3Transport( "dolly.ez.no", null, $options );
+        $pop3 = new ezcMailPop3Transport( self::$server, null, $options );
     }
 
     public function testTransportConnection()
     {
-        $connection = new ezcMailTransportConnection( "dolly.ez.no", 143 );
+        $connection = new ezcMailTransportConnection( self::$server, 143 );
         $expected = new ezcMailTransportOptions();
         $this->assertEquals( $expected, $connection->options );
     }
@@ -462,8 +692,8 @@
         {
             $this->markTestSkipped();
         }
-        $pop3 = new ezcMailPop3Transport( "ezctest.ez.no", null, array( 'ssl' 
=> true ) );
-        $pop3->authenticate( "as", "wee123" );
+        $pop3 = new ezcMailPop3Transport( self::$serverSSL, null, array( 'ssl' 
=> true ) );
+        $pop3->authenticate( self::$userSSL, self::$passwordSSL );
         $set = $pop3->fetchAll();
         $parser = new ezcMailParser();
         $mail = $parser->parseMail( $set );
@@ -479,12 +709,51 @@
         }
         try
         {
-            $pop3 = new ezcMailPop3Transport( "ezctest.ez.no", 110, array( 
'ssl' => true ) );
+            $pop3 = new ezcMailPop3Transport( self::$serverSSL, self::$port, 
array( 'ssl' => true ) );
             $this->fail( "Didn't get exception when expected" );
         }
         catch ( ezcMailTransportException $e )
         {
             $this->assertEquals( 'An error occured while sending or receiving 
mail. Failed to connect to the server: ezctest.ez.no:110.', $e->getMessage() );
+        }
+    }
+
+    public function testTransportOptionsDefault()
+    {
+        $options = new ezcMailPop3TransportOptions();
+        $this->assertEquals( ezcMailPop3Transport::AUTH_PLAIN_TEXT, 
$options->authenticationMethod );
+    }
+
+    public function testTransportOptionsSet()
+    {
+        $options = new ezcMailPop3TransportOptions();
+        $options->authenticationMethod = ezcMailPop3Transport::AUTH_APOP;
+        $this->assertEquals( ezcMailPop3Transport::AUTH_APOP, 
$options->authenticationMethod );
+    }
+
+    public function testTransportOptionsSetInvalid()
+    {
+        $options = new ezcMailPop3TransportOptions();
+        try
+        {
+            $options->authenticationMethod = 'xxx';
+            $this->fail( "Expected exception was not thrown" );
+        }
+        catch ( ezcBaseValueException $e )
+        {
+        }
+    }
+
+    public function testTransportOptionsSetNotExistent()
+    {
+        $options = new ezcMailPop3TransportOptions();
+        try
+        {
+            $options->no_such_option = 'xxx';
+            $this->fail( "Expected exception was not thrown" );
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
+        {
         }
     }
 

Modified: trunk/Mail/tests/transports/transport_smtp_test.php
==============================================================================
--- trunk/Mail/tests/transports/transport_smtp_test.php [iso-8859-1] (original)
+++ trunk/Mail/tests/transports/transport_smtp_test.php [iso-8859-1] Mon Jul  2 
13:22:39 2007
@@ -8,6 +8,8 @@
  * @subpackage Tests
  */
 
+include_once( 'wrappers/smtp_wrapper.php' );
+
 /**
  * @package Mail
  * @subpackage Tests
@@ -17,18 +19,20 @@
     private $transport;
     private $mail;
 
-    const HOST = "10.0.2.35";
-
+    const HOST = '10.0.2.35';
     const PORT = 2525;
 
+    const HOST_SSL = 'ezctest.ez.no';
+    const PORT_SSL = 465;
+
     protected function setUp()
     {
-        if ( @fsockopen( ezcMailTransportSmtpTest::HOST, 
ezcMailTransportSmtpTest::PORT, $errno, $errstr, 1 ) === false )
-        {
-            $this->markTestSkipped( "No connection to SMTP server " . 
ezcMailTransportSmtpTest::HOST . ":" . ezcMailTransportSmtpTest::PORT . "." );
-        }
-
-        $this->transport = new ezcMailTransportSmtp( 
ezcMailTransportSmtpTest::HOST, '', '', ezcMailTransportSmtpTest::PORT );
+        if ( @fsockopen( self::HOST, self::PORT, $errno, $errstr, 1 ) === 
false )
+        {
+            $this->markTestSkipped( "No connection to SMTP server " . 
self::HOST . ":" . self::PORT . "." );
+        }
+
+        $this->transport = new ezcMailTransportSmtp( self::HOST, '', '', 
self::PORT );
         $this->mail = new ezcMail();
         $this->mail->from = new ezcMailAddress( '[EMAIL PROTECTED]', 'Unit 
testing' );
         $this->mail->addTo( new ezcMailAddress( '[EMAIL PROTECTED]', 'Foster' 
) );
@@ -36,6 +40,216 @@
         $this->mail->body = new ezcMailText( "It doesn't look as if it's ever 
used." );
     }
 
+    
+    public function testWrapperMockLoginAuthenticateFail250()
+    {
+        $smtp = $this->getMock( 'ezcMailSmtpTransport', array( 'getReplyCode', 
'sendData' ), array( self::HOST, 'user', 'password', self::PORT ) );
+        $smtp->expects( $this->any() )
+             ->method( 'getReplyCode' )
+             ->will( $this->onConsecutiveCalls(
+                        $this->returnValue( 'custom response' )
+                   ) );
+
+        $smtp->expects( $this->any() )
+             ->method( 'sendData' )
+             ->will( $this->returnValue( false ) );
+
+        try
+        {
+            $smtp->login();
+            $this->fail( 'Expected exception was not thrown.' );
+        }
+        catch ( ezcMailTransportSmtpException $e )
+        {
+            $this->assertEquals( "HELO/EHLO failed with error: .", 
$e->getMessage() );
+        }
+        $smtp->setStatus( ezcMailSmtpTransport::STATUS_NOT_CONNECTED );
+    }
+
+    public function testWrapperMockLoginAuthenticateFail334()
+    {
+        $smtp = $this->getMock( 'ezcMailSmtpTransportWrapper', array( 
'getReplyCode', 'sendData' ), array( self::HOST, 'user', 'password', self::PORT 
) );
+        $smtp->expects( $this->any() )
+             ->method( 'getReplyCode' )
+             ->will( $this->onConsecutiveCalls(
+                        $this->returnValue( '250' ),
+                        $this->returnValue( 'custom response' )
+                   ) );
+
+        $smtp->expects( $this->any() )
+             ->method( 'sendData' )
+             ->will( $this->returnValue( false ) );
+
+        try
+        {
+            $smtp->login();
+            $this->fail( 'Expected exception was not thrown.' );
+        }
+        catch ( ezcMailTransportSmtpException $e )
+        {
+            $this->assertEquals( "SMTP server does not accept AUTH LOGIN.", 
$e->getMessage() );
+        }
+        $smtp->setStatus( ezcMailSmtpTransport::STATUS_NOT_CONNECTED );
+    }
+
+    public function testWrapperMockLoginAuthenticateFailUser334()
+    {
+        $smtp = $this->getMock( 'ezcMailSmtpTransportWrapper', array( 
'getReplyCode', 'sendData' ), array( self::HOST, 'user', 'password', self::PORT 
) );
+        $smtp->expects( $this->any() )
+             ->method( 'getReplyCode' )
+             ->will( $this->onConsecutiveCalls(
+                        $this->returnValue( '250' ),
+                        $this->returnValue( '334' ),
+                        $this->returnValue( 'custom response' )
+                   ) );
+
+        $smtp->expects( $this->any() )
+             ->method( 'sendData' )
+             ->will( $this->returnValue( false ) );
+
+        try
+        {
+            $smtp->login();
+            $this->fail( 'Expected exception was not thrown.' );
+        }
+        catch ( ezcMailTransportSmtpException $e )
+        {
+            $this->assertEquals( "SMTP server does not accept login: user.", 
$e->getMessage() );
+        }
+        $smtp->setStatus( ezcMailSmtpTransport::STATUS_NOT_CONNECTED );
+    }
+
+    public function testWrapperMockLoginAuthenticateFailPassword334()
+    {
+        $smtp = $this->getMock( 'ezcMailSmtpTransportWrapper', array( 
'getReplyCode', 'sendData' ), array( self::HOST, 'user', 'password', self::PORT 
) );
+        $smtp->expects( $this->any() )
+             ->method( 'getReplyCode' )
+             ->will( $this->onConsecutiveCalls(
+                        $this->returnValue( '250' ),
+                        $this->returnValue( '334' ),
+                        $this->returnValue( '334' ),
+                        $this->returnValue( 'custom response' )
+                   ) );
+
+        $smtp->expects( $this->any() )
+             ->method( 'sendData' )
+             ->will( $this->returnValue( false ) );
+
+        try
+        {
+            $smtp->login();
+            $this->fail( 'Expected exception was not thrown.' );
+        }
+        catch ( ezcMailTransportSmtpException $e )
+        {
+            $this->assertEquals( "SMTP server does not accept the password.", 
$e->getMessage() );
+        }
+        $smtp->setStatus( ezcMailSmtpTransport::STATUS_NOT_CONNECTED );
+    }
+
+    public function testWrapperMockLoginAuthenticateSucceed()
+    {
+        $smtp = $this->getMock( 'ezcMailSmtpTransportWrapper', array( 
'getReplyCode', 'sendData' ), array( self::HOST, 'user', 'password', self::PORT 
) );
+        $smtp->expects( $this->any() )
+             ->method( 'getReplyCode' )
+             ->will( $this->onConsecutiveCalls(
+                        $this->returnValue( '250' ),
+                        $this->returnValue( '334' ),
+                        $this->returnValue( '334' ),
+                        $this->returnValue( '235' )
+                   ) );
+
+        $smtp->expects( $this->any() )
+             ->method( 'sendData' )
+             ->will( $this->returnValue( false ) );
+
+        $smtp->login();
+        $this->assertEquals( ezcMailSmtpTransport::STATUS_AUTHENTICATED, 
$smtp->getStatus() );
+        $smtp->setStatus( ezcMailSmtpTransport::STATUS_NOT_CONNECTED );
+        $this->assertEquals( ezcMailSmtpTransport::STATUS_NOT_CONNECTED, 
$smtp->getStatus() );
+    }
+
+    public function testWrapperMockCmdMailFail()
+    {
+        $smtp = $this->getMock( 'ezcMailSmtpTransportWrapper', array( 
'getReplyCode', 'sendData' ), array( self::HOST, 'user', 'password', self::PORT 
) );
+        $smtp->expects( $this->any() )
+             ->method( 'getReplyCode' )
+             ->will( $this->onConsecutiveCalls(
+                        $this->returnValue( 'custom response' )
+                   ) );
+
+        $smtp->expects( $this->any() )
+             ->method( 'sendData' )
+             ->will( $this->returnValue( false ) );
+
+        $smtp->setStatus( ezcMailSmtpTransport::STATUS_AUTHENTICATED );
+
+        try
+        {
+            $smtp->cmdMail( '[EMAIL PROTECTED]' );
+            $this->fail( 'Expected exception was not thrown.' );
+        }
+        catch ( ezcMailTransportSmtpException $e )
+        {
+            $this->assertEquals( "MAIL FROM failed with error: .", 
$e->getMessage() );
+        }
+        $smtp->setStatus( ezcMailSmtpTransport::STATUS_NOT_CONNECTED );
+    }
+
+    public function testWrapperMockCmdRpctFail()
+    {
+        $smtp = $this->getMock( 'ezcMailSmtpTransportWrapper', array( 
'getReplyCode', 'sendData' ), array( self::HOST, 'user', 'password', self::PORT 
) );
+        $smtp->expects( $this->any() )
+             ->method( 'getReplyCode' )
+             ->will( $this->onConsecutiveCalls(
+                        $this->returnValue( 'custom response' )
+                   ) );
+
+        $smtp->expects( $this->any() )
+             ->method( 'sendData' )
+             ->will( $this->returnValue( false ) );
+
+        $smtp->setStatus( ezcMailSmtpTransport::STATUS_AUTHENTICATED );
+
+        try
+        {
+            $smtp->cmdRcpt( '[EMAIL PROTECTED]' );
+            $this->fail( 'Expected exception was not thrown.' );
+        }
+        catch ( ezcMailTransportSmtpException $e )
+        {
+            $this->assertEquals( "RCPT TO failed with error: .", 
$e->getMessage() );
+        }
+        $smtp->setStatus( ezcMailSmtpTransport::STATUS_NOT_CONNECTED );
+    }
+
+    public function testWrapperMockCmdDataFail()
+    {
+        $smtp = $this->getMock( 'ezcMailSmtpTransportWrapper', array( 
'getReplyCode', 'sendData' ), array( self::HOST, 'user', 'password', self::PORT 
) );
+        $smtp->expects( $this->any() )
+             ->method( 'getReplyCode' )
+             ->will( $this->onConsecutiveCalls(
+                        $this->returnValue( 'custom response' )
+                   ) );
+
+        $smtp->expects( $this->any() )
+             ->method( 'sendData' )
+             ->will( $this->returnValue( false ) );
+
+        $smtp->setStatus( ezcMailSmtpTransport::STATUS_AUTHENTICATED );
+
+        try
+        {
+            $smtp->cmdData();
+            $this->fail( 'Expected exception was not thrown.' );
+        }
+        catch ( ezcMailTransportSmtpException $e )
+        {
+            $this->assertEquals( "DATA failed with error: .", $e->getMessage() 
);
+        }
+        $smtp->setStatus( ezcMailSmtpTransport::STATUS_NOT_CONNECTED );
+    }
+
     public function testProperties()
     {
         try
@@ -155,7 +369,7 @@
             // great, it failed.
             return;
         }
-        $transport = new ezcMailTransportSmtp( "10.0.2.35", '', '', 26 ); // 
wrong port
+        $transport = new ezcMailTransportSmtp( self::HOST, '', '', 26 ); // 
wrong port
         try
         {
             $transport->send( $this->mail );
@@ -228,7 +442,7 @@
 
     public function testTransportProperties()
     {
-        $smtp = new ezcMailSmtpTransport( ezcMailTransportSmtpTest::HOST, '', 
'', ezcMailTransportSmtpTest::PORT );
+        $smtp = new ezcMailSmtpTransport( self::HOST, '', '', self::PORT );
 
         $options = $smtp->options;
         $smtp->options = new ezcMailSmtpTransportOptions();
@@ -279,7 +493,7 @@
         }
         try
         {
-            $smtp = new ezcMailSmtpTransport( 'ezctest.ez.no', '', '', null, 
array( 'connectionType' => ezcMailSmtpTransport::CONNECTION_SSL ) );
+            $smtp = new ezcMailSmtpTransport( self::HOST_SSL, '', '', null, 
array( 'connectionType' => ezcMailSmtpTransport::CONNECTION_SSL ) );
             $mail = new ezcMail();
             $mail->from = new ezcMailAddress( '[EMAIL PROTECTED]', 'From' );
             $mail->addTo( new ezcMailAddress( '[EMAIL PROTECTED]', 'To' ) );
@@ -302,7 +516,7 @@
         }
         try
         {
-            $smtp = new ezcMailSmtpTransport( 'ezctest.ez.no', '', '', 465,
+            $smtp = new ezcMailSmtpTransport( self::HOST_SSL, '', '', 
self::PORT_SSL,
                         array( 'connectionType' => 
ezcMailSmtpTransport::CONNECTION_SSL,
                                'connectionOptions' => array( 'wrapper_name' => 
array( 'option_name' => 'value' ) ) ) );
             $mail = new ezcMail();
@@ -327,7 +541,7 @@
         }
         try
         {
-            $smtp = new ezcMailSmtpTransport( 'ezctest.ez.no', '', '', null, 
array( 'connectionType' => ezcMailSmtpTransport::CONNECTION_SSLV2 ) );
+            $smtp = new ezcMailSmtpTransport( self::HOST_SSL, '', '', null, 
array( 'connectionType' => ezcMailSmtpTransport::CONNECTION_SSLV2 ) );
             $mail = new ezcMail();
             $mail->from = new ezcMailAddress( '[EMAIL PROTECTED]', 'From' );
             $mail->addTo( new ezcMailAddress( '[EMAIL PROTECTED]', 'To' ) );
@@ -350,7 +564,7 @@
         }
         try
         {
-            $smtp = new ezcMailSmtpTransport( 'ezctest.ez.no', '', '', 465, 
array( 'connectionType' => ezcMailSmtpTransport::CONNECTION_SSLV3 ) );
+            $smtp = new ezcMailSmtpTransport( self::HOST_SSL, '', '', 
self::PORT_SSL, array( 'connectionType' => 
ezcMailSmtpTransport::CONNECTION_SSLV3 ) );
             $mail = new ezcMail();
             $mail->from = new ezcMailAddress( '[EMAIL PROTECTED]', 'From' );
             $mail->addTo( new ezcMailAddress( '[EMAIL PROTECTED]', 'To' ) );
@@ -373,7 +587,7 @@
         }
         try
         {
-            $smtp = new ezcMailSmtpTransport( 'ezctest.ez.no', '', '', null, 
array( 'connectionType' => ezcMailSmtpTransport::CONNECTION_TLS ) );
+            $smtp = new ezcMailSmtpTransport( self::HOST_SSL, '', '', null, 
array( 'connectionType' => ezcMailSmtpTransport::CONNECTION_TLS ) );
             $mail = new ezcMail();
             $mail->from = new ezcMailAddress( '[EMAIL PROTECTED]', 'From' );
             $mail->addTo( new ezcMailAddress( '[EMAIL PROTECTED]', 'To' ) );
@@ -396,7 +610,7 @@
         }
         try
         {
-            $smtp = new ezcMailSmtpTransport( 'ezctest.ez.no', '', '', 25, 
array( 'connectionType' => ezcMailSmtpTransport::CONNECTION_TLS ) );
+            $smtp = new ezcMailSmtpTransport( self::HOST_SSL, '', '', 
self::PORT, array( 'connectionType' => ezcMailSmtpTransport::CONNECTION_TLS ) );
             $mail = new ezcMail();
             $mail->from = new ezcMailAddress( '[EMAIL PROTECTED]', 'From' );
             $mail->addTo( new ezcMailAddress( '[EMAIL PROTECTED]', 'To' ) );
@@ -415,7 +629,7 @@
     {
         try
         {
-            $smtp = new ezcMailSmtpTransport( 'ezctest.ez.no', '', '', null, 
array( 'connectionType' => ezcMailSmtpTransport::CONNECTION_PLAIN ) );
+            $smtp = new ezcMailSmtpTransport( self::HOST_SSL, '', '', null, 
array( 'connectionType' => ezcMailSmtpTransport::CONNECTION_PLAIN ) );
             $mail = new ezcMail();
             $mail->from = new ezcMailAddress( '[EMAIL PROTECTED]', 'From' );
             $mail->addTo( new ezcMailAddress( '[EMAIL PROTECTED]', 'To' ) );
@@ -432,30 +646,30 @@
 
     public function testConstructorPort()
     {
-        $smtp = new ezcMailSmtpTransport( 'ezctest.ez.no', '', '', null, 
array( 'connectionType' => ezcMailSmtpTransport::CONNECTION_PLAIN ) );
+        $smtp = new ezcMailSmtpTransport( self::HOST_SSL, '', '', null, array( 
'connectionType' => ezcMailSmtpTransport::CONNECTION_PLAIN ) );
         $this->assertEquals( 25, $smtp->serverPort );
 
-        $smtp = new ezcMailSmtpTransport( 'ezctest.ez.no', '', '', null, 
array( 'connectionType' => ezcMailSmtpTransport::CONNECTION_SSL ) );
-        $this->assertEquals( 465, $smtp->serverPort );
-
-        $smtp = new ezcMailSmtpTransport( 'ezctest.ez.no', '', '', null, 
array( 'connectionType' => ezcMailSmtpTransport::CONNECTION_SSLV2 ) );
-        $this->assertEquals( 465, $smtp->serverPort );
-
-        $smtp = new ezcMailSmtpTransport( 'ezctest.ez.no', '', '', null, 
array( 'connectionType' => ezcMailSmtpTransport::CONNECTION_SSLV3 ) );
-        $this->assertEquals( 465, $smtp->serverPort );
-
-        $smtp = new ezcMailSmtpTransport( 'ezctest.ez.no', '', '', null, 
array( 'connectionType' => ezcMailSmtpTransport::CONNECTION_TLS ) );
-        $this->assertEquals( 465, $smtp->serverPort );
-
-        $smtp = new ezcMailSmtpTransport( 'ezctest.ez.no', '', '', 465, array( 
'connectionType' => ezcMailSmtpTransport::CONNECTION_PLAIN ) );
-        $this->assertEquals( 465, $smtp->serverPort );
+        $smtp = new ezcMailSmtpTransport( self::HOST_SSL, '', '', null, array( 
'connectionType' => ezcMailSmtpTransport::CONNECTION_SSL ) );
+        $this->assertEquals( self::PORT_SSL, $smtp->serverPort );
+
+        $smtp = new ezcMailSmtpTransport( self::HOST_SSL, '', '', null, array( 
'connectionType' => ezcMailSmtpTransport::CONNECTION_SSLV2 ) );
+        $this->assertEquals( self::PORT_SSL, $smtp->serverPort );
+
+        $smtp = new ezcMailSmtpTransport( self::HOST_SSL, '', '', null, array( 
'connectionType' => ezcMailSmtpTransport::CONNECTION_SSLV3 ) );
+        $this->assertEquals( self::PORT_SSL, $smtp->serverPort );
+
+        $smtp = new ezcMailSmtpTransport( self::HOST_SSL, '', '', null, array( 
'connectionType' => ezcMailSmtpTransport::CONNECTION_TLS ) );
+        $this->assertEquals( self::PORT_SSL, $smtp->serverPort );
+
+        $smtp = new ezcMailSmtpTransport( self::HOST_SSL, '', '', 
self::PORT_SSL, array( 'connectionType' => 
ezcMailSmtpTransport::CONNECTION_PLAIN ) );
+        $this->assertEquals( self::PORT_SSL, $smtp->serverPort );
     }
 
     public function testConstructorOptions()
     {
         try
         {
-            $smtp = new ezcMailSmtpTransport( 'ezctest.ez.no', '', '', 465, 
array( 'connection' => ezcMailSmtpTransport::CONNECTION_TLS ) );
+            $smtp = new ezcMailSmtpTransport( self::HOST_SSL, '', '', 
self::PORT_SSL, array( 'connection' => ezcMailSmtpTransport::CONNECTION_TLS ) );
             $this->fail( "Expected exception was not thrown" );
         }
         catch ( ezcBasePropertyNotFoundException $e )
@@ -464,10 +678,65 @@
 
         try
         {
-            $smtp = new ezcMailSmtpTransport( 'ezctest.ez.no', '', '', 465, 
array( 'connectionOptions' => 'xxx' ) );
+            $smtp = new ezcMailSmtpTransport( self::HOST_SSL, '', '', 
self::PORT_SSL, array( 'connectionOptions' => 'xxx' ) );
             $this->fail( "Expected exception was not thrown" );
         }
         catch ( ezcBaseValueException $e )
+        {
+        }
+    }
+
+    public function testTransportOptionsDefault()
+    {
+        $options = new ezcMailSmtpTransportOptions();
+        $this->assertEquals( ezcMailSmtpTransport::CONNECTION_PLAIN, 
$options->connectionType );
+        $this->assertEquals( array(), $options->connectionOptions );
+    }
+
+    public function testTransportOptionsSet()
+    {
+        $options = new ezcMailSmtpTransportOptions();
+        $options->connectionType = ezcMailSmtpTransport::CONNECTION_TLS;
+        $options->connectionOptions = array( 'wrapper' => array( 'option' => 
'value' ) );
+        $this->assertEquals( ezcMailSmtpTransport::CONNECTION_TLS, 
$options->connectionType );
+        $this->assertEquals( array( 'wrapper' => array( 'option' => 'value' ) 
), $options->connectionOptions );
+        $options->ssl = true;
+        $this->assertEquals( ezcMailSmtpTransport::CONNECTION_SSL, 
$options->connectionType );
+        $options->ssl = false;
+        $this->assertEquals( ezcMailSmtpTransport::CONNECTION_PLAIN, 
$options->connectionType );
+    }
+
+    public function testTransportOptionsSetInvalid()
+    {
+        $options = new ezcMailSmtpTransportOptions();
+        try
+        {
+            $options->connectionOptions = 'xxx';
+            $this->fail( "Expected exception was not thrown" );
+        }
+        catch ( ezcBaseValueException $e )
+        {
+        }
+
+        try
+        {
+            $options->ssl = 'xxx';
+            $this->fail( "Expected exception was not thrown" );
+        }
+        catch ( ezcBaseValueException $e )
+        {
+        }
+    }
+
+    public function testTransportOptionsSetNotExistent()
+    {
+        $options = new ezcMailSmtpTransportOptions();
+        try
+        {
+            $options->no_such_option = 'xxx';
+            $this->fail( "Expected exception was not thrown" );
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
         {
         }
     }

Added: trunk/Mail/tests/transports/wrappers/imap_wrapper.php
==============================================================================
--- trunk/Mail/tests/transports/wrappers/imap_wrapper.php (added)
+++ trunk/Mail/tests/transports/wrappers/imap_wrapper.php [iso-8859-1] Mon Jul  
2 13:22:39 2007
@@ -1,0 +1,113 @@
+<?php
+/**
+ * File containing the ezcMailImapTransportWrapper class.
+ *
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @filesource
+ * @package Mail
+ * @version //autogen//
+ * @subpackage Tests
+ */
+
+/**
+ * Class which exposes the protected methods from the IMAP transport and allows
+ * setting a custom connection, response, status and tag (in order to use mock
+ * objects).
+ *
+ * For testing purposes only.
+ *
+ * @package Mail
+ * @version //autogen//
+ * @subpackage Tests
+ * @access private
+ */
+class ezcMailImapTransportWrapper extends ezcMailImapTransport
+{
+    /**
+     * Sets the specified connection to the transport.
+     *
+     * @param ezcMailTransportConnection $connection
+     */
+    public function setConnection( ezcMailTransportConnection $connection )
+    {
+        $this->connection = $connection;
+    }
+
+    /**
+     * Reads the responses from the server until encountering $tag.
+     *
+     * In IMAP, each command sent by the client is prepended with a
+     * alphanumeric tag like 'A1234'. The server sends the response
+     * to the client command as lines, and the last line in the response
+     * is prepended with the same tag, and it contains the status of
+     * the command completion ('OK', 'NO' or 'BAD').
+     * Sometimes the server sends alerts and response lines from other
+     * commands before sending the tagged line, so this method just
+     * reads all the responses until it encounters $tag.
+     * It returns the tagged line to be processed by the calling method.
+     * If $response is specified, then it will not read the response
+     * from the server before searching for $tag in $response.
+     *
+     * This wrapper function just returns the tag and the expected response
+     * to be used in tests with a custom connection.
+     *
+     * @param string $tag
+     * @param string $response
+     * @return string
+     */
+    public function getResponse( $tag, $response = null )
+    {
+        return "{$tag} {$response}";
+    }
+
+    /**
+     * Generates the next IMAP tag to prepend to client commands.
+     *
+     * The structure of the IMAP tag is Axxxx, where
+     *  - A is a letter (uppercase for conformity)
+     *  - x is a digit from 0 to 9
+     * example of generated tag: T5439
+     * It uses the class variable [EMAIL PROTECTED] $this->currentTag}.
+     * Everytime it is called, the tag increases by 1.
+     * If it reaches the last tag, it wraps around to the first tag.
+     * By default, the first generated tag is A0001.
+     *
+     * @return string
+     */
+    public function getNextTag()
+    {
+        return parent::getNextTag();
+    }
+
+    /**
+     * Sets the current IMAP tag to the specified tag.
+     *
+     * @param string $tag
+     */
+    public function setCurrentTag( $tag )
+    {
+        $this->currentTag = $tag;
+    }
+
+    /**
+     * Returns the current state of the IMAP transport.
+     *
+     * @return int
+     */
+    public function getStatus()
+    {
+        return $this->state;
+    }
+
+    /**
+     * Sets the current state of the IMAP transport to the specified state.
+     *
+     * @param int $status
+     */
+    public function setStatus( $status )
+    {
+        $this->state = $status;
+    }
+}
+?>

Propchange: trunk/Mail/tests/transports/wrappers/imap_wrapper.php
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/Mail/tests/transports/wrappers/pop3_wrapper.php
==============================================================================
--- trunk/Mail/tests/transports/wrappers/pop3_wrapper.php (added)
+++ trunk/Mail/tests/transports/wrappers/pop3_wrapper.php [iso-8859-1] Mon Jul  
2 13:22:39 2007
@@ -1,0 +1,67 @@
+<?php
+/**
+ * File containing the ezcMailPop3TransportWrapper class.
+ *
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @filesource
+ * @package Mail
+ * @version //autogen//
+ * @subpackage Tests
+ */
+
+/**
+ * Class which exposes the protected methods from the POP3 transport and allows
+ * setting a custom connection, status and greeting (in order to use mock
+ * objects).
+ *
+ * For testing purposes only.
+ *
+ * @package Mail
+ * @version //autogen//
+ * @subpackage Tests
+ * @access private
+ */
+class ezcMailPop3TransportWrapper extends ezcMailPop3Transport
+{
+    /**
+     * Sets the specified connection to the transport.
+     *
+     * @param ezcMailTransportConnection $connection
+     */
+    public function setConnection( ezcMailTransportConnection $connection )
+    {
+        $this->connection = $connection;
+    }
+
+    /**
+     * Sets the specified greeting to the transport.
+     *
+     * @param string $greeting
+     */
+    public function setGreeting( $greeting )
+    {
+        $this->greeting = $greeting;
+    }
+
+    /**
+     * Returns the current state of the IMAP transport.
+     *
+     * @return int
+     */
+    public function getStatus()
+    {
+        return $this->state;
+    }
+
+    /**
+     * Sets the current state of the IMAP transport to the specified state.
+     *
+     * @param int $status
+     */
+    public function setStatus( $status )
+    {
+        $this->state = $status;
+    }
+}
+?>

Propchange: trunk/Mail/tests/transports/wrappers/pop3_wrapper.php
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/Mail/tests/transports/wrappers/smtp_wrapper.php
==============================================================================
--- trunk/Mail/tests/transports/wrappers/smtp_wrapper.php (added)
+++ trunk/Mail/tests/transports/wrappers/smtp_wrapper.php [iso-8859-1] Mon Jul  
2 13:22:39 2007
@@ -1,0 +1,108 @@
+<?php
+/**
+ * File containing the ezcMailSmtpTransportWrapper class.
+ *
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @filesource
+ * @package Mail
+ * @version //autogen//
+ * @subpackage Tests
+ */
+
+/**
+ * Class which exposes the protected methods from the SMTP transport and allows
+ * setting a custom status (in order to use mock objects).
+ *
+ * For testing purposes only.
+ *
+ * @package Mail
+ * @version //autogen//
+ * @subpackage Tests
+ * @access private
+ */
+class ezcMailSmtpTransportWrapper extends ezcMailSmtpTransport
+{
+    /**
+     * Performs the initial handshake with the SMTP server and
+     * authenticates the user, if login data is provided to the
+     * constructor.
+     *
+     * @throws ezcMailTransportSmtpException
+     *         if the HELO/EHLO command or authentication fails
+     */
+    public function login()
+    {
+        parent::login();
+    }
+
+    /**
+     * Sends the MAIL FROM command, with the sender's mail address $from.
+     *
+     * This method must be called once to tell the server the sender address.
+     *
+     * The sender's mail address $from may be enclosed in angle brackets.
+     *
+     * @throws ezcMailTransportSmtpException
+     *         if there is no valid connection
+     *         or if the MAIL FROM command failed
+     * @param string $from
+     */
+    public function cmdMail( $from )
+    {
+        parent::cmdMail( $from );
+    }
+
+    /**
+     * Sends the 'RCTP TO' to the server with the address $email.
+     *
+     * This method must be called once for each recipient of the mail
+     * including cc and bcc recipients. The RCPT TO commands control
+     * where the mail is actually sent. It does not affect the headers
+     * of the email.
+     *
+     * The recipient mail address $email may be enclosed in angle brackets.
+     *
+     * @throws ezcMailTransportSmtpException
+     *         if there is no valid connection
+     *         or if the RCPT TO command failed
+     * @param string $email
+     */
+    public function cmdRcpt( $email )
+    {
+        parent::cmdRcpt( $email );
+    }
+
+    /**
+     * Sends the DATA command to the SMTP server.
+     *
+     * @throws ezcMailTransportSmtpException
+     *         if there is no valid connection
+     *         or if the DATA command failed
+     */
+    public function cmdData()
+    {
+        parent::cmdData();
+    }
+
+    /**
+     * Returns the current state of the IMAP transport.
+     *
+     * @return int
+     */
+    public function getStatus()
+    {
+        return $this->status;
+    }
+
+    /**
+     * Sets the current state of the IMAP transport to the specified state.
+     *
+     * @param int $status
+     */
+    public function setStatus( $status )
+    {
+        $this->status = $status;
+    }
+}
+?>

Propchange: trunk/Mail/tests/transports/wrappers/smtp_wrapper.php
------------------------------------------------------------------------------
    svn:eol-style = native


-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to