2011-02-27 18:25:23 +00:00
< ? php
/**
* CakeEmailTest file
*
* PHP 5
*
* CakePHP ( tm ) Tests < http :// book . cakephp . org / view / 1196 / Testing >
* Copyright 2005 - 2011 , Cake Software Foundation , Inc . ( http :// cakefoundation . org )
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @ copyright Copyright 2005 - 2011 , Cake Software Foundation , Inc . ( http :// cakefoundation . org )
* @ link http :// book . cakephp . org / view / 1196 / Testing CakePHP ( tm ) Tests
* @ package cake . tests . cases . libs
* @ since CakePHP ( tm ) v 2.0 . 0
* @ license MIT License ( http :// www . opensource . org / licenses / mit - license . php )
*/
2011-04-13 03:29:34 +00:00
App :: uses ( 'CakeEmail' , 'Network' );
2011-02-27 18:25:23 +00:00
2011-03-01 22:30:01 +00:00
/**
* Help to test CakeEmail
*
*/
class TestCakeEmail extends CakeEmail {
2011-04-10 01:56:09 +00:00
/**
* Config
*
*/
protected $_config = array ();
2011-03-01 22:30:01 +00:00
/**
* Wrap to protected method
*
*/
public function formatAddress ( $address ) {
2011-03-03 16:30:23 +00:00
return parent :: _formatAddress ( $address );
}
/**
* Wrap to protected method
*
*/
public function wrap ( $text ) {
return parent :: _wrap ( $text );
2011-03-01 22:30:01 +00:00
}
2011-04-19 13:22:42 +00:00
/**
* Get the boundary attribute
*
* @ return string
*/
public function getBoundary () {
return $this -> _boundary ;
}
2011-03-01 22:30:01 +00:00
}
2011-03-04 11:06:09 +00:00
/**
* Debug transport email
*
*/
class DebugTransport extends AbstractTransport {
/**
* Last email body
*
* @ var string
*/
public static $lastEmail = '' ;
/**
* Last email header
*
* @ var string
*/
public static $lastHeader = '' ;
/**
* Include addresses in header
*
* @ var boolean
*/
public static $includeAddresses = false ;
2011-04-16 02:37:55 +00:00
/**
* Config
*
* @ var array
*/
public static $config = array ();
/**
* Config
*
* @ param mixed $config
* @ return mixed
*/
public function config ( $config ) {
self :: $config = $config ;
}
2011-03-04 11:06:09 +00:00
/**
* Send
*
* @ param object $email CakeEmail
* @ return boolean
*/
public function send ( CakeEmail $email ) {
2011-03-21 12:30:16 +00:00
self :: $lastEmail = implode ( " \r \n " , $email -> message ());
2011-03-04 11:06:09 +00:00
$options = array ();
if ( self :: $includeAddresses ) {
$options = array_fill_keys ( array ( 'from' , 'replyTo' , 'readReceipt' , 'returnPath' , 'to' , 'cc' , 'bcc' ), true );
}
self :: $lastHeader = $this -> _headersToString ( $email -> getHeaders ( $options ));
return true ;
}
}
2011-02-27 18:25:23 +00:00
/**
* CakeEmailTest class
*
* @ package cake . tests . cases . libs
*/
class CakeEmailTest extends CakeTestCase {
2011-03-01 04:31:30 +00:00
/**
* setUp
*
* @ return void
*/
public function setUp () {
parent :: setUp ();
2011-03-01 22:30:01 +00:00
$this -> CakeEmail = new TestCakeEmail ();
2011-03-04 11:29:38 +00:00
App :: build ( array (
2011-04-13 04:20:35 +00:00
'views' => array ( LIBS . 'tests' . DS . 'test_app' . DS . 'View' . DS )
2011-03-04 11:29:38 +00:00
));
}
/**
* tearDown method
*
* @ return void
*/
function tearDown () {
parent :: tearDown ();
App :: build ();
2011-03-01 04:31:30 +00:00
}
/**
* testFrom method
*
* @ return void
*/
public function testFrom () {
2011-03-21 12:18:36 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> from (), array ());
2011-03-01 04:31:30 +00:00
2011-03-21 12:18:36 +00:00
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
2011-03-01 04:31:30 +00:00
$expected = array ( 'cake@cakephp.org' => 'cake@cakephp.org' );
2011-03-21 12:18:36 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> from (), $expected );
2011-03-01 04:31:30 +00:00
2011-03-21 12:18:36 +00:00
$this -> CakeEmail -> from ( array ( 'cake@cakephp.org' ));
$this -> assertIdentical ( $this -> CakeEmail -> from (), $expected );
2011-03-01 16:50:54 +00:00
2011-03-21 12:18:36 +00:00
$this -> CakeEmail -> from ( 'cake@cakephp.org' , 'CakePHP' );
2011-03-01 04:31:30 +00:00
$expected = array ( 'cake@cakephp.org' => 'CakePHP' );
2011-03-21 12:18:36 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> from (), $expected );
2011-03-01 16:50:54 +00:00
2011-04-16 02:37:55 +00:00
$result = $this -> CakeEmail -> from ( array ( 'cake@cakephp.org' => 'CakePHP' ));
2011-03-21 12:18:36 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> from (), $expected );
2011-04-16 02:37:55 +00:00
$this -> assertIdentical ( $this -> CakeEmail , $result );
2011-03-01 04:31:30 +00:00
}
2011-03-01 05:09:05 +00:00
/**
* testTo method
*
* @ return void
*/
public function testTo () {
2011-03-21 12:18:36 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> to (), array ());
2011-03-01 05:09:05 +00:00
2011-04-16 02:37:55 +00:00
$result = $this -> CakeEmail -> to ( 'cake@cakephp.org' );
2011-03-01 05:09:05 +00:00
$expected = array ( 'cake@cakephp.org' => 'cake@cakephp.org' );
2011-03-21 12:18:36 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> to (), $expected );
2011-04-16 02:37:55 +00:00
$this -> assertIdentical ( $this -> CakeEmail , $result );
2011-03-01 05:09:05 +00:00
2011-03-21 12:18:36 +00:00
$this -> CakeEmail -> to ( 'cake@cakephp.org' , 'CakePHP' );
2011-03-01 05:09:05 +00:00
$expected = array ( 'cake@cakephp.org' => 'CakePHP' );
2011-03-21 12:18:36 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> to (), $expected );
2011-03-01 05:09:05 +00:00
$list = array (
'cake@cakephp.org' => 'Cake PHP' ,
'cake-php@googlegroups.com' => 'Cake Groups' ,
'root@cakephp.org'
);
2011-03-21 12:18:36 +00:00
$this -> CakeEmail -> to ( $list );
2011-03-01 05:09:05 +00:00
$expected = array (
'cake@cakephp.org' => 'Cake PHP' ,
'cake-php@googlegroups.com' => 'Cake Groups' ,
'root@cakephp.org' => 'root@cakephp.org'
);
2011-03-21 12:18:36 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> to (), $expected );
2011-03-01 05:09:05 +00:00
$this -> CakeEmail -> addTo ( 'jrbasso@cakephp.org' );
$this -> CakeEmail -> addTo ( 'mark_story@cakephp.org' , 'Mark Story' );
2011-04-16 02:37:55 +00:00
$result = $this -> CakeEmail -> addTo ( array ( 'phpnut@cakephp.org' => 'PhpNut' , 'jose_zap@cakephp.org' ));
2011-03-01 05:09:05 +00:00
$expected = array (
'cake@cakephp.org' => 'Cake PHP' ,
'cake-php@googlegroups.com' => 'Cake Groups' ,
'root@cakephp.org' => 'root@cakephp.org' ,
'jrbasso@cakephp.org' => 'jrbasso@cakephp.org' ,
'mark_story@cakephp.org' => 'Mark Story' ,
'phpnut@cakephp.org' => 'PhpNut' ,
'jose_zap@cakephp.org' => 'jose_zap@cakephp.org'
);
2011-03-21 12:18:36 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> to (), $expected );
2011-04-16 02:37:55 +00:00
$this -> assertIdentical ( $this -> CakeEmail , $result );
2011-03-01 05:09:05 +00:00
}
2011-03-01 22:46:20 +00:00
/**
* Data provider function for testBuildInvalidData
*
* @ return array
*/
public static function invalidEmails () {
return array (
array ( 1.0 ),
array ( '' ),
array ( 'string' ),
array ( '<tag>' ),
array ( 'some@one.whereis' ),
array ( array ( 'ok@cakephp.org' , 1.0 , '' , 'string' ))
);
}
/**
* testBuildInvalidData
*
* @ dataProvider invalidEmails
* @ expectedException SocketException
2011-03-01 23:57:45 +00:00
* @ return void
2011-03-01 22:46:20 +00:00
*/
public function testInvalidEmail ( $value ) {
2011-03-21 12:18:36 +00:00
$this -> CakeEmail -> to ( $value );
2011-03-01 22:46:20 +00:00
}
2011-03-01 22:30:01 +00:00
/**
* testFormatAddress method
*
* @ return void
*/
public function testFormatAddress () {
$result = $this -> CakeEmail -> formatAddress ( array ( 'cake@cakephp.org' => 'cake@cakephp.org' ));
$expected = array ( 'cake@cakephp.org' );
$this -> assertIdentical ( $result , $expected );
$result = $this -> CakeEmail -> formatAddress ( array ( 'cake@cakephp.org' => 'cake@cakephp.org' , 'php@cakephp.org' => 'php@cakephp.org' ));
$expected = array ( 'cake@cakephp.org' , 'php@cakephp.org' );
$this -> assertIdentical ( $result , $expected );
$result = $this -> CakeEmail -> formatAddress ( array ( 'cake@cakephp.org' => 'CakePHP' , 'php@cakephp.org' => 'Cake' ));
$expected = array ( 'CakePHP <cake@cakephp.org>' , 'Cake <php@cakephp.org>' );
$this -> assertIdentical ( $result , $expected );
$result = $this -> CakeEmail -> formatAddress ( array ( 'cake@cakephp.org' => 'ÄÖÜTest' ));
$expected = array ( '=?UTF-8?B?w4TDlsOcVGVzdA==?= <cake@cakephp.org>' );
$this -> assertIdentical ( $result , $expected );
}
2011-03-04 12:00:32 +00:00
/**
* testAddresses method
*
* @ return void
*/
public function testAddresses () {
$this -> CakeEmail -> reset ();
2011-03-21 12:18:36 +00:00
$this -> CakeEmail -> from ( 'cake@cakephp.org' , 'CakePHP' );
$this -> CakeEmail -> replyTo ( 'replyto@cakephp.org' , 'ReplyTo CakePHP' );
$this -> CakeEmail -> readReceipt ( 'readreceipt@cakephp.org' , 'ReadReceipt CakePHP' );
$this -> CakeEmail -> returnPath ( 'returnpath@cakephp.org' , 'ReturnPath CakePHP' );
$this -> CakeEmail -> to ( 'to@cakephp.org' , 'To CakePHP' );
$this -> CakeEmail -> cc ( 'cc@cakephp.org' , 'Cc CakePHP' );
$this -> CakeEmail -> bcc ( 'bcc@cakephp.org' , 'Bcc CakePHP' );
2011-03-04 12:00:32 +00:00
$this -> CakeEmail -> addTo ( 'to2@cakephp.org' , 'To2 CakePHP' );
$this -> CakeEmail -> addCc ( 'cc2@cakephp.org' , 'Cc2 CakePHP' );
$this -> CakeEmail -> addBcc ( 'bcc2@cakephp.org' , 'Bcc2 CakePHP' );
2011-03-21 12:18:36 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> from (), array ( 'cake@cakephp.org' => 'CakePHP' ));
$this -> assertIdentical ( $this -> CakeEmail -> replyTo (), array ( 'replyto@cakephp.org' => 'ReplyTo CakePHP' ));
$this -> assertIdentical ( $this -> CakeEmail -> readReceipt (), array ( 'readreceipt@cakephp.org' => 'ReadReceipt CakePHP' ));
$this -> assertIdentical ( $this -> CakeEmail -> returnPath (), array ( 'returnpath@cakephp.org' => 'ReturnPath CakePHP' ));
$this -> assertIdentical ( $this -> CakeEmail -> to (), array ( 'to@cakephp.org' => 'To CakePHP' , 'to2@cakephp.org' => 'To2 CakePHP' ));
$this -> assertIdentical ( $this -> CakeEmail -> cc (), array ( 'cc@cakephp.org' => 'Cc CakePHP' , 'cc2@cakephp.org' => 'Cc2 CakePHP' ));
$this -> assertIdentical ( $this -> CakeEmail -> bcc (), array ( 'bcc@cakephp.org' => 'Bcc CakePHP' , 'bcc2@cakephp.org' => 'Bcc2 CakePHP' ));
2011-03-04 12:00:32 +00:00
$headers = $this -> CakeEmail -> getHeaders ( array_fill_keys ( array ( 'from' , 'replyTo' , 'readReceipt' , 'returnPath' , 'to' , 'cc' , 'bcc' ), true ));
$this -> assertIdentical ( $headers [ 'From' ], 'CakePHP <cake@cakephp.org>' );
$this -> assertIdentical ( $headers [ 'Reply-To' ], 'ReplyTo CakePHP <replyto@cakephp.org>' );
$this -> assertIdentical ( $headers [ 'Disposition-Notification-To' ], 'ReadReceipt CakePHP <readreceipt@cakephp.org>' );
$this -> assertIdentical ( $headers [ 'Return-Path' ], 'ReturnPath CakePHP <returnpath@cakephp.org>' );
$this -> assertIdentical ( $headers [ 'To' ], 'To CakePHP <to@cakephp.org>, To2 CakePHP <to2@cakephp.org>' );
$this -> assertIdentical ( $headers [ 'Cc' ], 'Cc CakePHP <cc@cakephp.org>, Cc2 CakePHP <cc2@cakephp.org>' );
$this -> assertIdentical ( $headers [ 'Bcc' ], 'Bcc CakePHP <bcc@cakephp.org>, Bcc2 CakePHP <bcc2@cakephp.org>' );
}
2011-03-01 23:57:45 +00:00
/**
* testMessageId method
*
* @ return void
*/
public function testMessageId () {
2011-03-21 12:30:16 +00:00
$this -> CakeEmail -> messageId ( true );
2011-03-01 23:57:45 +00:00
$result = $this -> CakeEmail -> getHeaders ();
$this -> assertTrue ( isset ( $result [ 'Message-ID' ]));
2011-03-21 12:30:16 +00:00
$this -> CakeEmail -> messageId ( false );
2011-03-01 23:57:45 +00:00
$result = $this -> CakeEmail -> getHeaders ();
$this -> assertFalse ( isset ( $result [ 'Message-ID' ]));
2011-04-16 02:37:55 +00:00
$result = $this -> CakeEmail -> messageId ( '<my-email@localhost>' );
$this -> assertIdentical ( $this -> CakeEmail , $result );
2011-03-01 23:57:45 +00:00
$result = $this -> CakeEmail -> getHeaders ();
$this -> assertIdentical ( $result [ 'Message-ID' ], '<my-email@localhost>' );
}
/**
* testMessageIdInvalid method
*
* @ return void
* @ expectedException SocketException
*/
public function testMessageIdInvalid () {
2011-03-21 12:30:16 +00:00
$this -> CakeEmail -> messageId ( 'my-email@localhost' );
2011-03-01 23:57:45 +00:00
}
2011-03-01 17:20:13 +00:00
/**
* testSubject method
*
* @ return void
*/
public function testSubject () {
2011-03-21 12:18:36 +00:00
$this -> CakeEmail -> subject ( 'You have a new message.' );
$this -> assertIdentical ( $this -> CakeEmail -> subject (), 'You have a new message.' );
2011-03-01 17:20:13 +00:00
2011-03-21 12:18:36 +00:00
$this -> CakeEmail -> subject ( 1 );
$this -> assertIdentical ( $this -> CakeEmail -> subject (), '1' );
2011-03-01 17:20:13 +00:00
2011-04-16 02:37:55 +00:00
$result = $this -> CakeEmail -> subject ( array ( 'something' ));
2011-03-21 12:18:36 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> subject (), 'Array' );
2011-04-16 02:37:55 +00:00
$this -> assertIdentical ( $this -> CakeEmail , $result );
2011-04-17 18:00:19 +00:00
$this -> CakeEmail -> subject ( 'هذه رسالة بعنوان طويل مرسل للمستلم' );
$expected = '=?UTF-8?B?2YfYsNmHINix2LPYp9mE2Kkg2KjYudmG2YjYp9mGINi32YjZitmEINmF2LE=?=' . " \r \n " . ' =?UTF-8?B?2LPZhCDZhNmE2YXYs9iq2YTZhQ==?=' ;
$this -> assertIdentical ( $this -> CakeEmail -> subject (), $expected );
2011-03-01 17:20:13 +00:00
}
2011-02-27 18:25:23 +00:00
/**
2011-03-01 04:19:47 +00:00
* testHeaders method
2011-02-27 18:25:23 +00:00
*
* @ return void
*/
2011-03-01 04:19:47 +00:00
public function testHeaders () {
2011-03-21 12:30:16 +00:00
$this -> CakeEmail -> messageId ( false );
2011-03-01 18:16:50 +00:00
$this -> CakeEmail -> setHeaders ( array ( 'X-Something' => 'nice' ));
$expected = array (
'X-Something' => 'nice' ,
'X-Mailer' => 'CakePHP Email Component' ,
2011-03-04 02:05:30 +00:00
'Date' => date ( DATE_RFC2822 ),
'Content-Type' => 'text/plain; charset=UTF-8' ,
'Content-Transfer-Encoding' => '7bit'
2011-03-01 18:16:50 +00:00
);
$this -> assertIdentical ( $this -> CakeEmail -> getHeaders (), $expected );
$this -> CakeEmail -> addHeaders ( array ( 'X-Something' => 'very nice' , 'X-Other' => 'cool' ));
$expected = array (
'X-Something' => 'very nice' ,
'X-Other' => 'cool' ,
'X-Mailer' => 'CakePHP Email Component' ,
2011-03-04 02:05:30 +00:00
'Date' => date ( DATE_RFC2822 ),
'Content-Type' => 'text/plain; charset=UTF-8' ,
'Content-Transfer-Encoding' => '7bit'
2011-03-01 18:16:50 +00:00
);
$this -> assertIdentical ( $this -> CakeEmail -> getHeaders (), $expected );
2011-03-21 12:18:36 +00:00
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
2011-03-01 18:16:50 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> getHeaders (), $expected );
2011-03-02 00:10:34 +00:00
$expected = array (
'From' => 'cake@cakephp.org' ,
'X-Something' => 'very nice' ,
'X-Other' => 'cool' ,
'X-Mailer' => 'CakePHP Email Component' ,
2011-03-04 02:05:30 +00:00
'Date' => date ( DATE_RFC2822 ),
'Content-Type' => 'text/plain; charset=UTF-8' ,
'Content-Transfer-Encoding' => '7bit'
2011-03-02 00:10:34 +00:00
);
2011-03-01 18:16:50 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> getHeaders ( array ( 'from' => true )), $expected );
2011-03-21 12:18:36 +00:00
$this -> CakeEmail -> from ( 'cake@cakephp.org' , 'CakePHP' );
2011-03-01 18:16:50 +00:00
$expected [ 'From' ] = 'CakePHP <cake@cakephp.org>' ;
$this -> assertIdentical ( $this -> CakeEmail -> getHeaders ( array ( 'from' => true )), $expected );
2011-03-21 12:18:36 +00:00
$this -> CakeEmail -> to ( array ( 'cake@cakephp.org' , 'php@cakephp.org' => 'CakePHP' ));
2011-03-02 00:10:34 +00:00
$expected = array (
'From' => 'CakePHP <cake@cakephp.org>' ,
'To' => 'cake@cakephp.org, CakePHP <php@cakephp.org>' ,
'X-Something' => 'very nice' ,
'X-Other' => 'cool' ,
'X-Mailer' => 'CakePHP Email Component' ,
2011-03-04 02:05:30 +00:00
'Date' => date ( DATE_RFC2822 ),
'Content-Type' => 'text/plain; charset=UTF-8' ,
'Content-Transfer-Encoding' => '7bit'
2011-03-02 00:10:34 +00:00
);
2011-03-01 18:16:50 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> getHeaders ( array ( 'from' => true , 'to' => true )), $expected );
2011-02-27 18:25:23 +00:00
}
2011-03-01 21:51:12 +00:00
/**
2011-04-17 23:40:18 +00:00
* testTemplate method
*
* @ return void
*/
public function testTemplate () {
$this -> CakeEmail -> template ( 'template' , 'layout' );
$expected = array ( 'template' => 'template' , 'layout' => 'layout' );
$this -> assertIdentical ( $this -> CakeEmail -> template (), $expected );
$this -> CakeEmail -> template ( 'new_template' );
$expected = array ( 'template' => 'new_template' , 'layout' => 'layout' );
$this -> assertIdentical ( $this -> CakeEmail -> template (), $expected );
$this -> CakeEmail -> template ( 'template' , null );
$expected = array ( 'template' => 'template' , 'layout' => null );
$this -> assertIdentical ( $this -> CakeEmail -> template (), $expected );
$this -> CakeEmail -> template ( null , null );
$expected = array ( 'template' => null , 'layout' => null );
$this -> assertIdentical ( $this -> CakeEmail -> template (), $expected );
}
2011-04-18 00:57:57 +00:00
/**
* testViewVars method
*
* @ return void
*/
public function testViewVars () {
$this -> assertIdentical ( $this -> CakeEmail -> viewVars (), array ());
$this -> CakeEmail -> viewVars ( array ( 'value' => 12345 ));
$this -> assertIdentical ( $this -> CakeEmail -> viewVars (), array ( 'value' => 12345 ));
$this -> CakeEmail -> viewVars ( array ( 'name' => 'CakePHP' ));
$this -> assertIdentical ( $this -> CakeEmail -> viewVars (), array ( 'value' => 12345 , 'name' => 'CakePHP' ));
$this -> CakeEmail -> viewVars ( array ( 'value' => 4567 ));
$this -> assertIdentical ( $this -> CakeEmail -> viewVars (), array ( 'value' => 4567 , 'name' => 'CakePHP' ));
}
2011-04-17 23:40:18 +00:00
/**
* testAttachments method
2011-03-01 21:51:12 +00:00
*
* @ return void
*/
public function testAttachments () {
2011-03-21 12:30:16 +00:00
$this -> CakeEmail -> attachments ( WWW_ROOT . 'index.php' );
2011-03-04 03:20:55 +00:00
$expected = array ( 'index.php' => WWW_ROOT . 'index.php' );
2011-03-21 12:30:16 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> attachments (), $expected );
2011-03-01 21:51:12 +00:00
2011-03-21 12:30:16 +00:00
$this -> CakeEmail -> attachments ( array ());
$this -> assertIdentical ( $this -> CakeEmail -> attachments (), array ());
2011-03-01 21:51:12 +00:00
2011-03-21 12:30:16 +00:00
$this -> CakeEmail -> attachments ( WWW_ROOT . 'index.php' );
2011-03-01 21:51:12 +00:00
$this -> CakeEmail -> addAttachments ( WWW_ROOT . 'test.php' );
2011-03-04 03:20:55 +00:00
$this -> CakeEmail -> addAttachments ( array ( WWW_ROOT . 'test.php' ));
$this -> CakeEmail -> addAttachments ( array ( 'other.txt' => WWW_ROOT . 'test.php' , 'ht' => WWW_ROOT . '.htaccess' ));
$expected = array (
'index.php' => WWW_ROOT . 'index.php' ,
'test.php' => WWW_ROOT . 'test.php' ,
'other.txt' => WWW_ROOT . 'test.php' ,
'ht' => WWW_ROOT . '.htaccess'
);
2011-03-21 12:30:16 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> attachments (), $expected );
2011-03-01 21:51:12 +00:00
}
2011-04-16 02:37:55 +00:00
/**
* testTransport method
*
* @ return void
*/
public function testTransport () {
$result = $this -> CakeEmail -> transport ( 'debug' );
$this -> assertIdentical ( $this -> CakeEmail , $result );
$this -> assertIdentical ( $this -> CakeEmail -> transport (), 'debug' );
$result = $this -> CakeEmail -> transportClass ();
$this -> assertIsA ( $result , 'DebugTransport' );
}
/**
* testConfig method
*
* @ return void
*/
public function testConfig () {
$this -> CakeEmail -> transport ( 'debug' ) -> transportClass ();
DebugTransport :: $config = array ();
$config = array ( 'test' => 'ok' , 'test2' => true );
$this -> CakeEmail -> config ( $config );
$this -> assertIdentical ( DebugTransport :: $config , $config );
2011-04-17 15:53:12 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> config (), $config );
$this -> CakeEmail -> config ( array ());
$this -> assertIdentical ( DebugTransport :: $config , array ());
2011-04-16 02:37:55 +00:00
}
2011-02-27 18:25:23 +00:00
/**
2011-03-04 11:06:09 +00:00
* testSendWithContent method
2011-02-27 18:25:23 +00:00
*
* @ return void
*/
2011-03-04 11:06:09 +00:00
public function testSendWithContent () {
$this -> CakeEmail -> reset ();
2011-03-21 12:30:16 +00:00
$this -> CakeEmail -> transport ( 'debug' );
2011-03-04 11:06:09 +00:00
DebugTransport :: $includeAddresses = false ;
2011-03-21 12:18:36 +00:00
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( array ( 'you@cakephp.org' => 'You' ));
$this -> CakeEmail -> subject ( 'My title' );
2011-04-13 04:20:35 +00:00
$this -> CakeEmail -> config ( array ( 'empty' ));
2011-03-04 11:06:09 +00:00
$result = $this -> CakeEmail -> send ( " Here is my body, with multi lines. \n This is the second line. \r \n \r \n And the last. " );
$this -> assertTrue ( $result );
$expected = " Here is my body, with multi lines. \r \n This is the second line. \r \n \r \n And the last. \r \n \r \n " ;
$this -> assertIdentical ( DebugTransport :: $lastEmail , $expected );
$this -> assertTrue (( bool ) strpos ( DebugTransport :: $lastHeader , 'Date: ' ));
$this -> assertTrue (( bool ) strpos ( DebugTransport :: $lastHeader , 'Message-ID: ' ));
$this -> assertFalse ( strpos ( DebugTransport :: $lastHeader , 'To: ' ));
DebugTransport :: $includeAddresses = true ;
$this -> CakeEmail -> send ( " Other body " );
$this -> assertIdentical ( DebugTransport :: $lastEmail , " Other body \r \n \r \n " );
$this -> assertTrue (( bool ) strpos ( DebugTransport :: $lastHeader , 'Message-ID: ' ));
$this -> assertTrue (( bool ) strpos ( DebugTransport :: $lastHeader , 'To: ' ));
2011-02-27 18:25:23 +00:00
}
2011-03-04 11:29:38 +00:00
/**
* testSendRender method
*
* @ return void
*/
public function testSendRender () {
$this -> CakeEmail -> reset ();
2011-03-21 12:30:16 +00:00
$this -> CakeEmail -> transport ( 'debug' );
2011-03-04 11:29:38 +00:00
DebugTransport :: $includeAddresses = true ;
2011-03-21 12:18:36 +00:00
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( array ( 'you@cakephp.org' => 'You' ));
$this -> CakeEmail -> subject ( 'My title' );
2011-04-13 04:20:35 +00:00
$this -> CakeEmail -> config ( array ( 'empty' ));
2011-04-17 23:40:18 +00:00
$this -> CakeEmail -> template ( 'default' , 'default' );
2011-03-04 11:29:38 +00:00
$result = $this -> CakeEmail -> send ();
$this -> assertTrue (( bool ) strpos ( DebugTransport :: $lastEmail , 'This email was sent using the CakePHP Framework' ));
$this -> assertTrue (( bool ) strpos ( DebugTransport :: $lastHeader , 'Message-ID: ' ));
$this -> assertTrue (( bool ) strpos ( DebugTransport :: $lastHeader , 'To: ' ));
}
2011-04-17 21:22:20 +00:00
/**
* testSendRenderWithVars method
*
* @ return void
*/
public function testSendRenderWithVars () {
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'debug' );
DebugTransport :: $includeAddresses = true ;
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( array ( 'you@cakephp.org' => 'You' ));
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> config ( array ( 'empty' ));
2011-04-17 23:40:18 +00:00
$this -> CakeEmail -> template ( 'custom' , 'default' );
2011-04-17 21:22:20 +00:00
$this -> CakeEmail -> viewVars ( array ( 'value' => 12345 ));
$result = $this -> CakeEmail -> send ();
$this -> assertTrue (( bool ) strpos ( DebugTransport :: $lastEmail , 'Here is your value: 12345' ));
}
2011-04-19 13:22:42 +00:00
/**
* testSendMultipleMIME method
*
* @ return void
*/
public function testSendMultipleMIME () {
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'debug' );
DebugTransport :: $includeAddresses = true ;
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( array ( 'you@cakephp.org' => 'You' ));
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> template ( 'custom' , 'default' );
$this -> CakeEmail -> config ( array ());
$this -> CakeEmail -> viewVars ( array ( 'value' => 12345 ));
$this -> CakeEmail -> emailFormat ( 'both' );
$result = $this -> CakeEmail -> send ();
$message = $this -> CakeEmail -> message ();
$boundary = $this -> CakeEmail -> getBoundary ();
$this -> assertFalse ( empty ( $boundary ));
$this -> assertFalse ( in_array ( '--' . $boundary , $message ));
$this -> assertFalse ( in_array ( '--' . $boundary . '--' , $message ));
$this -> assertTrue ( in_array ( '--alt-' . $boundary , $message ));
$this -> assertTrue ( in_array ( '--alt-' . $boundary . '--' , $message ));
$this -> CakeEmail -> attachments ( array ( 'fake.php' => __FILE__ ));
$this -> CakeEmail -> send ();
$message = $this -> CakeEmail -> message ();
$boundary = $this -> CakeEmail -> getBoundary ();
$this -> assertFalse ( empty ( $boundary ));
$this -> assertTrue ( in_array ( '--' . $boundary , $message ));
$this -> assertTrue ( in_array ( '--' . $boundary . '--' , $message ));
$this -> assertTrue ( in_array ( '--alt-' . $boundary , $message ));
$this -> assertTrue ( in_array ( '--alt-' . $boundary . '--' , $message ));
}
2011-04-18 01:23:48 +00:00
/**
2011-04-19 21:07:38 +00:00
* testDeliver method
2011-04-18 01:23:48 +00:00
*
* @ return void
*/
2011-04-19 21:07:38 +00:00
public function testDeliver () {
$instance = CakeEmail :: deliver ( 'all@cakephp.org' , 'About' , 'Everything ok' , array ( 'from' => 'root@cakephp.org' ), false );
2011-04-18 01:23:48 +00:00
$this -> assertIsA ( $instance , 'CakeEmail' );
$this -> assertIdentical ( $instance -> to (), array ( 'all@cakephp.org' => 'all@cakephp.org' ));
$this -> assertIdentical ( $instance -> subject (), 'About' );
$this -> assertIdentical ( $instance -> from (), array ( 'root@cakephp.org' => 'root@cakephp.org' ));
$config = array (
'from' => 'cake@cakephp.org' ,
'to' => 'debug@cakephp.org' ,
'subject' => 'Update ok' ,
'template' => 'custom' ,
'layout' => 'custom_layout' ,
'viewVars' => array ( 'value' => 123 ),
'cc' => array ( 'cake@cakephp.org' => 'Myself' )
);
2011-04-19 21:07:38 +00:00
$instance = CakeEmail :: deliver ( null , null , array ( 'name' => 'CakePHP' ), $config , false );
2011-04-18 01:23:48 +00:00
$this -> assertIdentical ( $instance -> from (), array ( 'cake@cakephp.org' => 'cake@cakephp.org' ));
$this -> assertIdentical ( $instance -> to (), array ( 'debug@cakephp.org' => 'debug@cakephp.org' ));
$this -> assertIdentical ( $instance -> subject (), 'Update ok' );
$this -> assertIdentical ( $instance -> template (), array ( 'template' => 'custom' , 'layout' => 'custom_layout' ));
$this -> assertIdentical ( $instance -> viewVars (), array ( 'value' => 123 , 'name' => 'CakePHP' ));
$this -> assertIdentical ( $instance -> cc (), array ( 'cake@cakephp.org' => 'Myself' ));
}
2011-04-17 21:53:51 +00:00
/**
* testMessage method
*
* @ return void
*/
public function testMessage () {
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'debug' );
DebugTransport :: $includeAddresses = true ;
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( array ( 'you@cakephp.org' => 'You' ));
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> config ( array ( 'empty' ));
2011-04-17 23:40:18 +00:00
$this -> CakeEmail -> template ( 'default' , 'default' );
2011-04-17 21:53:51 +00:00
$this -> CakeEmail -> emailFormat ( 'both' );
$result = $this -> CakeEmail -> send ();
$expected = '<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>' ;
$this -> assertTrue (( bool ) strpos ( $this -> CakeEmail -> message ( CakeEmail :: MESSAGE_HTML ), $expected ));
$expected = 'This email was sent using the CakePHP Framework, http://cakephp.org.' ;
$this -> assertTrue (( bool ) strpos ( $this -> CakeEmail -> message ( CakeEmail :: MESSAGE_TEXT ), $expected ));
$message = $this -> CakeEmail -> message ();
$this -> assertTrue ( in_array ( 'Content-Type: text/plain; charset=UTF-8' , $message ));
$this -> assertTrue ( in_array ( 'Content-Type: text/html; charset=UTF-8' , $message ));
}
2011-02-27 18:25:23 +00:00
/**
* testReset method
*
* @ return void
*/
public function testReset () {
2011-03-21 12:18:36 +00:00
$this -> CakeEmail -> to ( 'cake@cakephp.org' );
$this -> assertIdentical ( $this -> CakeEmail -> to (), array ( 'cake@cakephp.org' => 'cake@cakephp.org' ));
2011-03-01 17:25:25 +00:00
$this -> CakeEmail -> reset ();
2011-03-21 12:18:36 +00:00
$this -> assertIdentical ( $this -> CakeEmail -> to (), array ());
2011-02-27 18:25:23 +00:00
}
2011-03-03 16:30:23 +00:00
/**
* testWrap method
*
* @ return void
*/
public function testWrap () {
$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac turpis orci, non commodo odio. Morbi nibh nisi, vehicula pellentesque accumsan amet.' ;
$result = $this -> CakeEmail -> wrap ( $text );
$expected = array (
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac turpis orci,' ,
'non commodo odio. Morbi nibh nisi, vehicula pellentesque accumsan amet.' ,
''
);
$this -> assertIdentical ( $result , $expected );
$text = 'Lorem ipsum dolor sit amet, consectetur < adipiscing elit. Donec ac turpis orci, non commodo odio. Morbi nibh nisi, vehicula > pellentesque accumsan amet.' ;
$result = $this -> CakeEmail -> wrap ( $text );
$expected = array (
'Lorem ipsum dolor sit amet, consectetur < adipiscing elit. Donec ac turpis' ,
'orci, non commodo odio. Morbi nibh nisi, vehicula > pellentesque accumsan' ,
'amet.' ,
''
);
$this -> assertIdentical ( $result , $expected );
$text = '<p>Lorem ipsum dolor sit amet,<br> consectetur adipiscing elit.<br> Donec ac turpis orci, non <b>commodo</b> odio. <br /> Morbi nibh nisi, vehicula pellentesque accumsan amet.<hr></p>' ;
$result = $this -> CakeEmail -> wrap ( $text );
$expected = array (
'<p>Lorem ipsum dolor sit amet,<br> consectetur adipiscing elit.<br> Donec ac' ,
'turpis orci, non <b>commodo</b> odio. <br /> Morbi nibh nisi, vehicula' ,
'pellentesque accumsan amet.<hr></p>' ,
''
);
$this -> assertIdentical ( $result , $expected );
$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac <a href="http://cakephp.org">turpis</a> orci, non commodo odio. Morbi nibh nisi, vehicula pellentesque accumsan amet.' ;
$result = $this -> CakeEmail -> wrap ( $text );
$expected = array (
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac' ,
'<a href="http://cakephp.org">turpis</a> orci, non commodo odio. Morbi nibh' ,
'nisi, vehicula pellentesque accumsan amet.' ,
''
);
$this -> assertIdentical ( $result , $expected );
2011-03-04 12:48:51 +00:00
$text = 'Lorem ipsum <a href="http://www.cakephp.org/controller/action/param1/param2" class="nice cool fine amazing awesome">ok</a>' ;
$result = $this -> CakeEmail -> wrap ( $text );
$expected = array (
'Lorem ipsum' ,
'<a href="http://www.cakephp.org/controller/action/param1/param2" class="nice cool fine amazing awesome">' ,
'ok</a>' ,
''
);
$this -> assertIdentical ( $result , $expected );
$text = 'Lorem ipsum withonewordverybigMorethanthelineshouldsizeofrfcspecificationbyieeeavailableonieeesite ok.' ;
$result = $this -> CakeEmail -> wrap ( $text );
$expected = array (
'Lorem ipsum' ,
'withonewordverybigMorethanthelineshouldsizeofrfcspecificationbyieeeavailableonieeesite' ,
'ok.' ,
''
);
$this -> assertIdentical ( $result , $expected );
2011-03-03 16:30:23 +00:00
}
2011-02-27 18:25:23 +00:00
}