public function testMsgHandleMail() { $server = new Server('', 0); $server->setLog(new Logger('test_application')); $server->init(); $client = new Client(); $client->setServer($server); $client->setId(1); $msg = $client->msgHandle('MAIL FROM:<*****@*****.**>'); $this->assertEquals('500 Syntax error, command unrecognized' . Client::MSG_SEPARATOR, $msg); $msg = $client->msgHandle('HELO localhost.localdomain'); $this->assertEquals('250 localhost.localdomain' . Client::MSG_SEPARATOR, $msg); $msg = $client->msgHandle('MAIL'); $this->assertEquals('501 Syntax error in parameters or arguments' . Client::MSG_SEPARATOR, $msg); $msg = $client->msgHandle('MAIL FROM:<*****@*****.**>'); $this->assertEquals('250 OK' . Client::MSG_SEPARATOR, $msg); $msg = $client->msgHandle('RCPT'); $this->assertEquals('501 Syntax error in parameters or arguments' . Client::MSG_SEPARATOR, $msg); $msg = $client->msgHandle('RCPT TO:<*****@*****.**>'); $this->assertEquals('250 OK' . Client::MSG_SEPARATOR, $msg); $msg = $client->msgHandle('RCPT TO:<*****@*****.**>'); $this->assertEquals('250 OK' . Client::MSG_SEPARATOR, $msg); $msg = $client->msgHandle('DATA'); $this->assertEquals('354 Start mail input; end with <CRLF>.<CRLF>' . Client::MSG_SEPARATOR, $msg); $msg = $client->msgHandle('From: TheFox <*****@*****.**>'); $this->assertEquals('', $msg); $msg = $client->msgHandle('To: TheFox <*****@*****.**>'); $this->assertEquals('', $msg); $msg = $client->msgHandle('Subject: Test'); $this->assertEquals('', $msg); $msg = $client->msgHandle(''); $this->assertEquals('', $msg); $msg = $client->msgHandle('Body'); $this->assertEquals('', $msg); $msg = $client->msgHandle('.'); $this->assertEquals('250 OK' . Client::MSG_SEPARATOR, $msg); $msg = $client->msgHandle('QUIT'); $this->assertEquals('221 localhost.localdomain Service closing transmission channel' . Client::MSG_SEPARATOR, $msg); }
public function testEvent() { $server = new Server('', 0); $server->setLog(new Logger('test_application')); $server->init(); $testData = 21; $event1 = new Event(Event::TRIGGER_MAIL_NEW, null, function ($event, $from, $rcpt, $mail) use(&$testData) { #fwrite(STDOUT, 'my function: '.$event->getTrigger().', '.$testData."\n"); $testData = 24; $this->assertEquals('*****@*****.**', $from); $this->assertEquals(array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'), $rcpt); $current = array(); foreach ($mail->getTo() as $n => $address) { $current[] = $address->toString(); } $this->assertEquals(array('Joe User <*****@*****.**>', '<*****@*****.**>'), $current); $this->assertEquals('Here is the subject', $mail->getSubject()); return 42; }); $server->eventAdd($event1); $mail = ''; $mail .= 'Date: Thu, 31 Jul 2014 22:18:51 +0200' . Client::MSG_SEPARATOR; $mail .= 'To: Joe User <*****@*****.**>, to2@example.com' . Client::MSG_SEPARATOR; $mail .= 'From: Mailer <*****@*****.**>' . Client::MSG_SEPARATOR; $mail .= 'Cc: cc@example.com' . Client::MSG_SEPARATOR; $mail .= 'Reply-To: Information <*****@*****.**>' . Client::MSG_SEPARATOR; $mail .= 'Subject: Here is the subject' . Client::MSG_SEPARATOR; $mail .= 'MIME-Version: 1.0' . Client::MSG_SEPARATOR; $mail .= 'Content-Type: text/plain; charset=iso-8859-1' . Client::MSG_SEPARATOR; $mail .= 'Content-Transfer-Encoding: 8bit' . Client::MSG_SEPARATOR; $mail .= '' . Client::MSG_SEPARATOR; $mail .= 'This is the message body.' . Client::MSG_SEPARATOR; $mail .= 'END' . Client::MSG_SEPARATOR; $zmail = Message::fromString($mail); $rcpt = array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'); $server->mailNew('*****@*****.**', $rcpt, $zmail); $this->assertEquals(24, $testData); $this->assertEquals(42, $event1->getReturnValue()); }
public function testEventAuthWithAllTrue() { $server = new Server('', 0); $server->setLog(new Logger('test_application')); $server->init(); $username = '******'; $password = '******'; $phpunit = $this; $event1 = new Event(Event::TRIGGER_AUTH_ATTEMPT, null, function ($event, $method, $credentials) { return true; }); $server->eventAdd($event1); $testObj = new TestObj(); $event2 = new Event(Event::TRIGGER_AUTH_ATTEMPT, $testObj, 'test2'); $server->eventAdd($event2); $method = 'LOGIN'; $credentials = array('user' => base64_encode($username), 'password' => base64_encode($password)); $authenticated = $server->authenticateUser($method, $credentials); $this->assertTrue($authenticated); }
public function testMsgHandleStartTls() { $server = new Server('', 0); $server->setLog(new Logger('test_application')); $server->init(); $socket = $this->getMock('TheFox\\Network\\StreamSocket', array('enableEncryption')); $socket->expects($this->at(0))->method('enableEncryption')->will($this->throwException(new RuntimeException())); $socket->expects($this->at(1))->method('enableEncryption')->will($this->returnValue(true)); $client = new Client(); $client->setServer($server); $client->setId(1); $client->setSocket($socket); $msg = $client->msgHandle('EHLO localhost.localdomain'); $expect = '250-localhost.localdomain' . Client::MSG_SEPARATOR; $expect .= '250-AUTH PLAIN LOGIN' . Client::MSG_SEPARATOR; $expect .= '250-STARTTLS' . Client::MSG_SEPARATOR; $expect .= '250 HELP' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('STARTTLS PARAMETER'); $this->assertEquals('501 Syntax error in parameters or arguments' . Client::MSG_SEPARATOR, $msg); $msg = $client->msgHandle('STARTTLS'); $this->assertEquals('454 TLS not available due to temporary reason' . Client::MSG_SEPARATOR, $msg); $msg = $client->msgHandle('STARTTLS'); $this->assertTrue($msg); }