|
|
@@ -16,6 +16,7 @@ namespace Cake\Test\TestCase\Mailer\Transport;
|
|
|
|
|
|
use Cake\Mailer\Email;
|
|
|
use Cake\Mailer\Transport\SmtpTransport;
|
|
|
+use Cake\Network\Exception\SocketException;
|
|
|
use Cake\Network\Socket;
|
|
|
use Cake\TestSuite\TestCase;
|
|
|
|
|
|
@@ -124,8 +125,6 @@ class SmtpTransportTest extends TestCase
|
|
|
/**
|
|
|
* testConnectEhloTlsOnNonTlsServer method
|
|
|
*
|
|
|
- * @expectedException \Cake\Network\Exception\SocketException
|
|
|
- * @expectedExceptionMessage SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS.
|
|
|
* @return void
|
|
|
*/
|
|
|
public function testConnectEhloTlsOnNonTlsServer()
|
|
|
@@ -138,7 +137,17 @@ class SmtpTransportTest extends TestCase
|
|
|
$this->socket->expects($this->at(4))->method('write')->with("STARTTLS\r\n");
|
|
|
$this->socket->expects($this->at(5))->method('read')
|
|
|
->will($this->returnValue("500 5.3.3 Unrecognized command\r\n"));
|
|
|
- $this->SmtpTransport->connect();
|
|
|
+
|
|
|
+ $e = null;
|
|
|
+ try {
|
|
|
+ $this->SmtpTransport->connect();
|
|
|
+ } catch (SocketException $e) {
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->assertNotNull($e);
|
|
|
+ $this->assertEquals('SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS.', $e->getMessage());
|
|
|
+ $this->assertInstanceOf(SocketException::class, $e->getPrevious());
|
|
|
+ $this->assertContains('500 5.3.3 Unrecognized command', $e->getPrevious()->getMessage());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -180,8 +189,6 @@ class SmtpTransportTest extends TestCase
|
|
|
/**
|
|
|
* testConnectFail method
|
|
|
*
|
|
|
- * @expectedException \Cake\Network\Exception\SocketException
|
|
|
- * @expectedExceptionMessage SMTP server did not accept the connection.
|
|
|
* @return void
|
|
|
*/
|
|
|
public function testConnectFail()
|
|
|
@@ -192,7 +199,17 @@ class SmtpTransportTest extends TestCase
|
|
|
$this->socket->expects($this->at(3))->method('read')->will($this->returnValue("200 Not Accepted\r\n"));
|
|
|
$this->socket->expects($this->at(4))->method('write')->with("HELO localhost\r\n");
|
|
|
$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("200 Not Accepted\r\n"));
|
|
|
- $this->SmtpTransport->connect();
|
|
|
+
|
|
|
+ $e = null;
|
|
|
+ try {
|
|
|
+ $this->SmtpTransport->connect();
|
|
|
+ } catch (SocketException $e) {
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->assertNotNull($e);
|
|
|
+ $this->assertEquals('SMTP server did not accept the connection.', $e->getMessage());
|
|
|
+ $this->assertInstanceOf(SocketException::class, $e->getPrevious());
|
|
|
+ $this->assertContains('200 Not Accepted', $e->getPrevious()->getMessage());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -263,8 +280,6 @@ class SmtpTransportTest extends TestCase
|
|
|
/**
|
|
|
* testAuthBadUsername method
|
|
|
*
|
|
|
- * @expectedException \Cake\Network\Exception\SocketException
|
|
|
- * @expectedExceptionMessage SMTP server did not accept the username.
|
|
|
* @return void
|
|
|
*/
|
|
|
public function testAuthBadUsername()
|
|
|
@@ -275,14 +290,22 @@ class SmtpTransportTest extends TestCase
|
|
|
$this->socket->expects($this->at(3))->method('read')
|
|
|
->will($this->returnValue("535 5.7.8 Authentication failed\r\n"));
|
|
|
$this->SmtpTransport->config(['username' => 'mark', 'password' => 'story']);
|
|
|
- $this->SmtpTransport->auth();
|
|
|
+
|
|
|
+ $e = null;
|
|
|
+ try {
|
|
|
+ $this->SmtpTransport->auth();
|
|
|
+ } catch (SocketException $e) {
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->assertNotNull($e);
|
|
|
+ $this->assertEquals('SMTP server did not accept the username.', $e->getMessage());
|
|
|
+ $this->assertInstanceOf(SocketException::class, $e->getPrevious());
|
|
|
+ $this->assertContains('535 5.7.8 Authentication failed', $e->getPrevious()->getMessage());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* testAuthBadPassword method
|
|
|
*
|
|
|
- * @expectedException \Cake\Network\Exception\SocketException
|
|
|
- * @expectedExceptionMessage SMTP server did not accept the password.
|
|
|
* @return void
|
|
|
*/
|
|
|
public function testAuthBadPassword()
|
|
|
@@ -294,7 +317,17 @@ class SmtpTransportTest extends TestCase
|
|
|
$this->socket->expects($this->at(4))->method('write')->with("c3Rvcnk=\r\n");
|
|
|
$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("535 5.7.8 Authentication failed\r\n"));
|
|
|
$this->SmtpTransport->config(['username' => 'mark', 'password' => 'story']);
|
|
|
- $this->SmtpTransport->auth();
|
|
|
+
|
|
|
+ $e = null;
|
|
|
+ try {
|
|
|
+ $this->SmtpTransport->auth();
|
|
|
+ } catch (SocketException $e) {
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->assertNotNull($e);
|
|
|
+ $this->assertEquals('SMTP server did not accept the password.', $e->getMessage());
|
|
|
+ $this->assertInstanceOf(SocketException::class, $e->getPrevious());
|
|
|
+ $this->assertContains('535 5.7.8 Authentication failed', $e->getPrevious()->getMessage());
|
|
|
}
|
|
|
|
|
|
/**
|