PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php

https://gitlab.com/fouzia23chowdhury/cakephpCRUD
PHP | 540 lines | 324 code | 47 blank | 169 comment | 0 complexity | 0d8b3f36bfaf9985aecc418bb500d043 MD5 | raw file
  1. <?php
  2. /**
  3. * SmtpTransportTest file
  4. *
  5. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  6. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7. *
  8. * Licensed under The MIT License
  9. * For full copyright and license information, please see the LICENSE.txt
  10. * Redistributions of files must retain the above copyright notice
  11. *
  12. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  13. * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
  14. * @package Cake.Test.Case.Network.Email
  15. * @since CakePHP(tm) v 2.0.0
  16. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  17. */
  18. App::uses('CakeEmail', 'Network/Email');
  19. App::uses('AbstractTransport', 'Network/Email');
  20. App::uses('SmtpTransport', 'Network/Email');
  21. /**
  22. * Help to test SmtpTransport
  23. *
  24. */
  25. class SmtpTestTransport extends SmtpTransport {
  26. /**
  27. * Helper to change the socket
  28. *
  29. * @param object $socket
  30. * @return void
  31. */
  32. public function setSocket(CakeSocket $socket) {
  33. $this->_socket = $socket;
  34. }
  35. /**
  36. * Helper to change the CakeEmail
  37. *
  38. * @param object $cakeEmail
  39. * @return void
  40. */
  41. public function setCakeEmail($cakeEmail) {
  42. $this->_cakeEmail = $cakeEmail;
  43. }
  44. /**
  45. * Disabled the socket change
  46. *
  47. * @return void
  48. */
  49. protected function _generateSocket() {
  50. }
  51. /**
  52. * Magic function to call protected methods
  53. *
  54. * @param string $method
  55. * @param string $args
  56. * @return mixed
  57. */
  58. public function __call($method, $args) {
  59. $method = '_' . $method;
  60. return call_user_func_array(array($this, $method), $args);
  61. }
  62. }
  63. /**
  64. * Test case
  65. *
  66. */
  67. class SmtpTransportTest extends CakeTestCase {
  68. /**
  69. * Setup
  70. *
  71. * @return void
  72. */
  73. public function setUp() {
  74. parent::setUp();
  75. $this->socket = $this->getMock('CakeSocket', array('read', 'write', 'connect', 'enableCrypto'));
  76. $this->SmtpTransport = new SmtpTestTransport();
  77. $this->SmtpTransport->setSocket($this->socket);
  78. $this->SmtpTransport->config(array('client' => 'localhost'));
  79. }
  80. /**
  81. * testConnectEhlo method
  82. *
  83. * @return void
  84. */
  85. public function testConnectEhlo() {
  86. $this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
  87. $this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
  88. $this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
  89. $this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
  90. $this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
  91. $this->socket->expects($this->at(4))->method('read')->will($this->returnValue("250 Accepted\r\n"));
  92. $this->SmtpTransport->connect();
  93. }
  94. /**
  95. * testConnectEhloTls method
  96. *
  97. * @return void
  98. */
  99. public function testConnectEhloTls() {
  100. $this->SmtpTransport->config(array('tls' => true));
  101. $this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
  102. $this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
  103. $this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
  104. $this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
  105. $this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
  106. $this->socket->expects($this->at(4))->method('read')->will($this->returnValue("250 Accepted\r\n"));
  107. $this->socket->expects($this->at(5))->method('write')->with("STARTTLS\r\n");
  108. $this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false));
  109. $this->socket->expects($this->at(7))->method('read')->will($this->returnValue("220 Server ready\r\n"));
  110. $this->socket->expects($this->at(8))->method('enableCrypto')->with('tls')->will($this->returnValue(true));
  111. $this->socket->expects($this->at(9))->method('write')->with("EHLO localhost\r\n");
  112. $this->socket->expects($this->at(10))->method('read')->will($this->returnValue(false));
  113. $this->socket->expects($this->at(11))->method('read')->will($this->returnValue("250 Accepted\r\n"));
  114. $this->SmtpTransport->connect();
  115. }
  116. /**
  117. * testConnectEhloTlsOnNonTlsServer method
  118. *
  119. * @expectedException SocketException
  120. * @expectedExceptionMessage SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS.
  121. * @return void
  122. */
  123. public function testConnectEhloTlsOnNonTlsServer() {
  124. $this->SmtpTransport->config(array('tls' => true));
  125. $this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
  126. $this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
  127. $this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
  128. $this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
  129. $this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
  130. $this->socket->expects($this->at(4))->method('read')->will($this->returnValue("250 Accepted\r\n"));
  131. $this->socket->expects($this->at(5))->method('write')->with("STARTTLS\r\n");
  132. $this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false));
  133. $this->socket->expects($this->at(7))->method('read')->will($this->returnValue("500 5.3.3 Unrecognized command\r\n"));
  134. $this->SmtpTransport->connect();
  135. }
  136. /**
  137. * testConnectEhloNoTlsOnRequiredTlsServer method
  138. *
  139. * @expectedException SocketException
  140. * @expectedExceptionMessage SMTP authentication method not allowed, check if SMTP server requires TLS.
  141. * @return void
  142. */
  143. public function testConnectEhloNoTlsOnRequiredTlsServer() {
  144. $this->SmtpTransport->config(array('tls' => false, 'username' => 'user', 'password' => 'pass'));
  145. $this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
  146. $this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
  147. $this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
  148. $this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
  149. $this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
  150. $this->socket->expects($this->at(4))->method('read')->will($this->returnValue("250 Accepted\r\n"));
  151. $this->socket->expects($this->at(5))->method('write')->with("AUTH LOGIN\r\n");
  152. $this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false));
  153. $this->socket->expects($this->at(7))->method('read')->will($this->returnValue("504 5.7.4 Unrecognized authentication type\r\n"));
  154. $this->SmtpTransport->connect();
  155. $this->SmtpTransport->auth();
  156. }
  157. /**
  158. * testConnectHelo method
  159. *
  160. * @return void
  161. */
  162. public function testConnectHelo() {
  163. $this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
  164. $this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
  165. $this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
  166. $this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
  167. $this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
  168. $this->socket->expects($this->at(4))->method('read')->will($this->returnValue("200 Not Accepted\r\n"));
  169. $this->socket->expects($this->at(5))->method('write')->with("HELO localhost\r\n");
  170. $this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false));
  171. $this->socket->expects($this->at(7))->method('read')->will($this->returnValue("250 Accepted\r\n"));
  172. $this->SmtpTransport->connect();
  173. }
  174. /**
  175. * testConnectFail method
  176. *
  177. * @expectedException SocketException
  178. * @expectedExceptionMessage SMTP server did not accept the connection.
  179. * @return void
  180. */
  181. public function testConnectFail() {
  182. $this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
  183. $this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
  184. $this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
  185. $this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
  186. $this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
  187. $this->socket->expects($this->at(4))->method('read')->will($this->returnValue("200 Not Accepted\r\n"));
  188. $this->socket->expects($this->at(5))->method('write')->with("HELO localhost\r\n");
  189. $this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false));
  190. $this->socket->expects($this->at(7))->method('read')->will($this->returnValue("200 Not Accepted\r\n"));
  191. $this->SmtpTransport->connect();
  192. }
  193. /**
  194. * testAuth method
  195. *
  196. * @return void
  197. */
  198. public function testAuth() {
  199. $this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n");
  200. $this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
  201. $this->socket->expects($this->at(2))->method('read')->will($this->returnValue("334 Login\r\n"));
  202. $this->socket->expects($this->at(3))->method('write')->with("bWFyaw==\r\n");
  203. $this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
  204. $this->socket->expects($this->at(5))->method('read')->will($this->returnValue("334 Pass\r\n"));
  205. $this->socket->expects($this->at(6))->method('write')->with("c3Rvcnk=\r\n");
  206. $this->socket->expects($this->at(7))->method('read')->will($this->returnValue(false));
  207. $this->socket->expects($this->at(8))->method('read')->will($this->returnValue("235 OK\r\n"));
  208. $this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story'));
  209. $this->SmtpTransport->auth();
  210. }
  211. /**
  212. * testAuthNotRecognized method
  213. *
  214. * @expectedException SocketException
  215. * @expectedExceptionMessage AUTH command not recognized or not implemented, SMTP server may not require authentication.
  216. * @return void
  217. */
  218. public function testAuthNotRecognized() {
  219. $this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n");
  220. $this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
  221. $this->socket->expects($this->at(2))->method('read')->will($this->returnValue("500 5.3.3 Unrecognized command\r\n"));
  222. $this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story'));
  223. $this->SmtpTransport->auth();
  224. }
  225. /**
  226. * testAuthNotImplemented method
  227. *
  228. * @expectedException SocketException
  229. * @expectedExceptionMessage AUTH command not recognized or not implemented, SMTP server may not require authentication.
  230. * @return void
  231. */
  232. public function testAuthNotImplemented() {
  233. $this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n");
  234. $this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
  235. $this->socket->expects($this->at(2))->method('read')->will($this->returnValue("502 5.3.3 Command not implemented\r\n"));
  236. $this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story'));
  237. $this->SmtpTransport->auth();
  238. }
  239. /**
  240. * testAuthBadSequence method
  241. *
  242. * @expectedException SocketException
  243. * @expectedExceptionMessage SMTP Error: 503 5.5.1 Already authenticated
  244. * @return void
  245. */
  246. public function testAuthBadSequence() {
  247. $this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n");
  248. $this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
  249. $this->socket->expects($this->at(2))->method('read')->will($this->returnValue("503 5.5.1 Already authenticated\r\n"));
  250. $this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story'));
  251. $this->SmtpTransport->auth();
  252. }
  253. /**
  254. * testAuthBadUsername method
  255. *
  256. * @expectedException SocketException
  257. * @expectedExceptionMessage SMTP server did not accept the username.
  258. * @return void
  259. */
  260. public function testAuthBadUsername() {
  261. $this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n");
  262. $this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
  263. $this->socket->expects($this->at(2))->method('read')->will($this->returnValue("334 Login\r\n"));
  264. $this->socket->expects($this->at(3))->method('write')->with("bWFyaw==\r\n");
  265. $this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
  266. $this->socket->expects($this->at(5))->method('read')->will($this->returnValue("535 5.7.8 Authentication failed\r\n"));
  267. $this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story'));
  268. $this->SmtpTransport->auth();
  269. }
  270. /**
  271. * testAuthBadPassword method
  272. *
  273. * @expectedException SocketException
  274. * @expectedExceptionMessage SMTP server did not accept the password.
  275. * @return void
  276. */
  277. public function testAuthBadPassword() {
  278. $this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n");
  279. $this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
  280. $this->socket->expects($this->at(2))->method('read')->will($this->returnValue("334 Login\r\n"));
  281. $this->socket->expects($this->at(3))->method('write')->with("bWFyaw==\r\n");
  282. $this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
  283. $this->socket->expects($this->at(5))->method('read')->will($this->returnValue("334 Pass\r\n"));
  284. $this->socket->expects($this->at(6))->method('write')->with("c3Rvcnk=\r\n");
  285. $this->socket->expects($this->at(7))->method('read')->will($this->returnValue(false));
  286. $this->socket->expects($this->at(8))->method('read')->will($this->returnValue("535 5.7.8 Authentication failed\r\n"));
  287. $this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story'));
  288. $this->SmtpTransport->auth();
  289. }
  290. /**
  291. * testAuthNoAuth method
  292. *
  293. * @return void
  294. */
  295. public function testAuthNoAuth() {
  296. $this->socket->expects($this->any())->method('write')->with($this->logicalNot($this->stringContains('AUTH LOGIN')));
  297. $this->SmtpTransport->config(array('username' => null, 'password' => null));
  298. $this->SmtpTransport->auth();
  299. }
  300. /**
  301. * testRcpt method
  302. *
  303. * @return void
  304. */
  305. public function testRcpt() {
  306. $email = new CakeEmail();
  307. $email->from('noreply@cakephp.org', 'CakePHP Test');
  308. $email->to('cake@cakephp.org', 'CakePHP');
  309. $email->bcc('phpnut@cakephp.org');
  310. $email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso'));
  311. $this->socket->expects($this->at(0))->method('write')->with("MAIL FROM:<noreply@cakephp.org>\r\n");
  312. $this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
  313. $this->socket->expects($this->at(2))->method('read')->will($this->returnValue("250 OK\r\n"));
  314. $this->socket->expects($this->at(3))->method('write')->with("RCPT TO:<cake@cakephp.org>\r\n");
  315. $this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
  316. $this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n"));
  317. $this->socket->expects($this->at(6))->method('write')->with("RCPT TO:<mark@cakephp.org>\r\n");
  318. $this->socket->expects($this->at(7))->method('read')->will($this->returnValue(false));
  319. $this->socket->expects($this->at(8))->method('read')->will($this->returnValue("250 OK\r\n"));
  320. $this->socket->expects($this->at(9))->method('write')->with("RCPT TO:<juan@cakephp.org>\r\n");
  321. $this->socket->expects($this->at(10))->method('read')->will($this->returnValue(false));
  322. $this->socket->expects($this->at(11))->method('read')->will($this->returnValue("250 OK\r\n"));
  323. $this->socket->expects($this->at(12))->method('write')->with("RCPT TO:<phpnut@cakephp.org>\r\n");
  324. $this->socket->expects($this->at(13))->method('read')->will($this->returnValue(false));
  325. $this->socket->expects($this->at(14))->method('read')->will($this->returnValue("250 OK\r\n"));
  326. $this->SmtpTransport->setCakeEmail($email);
  327. $this->SmtpTransport->sendRcpt();
  328. }
  329. /**
  330. * testRcptWithReturnPath method
  331. *
  332. * @return void
  333. */
  334. public function testRcptWithReturnPath() {
  335. $email = new CakeEmail();
  336. $email->from('noreply@cakephp.org', 'CakePHP Test');
  337. $email->to('cake@cakephp.org', 'CakePHP');
  338. $email->returnPath('pleasereply@cakephp.org', 'CakePHP Return');
  339. $this->socket->expects($this->at(0))->method('write')->with("MAIL FROM:<pleasereply@cakephp.org>\r\n");
  340. $this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
  341. $this->socket->expects($this->at(2))->method('read')->will($this->returnValue("250 OK\r\n"));
  342. $this->socket->expects($this->at(3))->method('write')->with("RCPT TO:<cake@cakephp.org>\r\n");
  343. $this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
  344. $this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n"));
  345. $this->SmtpTransport->setCakeEmail($email);
  346. $this->SmtpTransport->sendRcpt();
  347. }
  348. /**
  349. * testSendData method
  350. *
  351. * @return void
  352. */
  353. public function testSendData() {
  354. $email = $this->getMock('CakeEmail', array('message'), array(), 'SmtpCakeEmail');
  355. $email->from('noreply@cakephp.org', 'CakePHP Test');
  356. $email->returnPath('pleasereply@cakephp.org', 'CakePHP Return');
  357. $email->to('cake@cakephp.org', 'CakePHP');
  358. $email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso'));
  359. $email->bcc('phpnut@cakephp.org');
  360. $email->messageID('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>');
  361. $email->subject('Testing SMTP');
  362. $date = date(DATE_RFC2822);
  363. $email->setHeaders(array('X-Mailer' => SmtpCakeEmail::EMAIL_CLIENT, 'Date' => $date));
  364. $email->expects($this->once())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', '')));
  365. $data = "From: CakePHP Test <noreply@cakephp.org>\r\n";
  366. $data .= "To: CakePHP <cake@cakephp.org>\r\n";
  367. $data .= "Cc: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>\r\n";
  368. $data .= "X-Mailer: CakePHP Email\r\n";
  369. $data .= "Date: " . $date . "\r\n";
  370. $data .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>\r\n";
  371. $data .= "Subject: Testing SMTP\r\n";
  372. $data .= "MIME-Version: 1.0\r\n";
  373. $data .= "Content-Type: text/plain; charset=UTF-8\r\n";
  374. $data .= "Content-Transfer-Encoding: 8bit\r\n";
  375. $data .= "\r\n";
  376. $data .= "First Line\r\n";
  377. $data .= "Second Line\r\n";
  378. $data .= "..Third Line\r\n"; // RFC5321 4.5.2.Transparency
  379. $data .= "\r\n";
  380. $data .= "\r\n\r\n.\r\n";
  381. $this->socket->expects($this->at(0))->method('write')->with("DATA\r\n");
  382. $this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
  383. $this->socket->expects($this->at(2))->method('read')->will($this->returnValue("354 OK\r\n"));
  384. $this->socket->expects($this->at(3))->method('write')->with($data);
  385. $this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
  386. $this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n"));
  387. $this->SmtpTransport->setCakeEmail($email);
  388. $this->SmtpTransport->sendData();
  389. }
  390. /**
  391. * testQuit method
  392. *
  393. * @return void
  394. */
  395. public function testQuit() {
  396. $this->socket->expects($this->at(0))->method('write')->with("QUIT\r\n");
  397. $this->SmtpTransport->disconnect();
  398. }
  399. /**
  400. * testEmptyConfigArray method
  401. *
  402. * @return void
  403. */
  404. public function testEmptyConfigArray() {
  405. $expected = $this->SmtpTransport->config(array(
  406. 'client' => 'myhost.com',
  407. 'port' => 666
  408. ));
  409. $this->assertEquals(666, $expected['port']);
  410. $result = $this->SmtpTransport->config(array());
  411. $this->assertEquals($expected, $result);
  412. }
  413. /**
  414. * testGetLastResponse method
  415. *
  416. * @return void
  417. */
  418. public function testGetLastResponse() {
  419. $this->assertEmpty($this->SmtpTransport->getLastResponse());
  420. $this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
  421. $this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
  422. $this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
  423. $this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
  424. $this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
  425. $this->socket->expects($this->at(4))->method('read')->will($this->returnValue("250-PIPELINING\r\n"));
  426. $this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250-SIZE 102400000\r\n"));
  427. $this->socket->expects($this->at(6))->method('read')->will($this->returnValue("250-VRFY\r\n"));
  428. $this->socket->expects($this->at(7))->method('read')->will($this->returnValue("250-ETRN\r\n"));
  429. $this->socket->expects($this->at(8))->method('read')->will($this->returnValue("250-STARTTLS\r\n"));
  430. $this->socket->expects($this->at(9))->method('read')->will($this->returnValue("250-AUTH PLAIN LOGIN\r\n"));
  431. $this->socket->expects($this->at(10))->method('read')->will($this->returnValue("250-AUTH=PLAIN LOGIN\r\n"));
  432. $this->socket->expects($this->at(11))->method('read')->will($this->returnValue("250-ENHANCEDSTATUSCODES\r\n"));
  433. $this->socket->expects($this->at(12))->method('read')->will($this->returnValue("250-8BITMIME\r\n"));
  434. $this->socket->expects($this->at(13))->method('read')->will($this->returnValue("250 DSN\r\n"));
  435. $this->SmtpTransport->connect();
  436. $expected = array(
  437. array('code' => '250', 'message' => 'PIPELINING'),
  438. array('code' => '250', 'message' => 'SIZE 102400000'),
  439. array('code' => '250', 'message' => 'VRFY'),
  440. array('code' => '250', 'message' => 'ETRN'),
  441. array('code' => '250', 'message' => 'STARTTLS'),
  442. array('code' => '250', 'message' => 'AUTH PLAIN LOGIN'),
  443. array('code' => '250', 'message' => 'AUTH=PLAIN LOGIN'),
  444. array('code' => '250', 'message' => 'ENHANCEDSTATUSCODES'),
  445. array('code' => '250', 'message' => '8BITMIME'),
  446. array('code' => '250', 'message' => 'DSN')
  447. );
  448. $result = $this->SmtpTransport->getLastResponse();
  449. $this->assertEquals($expected, $result);
  450. $email = new CakeEmail();
  451. $email->from('noreply@cakephp.org', 'CakePHP Test');
  452. $email->to('cake@cakephp.org', 'CakePHP');
  453. $this->socket->expects($this->at(0))->method('write')->with("MAIL FROM:<noreply@cakephp.org>\r\n");
  454. $this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
  455. $this->socket->expects($this->at(2))->method('read')->will($this->returnValue("250 OK\r\n"));
  456. $this->socket->expects($this->at(3))->method('write')->with("RCPT TO:<cake@cakephp.org>\r\n");
  457. $this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
  458. $this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n"));
  459. $this->SmtpTransport->setCakeEmail($email);
  460. $this->SmtpTransport->sendRcpt();
  461. $expected = array(
  462. array('code' => '250', 'message' => 'OK'),
  463. );
  464. $result = $this->SmtpTransport->getLastResponse();
  465. $this->assertEquals($expected, $result);
  466. }
  467. /**
  468. * testBufferResponseLines method
  469. *
  470. * @return void
  471. */
  472. public function testBufferResponseLines() {
  473. $reponseLines = array(
  474. '123',
  475. "456\tFOO",
  476. 'FOOBAR',
  477. '250-PIPELINING',
  478. '250-ENHANCEDSTATUSCODES',
  479. '250-8BITMIME',
  480. '250 DSN',
  481. );
  482. $this->SmtpTransport->bufferResponseLines($reponseLines);
  483. $expected = array(
  484. array('code' => '123', 'message' => null),
  485. array('code' => '250', 'message' => 'PIPELINING'),
  486. array('code' => '250', 'message' => 'ENHANCEDSTATUSCODES'),
  487. array('code' => '250', 'message' => '8BITMIME'),
  488. array('code' => '250', 'message' => 'DSN')
  489. );
  490. $result = $this->SmtpTransport->getLastResponse();
  491. $this->assertEquals($expected, $result);
  492. }
  493. }