Skip to content

Commit

Permalink
Tests to smtp auth.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Apr 13, 2011
1 parent 9296783 commit 174fae7
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cake/tests/cases/libs/email/smtp_transport.test.php
Expand Up @@ -43,6 +43,16 @@ public function setSocket(CakeSocket $socket) {
$this->_socket = $socket;
}

/**
* Helper to change the config attribute
*
* @param array config
* @return void
*/
public function setConfig($config) {
$this->_config = array_merge($this->_config, $config);
}

/**
* Disabled the socket change
*
Expand Down Expand Up @@ -139,4 +149,34 @@ public function testConnetFail() {
$this->SmtpTransport->connect();
}

/**
* testAuth method
*
* @return void
*/
public function testAuth() {
$this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n");
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("334 Login\r\n"));
$this->socket->expects($this->at(3))->method('write')->with("bWFyaw==\r\n");
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("334 Pass\r\n"));
$this->socket->expects($this->at(6))->method('write')->with("c3Rvcnk=\r\n");
$this->socket->expects($this->at(7))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(8))->method('read')->will($this->returnValue("235 OK\r\n"));
$this->SmtpTransport->setConfig(array('username' => 'mark', 'password' => 'story'));
$this->SmtpTransport->auth();
}

/**
* testAuthNoAuth method
*
* @return void
*/
public function testAuthNoAuth() {
$this->socket->expects($this->never())->method('write')->with("AUTH LOGIN\r\n");
$this->SmtpTransport->setConfig(array('username' => null, 'password' => null));
$this->SmtpTransport->auth();
}

}

0 comments on commit 174fae7

Please sign in to comment.