2011-02-27 18:25:23 +00:00
< ? php
/**
* CakeEmailTest file
*
2012-04-27 02:49:18 +00:00
* CakePHP ( tm ) Tests < http :// book . cakephp . org / 2.0 / en / development / testing . html >
2013-02-08 11:59:49 +00:00
* Copyright ( c ) Cake Software Foundation , Inc . ( http :// cakefoundation . org )
2011-02-27 18:25:23 +00:00
*
* Licensed under The MIT License
2013-02-08 12:22:51 +00:00
* For full copyright and license information , please see the LICENSE . txt
2011-02-27 18:25:23 +00:00
* Redistributions of files must retain the above copyright notice
*
2013-02-08 11:59:49 +00:00
* @ copyright Copyright ( c ) Cake Software Foundation , Inc . ( http :// cakefoundation . org )
2012-04-27 02:49:18 +00:00
* @ link http :// book . cakephp . org / 2.0 / en / development / testing . html CakePHP ( tm ) Tests
2011-07-26 06:16:14 +00:00
* @ package Cake . Test . Case . Network . Email
2011-02-27 18:25:23 +00:00
* @ since CakePHP ( tm ) v 2.0 . 0
2013-05-30 22:11:14 +00:00
* @ license http :// www . opensource . org / licenses / mit - license . php MIT License
2011-02-27 18:25:23 +00:00
*/
2013-05-30 22:11:14 +00:00
2011-04-27 02:19:17 +00:00
App :: uses ( 'CakeEmail' , 'Network/Email' );
2011-02-27 18:25:23 +00:00
2011-03-01 22:30:01 +00:00
/**
* Help to test CakeEmail
*
*/
class TestCakeEmail extends CakeEmail {
2013-09-28 02:22:23 +00:00
/**
2013-10-23 02:59:50 +00:00
* Config class name .
2013-09-28 02:22:23 +00:00
*
* Use a the testing config class in this file .
*
* @ var string
*/
protected $_configClass = 'TestEmailConfig' ;
2011-04-10 01:56:09 +00:00
/**
* Config
*
*/
protected $_config = array ();
2011-03-01 22:30:01 +00:00
/**
* Wrap to protected method
*
2014-04-02 01:02:37 +00:00
* @ return array
2011-03-01 22:30:01 +00:00
*/
public function formatAddress ( $address ) {
2011-03-03 16:30:23 +00:00
return parent :: _formatAddress ( $address );
}
/**
* Wrap to protected method
*
2014-04-02 01:02:37 +00:00
* @ return array
2011-03-03 16:30:23 +00:00
*/
2012-12-18 01:54:38 +00:00
public function wrap ( $text , $length = CakeEmail :: LINE_LENGTH_MUST ) {
return parent :: _wrap ( $text , $length );
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-10-19 15:18:42 +00:00
/**
* Encode to protected method
*
2014-04-02 01:02:37 +00:00
* @ return string
2011-10-19 15:18:42 +00:00
*/
public function encode ( $text ) {
return $this -> _encode ( $text );
}
2012-03-17 02:19:01 +00:00
2013-06-29 13:16:58 +00:00
/**
* Render to protected method
*
2014-04-02 01:02:37 +00:00
* @ return array
2013-06-29 13:16:58 +00:00
*/
public function render ( $content ) {
return $this -> _render ( $content );
}
2011-03-01 22:30:01 +00:00
}
2014-04-02 01:02:37 +00:00
/**
2011-08-29 01:11:30 +00:00
* EmailConfig class
2011-03-04 11:06:09 +00:00
*
*/
2013-09-28 02:22:23 +00:00
class TestEmailConfig {
2011-03-04 11:06:09 +00:00
/**
2011-08-29 01:11:30 +00:00
* test config
2011-03-04 11:06:09 +00:00
*
2014-04-02 01:02:37 +00:00
* @ var array
2011-03-04 11:06:09 +00:00
*/
2011-08-29 01:11:30 +00:00
public $test = array (
'from' => array ( 'some@example.com' => 'My website' ),
'to' => array ( 'test@example.com' => 'Testname' ),
'subject' => 'Test mail subject' ,
'transport' => 'Debug' ,
2012-03-28 05:22:55 +00:00
'theme' => 'TestTheme' ,
2012-06-23 01:44:37 +00:00
'helpers' => array ( 'Html' , 'Form' ),
2011-08-29 01:11:30 +00:00
);
2011-03-04 11:06:09 +00:00
2013-08-13 08:42:52 +00:00
/**
* test config 2
*
2014-04-02 01:02:37 +00:00
* @ var array
2013-08-13 08:42:52 +00:00
*/
public $test2 = array (
'from' => array ( 'some@example.com' => 'My website' ),
'to' => array ( 'test@example.com' => 'Testname' ),
'subject' => 'Test mail subject' ,
'transport' => 'Smtp' ,
'host' => 'cakephp.org' ,
'timeout' => 60
);
2011-03-04 11:06:09 +00:00
}
2014-04-02 01:02:37 +00:00
/**
2011-08-29 14:02:00 +00:00
* ExtendTransport class
* test class to ensure the class has send () method
*
*/
class ExtendTransport {
}
2011-02-27 18:25:23 +00:00
/**
* CakeEmailTest class
*
2011-07-26 06:16:14 +00:00
* @ package Cake . Test . Case . Network . Email
2011-02-27 18:25:23 +00:00
*/
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 (
2012-03-17 02:19:01 +00:00
'View' => array ( CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS )
2011-03-04 11:29:38 +00:00
));
}
/**
* tearDown method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function tearDown () {
2011-03-04 11:29:38 +00:00
parent :: tearDown ();
App :: build ();
2011-03-01 04:31:30 +00:00
}
/**
* testFrom method
*
* @ return void
*/
public function testFrom () {
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $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-11-16 00:07:56 +00:00
$this -> assertSame ( $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' ));
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $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-11-16 00:07:56 +00:00
$this -> assertSame ( $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-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> from (), $expected );
$this -> assertSame ( $this -> CakeEmail , $result );
2011-08-29 14:02:00 +00:00
$this -> setExpectedException ( 'SocketException' );
$result = $this -> CakeEmail -> from ( array ( 'cake@cakephp.org' => 'CakePHP' , 'fail@cakephp.org' => 'From can only be one address' ));
2011-03-01 04:31:30 +00:00
}
2013-09-13 00:14:11 +00:00
/**
* Test that from addresses using colons work .
*
* @ return void
*/
public function testFromWithColonsAndQuotes () {
$address = array (
'info@example.com' => '70:20:00 " Forum'
);
$this -> CakeEmail -> from ( $address );
$this -> assertEquals ( $address , $this -> CakeEmail -> from ());
$this -> CakeEmail -> to ( 'info@example.com' )
-> subject ( 'Test email' )
-> transport ( 'Debug' );
$result = $this -> CakeEmail -> send ();
$this -> assertContains ( 'From: "70:20:00 \" Forum" <info@example.com>' , $result [ 'headers' ]);
}
2011-04-20 00:18:02 +00:00
/**
* testSender method
*
* @ return void
*/
public function testSender () {
$this -> CakeEmail -> reset ();
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> sender (), array ());
2011-04-20 00:18:02 +00:00
$this -> CakeEmail -> sender ( 'cake@cakephp.org' , 'Name' );
$expected = array ( 'cake@cakephp.org' => 'Name' );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> sender (), $expected );
2011-04-20 00:18:02 +00:00
$headers = $this -> CakeEmail -> getHeaders ( array ( 'from' => true , 'sender' => true ));
2013-09-18 22:17:21 +00:00
$this -> assertFalse ( $headers [ 'From' ]);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $headers [ 'Sender' ], 'Name <cake@cakephp.org>' );
2011-04-20 00:18:02 +00:00
$this -> CakeEmail -> from ( 'cake@cakephp.org' , 'CakePHP' );
$headers = $this -> CakeEmail -> getHeaders ( array ( 'from' => true , 'sender' => true ));
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $headers [ 'From' ], 'CakePHP <cake@cakephp.org>' );
$this -> assertSame ( $headers [ 'Sender' ], '' );
2011-04-20 00:18:02 +00:00
}
2011-03-01 05:09:05 +00:00
/**
* testTo method
*
* @ return void
*/
public function testTo () {
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $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-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> to (), $expected );
$this -> assertSame ( $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-11-16 00:07:56 +00:00
$this -> assertSame ( $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-11-16 00:07:56 +00:00
$this -> assertSame ( $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-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> to (), $expected );
$this -> assertSame ( $this -> CakeEmail , $result );
2013-12-17 18:29:08 +00:00
$this -> setExpectedException ( 'SocketException' );
$this -> CakeEmail -> to ( array ( 'cake@localhost' , 'CakePHP' ));
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>' ),
2012-12-01 23:34:26 +00:00
array ( 'some@one-whereis' ),
2011-08-29 14:02:00 +00:00
array ( 'wrong@key' => 'Name' ),
2011-03-01 22:46:20 +00:00
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-08-29 14:02:00 +00:00
/**
* testBuildInvalidData
*
* @ dataProvider invalidEmails
* @ expectedException SocketException
* @ return void
*/
public function testInvalidEmailAdd ( $value ) {
$this -> CakeEmail -> addTo ( $value );
}
2013-06-28 17:44:55 +00:00
/**
2013-06-30 15:03:18 +00:00
* test emailPattern method
2013-06-28 17:44:55 +00:00
*
* @ return void
*/
2013-06-30 15:03:18 +00:00
public function testEmailPattern () {
2013-06-28 17:44:55 +00:00
$regex = '/.+@.+\..+/i' ;
2013-06-30 15:03:18 +00:00
$this -> assertNull ( $this -> CakeEmail -> emailPattern ());
$this -> assertSame ( $regex , $this -> CakeEmail -> emailPattern ( $regex ) -> emailPattern ());
2013-06-28 17:44:55 +00:00
}
/**
* Tests that it is possible to set email regex configuration to a CakeEmail object
*
* @ return void
*/
2013-06-30 15:03:18 +00:00
public function testConfigEmailPattern () {
2013-06-28 17:44:55 +00:00
$regex = '/.+@.+\..+/i' ;
2013-06-30 15:03:18 +00:00
$email = new CakeEmail ( array ( 'emailPattern' => $regex ));
$this -> assertSame ( $regex , $email -> emailPattern ());
2013-06-28 17:44:55 +00:00
}
2013-06-28 17:55:16 +00:00
/**
* Tests that it is possible set custom email validation
2014-04-02 01:02:37 +00:00
*
* @ return void
2013-06-28 17:55:16 +00:00
*/
public function testCustomEmailValidation () {
$regex = '/^[\.a-z0-9!#$%&\'*+\/=?^_`{|}~-]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]{2,6}$/i' ;
2013-06-30 15:03:18 +00:00
$this -> CakeEmail -> emailPattern ( $regex ) -> to ( 'pass.@example.com' );
2013-06-28 17:55:16 +00:00
$this -> assertSame ( array (
'pass.@example.com' => 'pass.@example.com' ,
), $this -> CakeEmail -> to ());
$this -> CakeEmail -> addTo ( 'pass..old.docomo@example.com' );
$this -> assertSame ( array (
'pass.@example.com' => 'pass.@example.com' ,
'pass..old.docomo@example.com' => 'pass..old.docomo@example.com' ,
), $this -> CakeEmail -> to ());
$this -> CakeEmail -> reset ();
$emails = array (
'pass.@example.com' ,
'pass..old.docomo@example.com'
);
$additionalEmails = array (
'.extend.@example.com' ,
'.docomo@example.com'
);
2013-06-30 15:03:18 +00:00
$this -> CakeEmail -> emailPattern ( $regex ) -> to ( $emails );
2013-06-28 17:55:16 +00:00
$this -> assertSame ( array (
'pass.@example.com' => 'pass.@example.com' ,
'pass..old.docomo@example.com' => 'pass..old.docomo@example.com' ,
), $this -> CakeEmail -> to ());
$this -> CakeEmail -> addTo ( $additionalEmails );
$this -> assertSame ( array (
'pass.@example.com' => 'pass.@example.com' ,
'pass..old.docomo@example.com' => 'pass..old.docomo@example.com' ,
'.extend.@example.com' => '.extend.@example.com' ,
'.docomo@example.com' => '.docomo@example.com' ,
), $this -> CakeEmail -> to ());
}
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' );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $expected , $result );
2011-03-01 22:30:01 +00:00
$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' );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $expected , $result );
2011-03-01 22:30:01 +00:00
$result = $this -> CakeEmail -> formatAddress ( array ( 'cake@cakephp.org' => 'CakePHP' , 'php@cakephp.org' => 'Cake' ));
$expected = array ( 'CakePHP <cake@cakephp.org>' , 'Cake <php@cakephp.org>' );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $expected , $result );
2011-03-01 22:30:01 +00:00
2012-01-26 02:03:03 +00:00
$result = $this -> CakeEmail -> formatAddress ( array ( 'me@example.com' => 'Last, First' ));
$expected = array ( '"Last, First" <me@example.com>' );
$this -> assertSame ( $expected , $result );
2013-09-13 00:14:11 +00:00
$result = $this -> CakeEmail -> formatAddress ( array ( 'me@example.com' => '"Last" First' ));
$expected = array ( '"\"Last\" First" <me@example.com>' );
$this -> assertSame ( $expected , $result );
2012-01-26 02:03:03 +00:00
$result = $this -> CakeEmail -> formatAddress ( array ( 'me@example.com' => 'Last First' ));
$expected = array ( 'Last First <me@example.com>' );
$this -> assertSame ( $expected , $result );
2011-03-01 22:30:01 +00:00
$result = $this -> CakeEmail -> formatAddress ( array ( 'cake@cakephp.org' => 'ÄÖÜTest' ));
$expected = array ( '=?UTF-8?B?w4TDlsOcVGVzdA==?= <cake@cakephp.org>' );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $expected , $result );
2011-10-19 15:18:42 +00:00
2011-10-19 04:32:20 +00:00
$result = $this -> CakeEmail -> formatAddress ( array ( 'cake@cakephp.org' => '日本語Test' ));
$expected = array ( '=?UTF-8?B?5pel5pys6KqeVGVzdA==?= <cake@cakephp.org>' );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $expected , $result );
2011-10-19 04:32:20 +00:00
}
/**
* testFormatAddressJapanese
*
* @ return void
*/
public function testFormatAddressJapanese () {
$this -> skipIf ( ! function_exists ( 'mb_convert_encoding' ));
2011-10-19 15:18:42 +00:00
$this -> CakeEmail -> headerCharset = 'ISO-2022-JP' ;
2011-10-19 04:32:20 +00:00
$result = $this -> CakeEmail -> formatAddress ( array ( 'cake@cakephp.org' => '日本語Test' ));
$expected = array ( '=?ISO-2022-JP?B?GyRCRnxLXDhsGyhCVGVzdA==?= <cake@cakephp.org>' );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $expected , $result );
2011-10-19 15:18:42 +00:00
$result = $this -> CakeEmail -> formatAddress ( array ( 'cake@cakephp.org' => '寿限無寿限無五劫の擦り切れ海砂利水魚の水行末雲来末風来末食う寝る処に住む処やぶら小路の藪柑子パイポパイポパイポのシューリンガンシューリンガンのグーリンダイグーリンダイのポンポコピーのポンポコナーの長久命の長助' ));
2012-03-17 02:19:01 +00:00
$expected = array ( " =?ISO-2022-JP?B?GyRCPHc4Qkw1PHc4Qkw1OF45ZSROOyQkakBaJGwzJDo9TXg/ZTV7GyhC?= \r \n " .
" =?ISO-2022-JP?B?GyRCJE4/ZTlUS3YxQE1oS3ZJd01oS3Y/KSQmPzIkaz1oJEs9OyRgGyhC?= \r \n " .
" =?ISO-2022-JP?B?GyRCPWgkZCRWJGk+Lk8pJE5pLjQ7O1IlUSUkJV0lUSUkJV0lUSUkGyhC?= \r \n " .
" =?ISO-2022-JP?B?GyRCJV0kTiU3JWUhPCVqJXMlLCVzJTclZSE8JWolcyUsJXMkTiUwGyhC?= \r \n " .
" =?ISO-2022-JP?B?GyRCITwlaiVzJUAlJCUwITwlaiVzJUAlJCROJV0lcyVdJTMlVCE8GyhC?= \r \n " .
" =?ISO-2022-JP?B?GyRCJE4lXSVzJV0lMyVKITwkTkQ5NVdMPyRORDk9dRsoQg==?= <cake@cakephp.org> " );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $expected , $result );
2011-03-01 22:30:01 +00:00
}
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' );
2013-11-22 18:14:21 +00:00
$this -> CakeEmail -> to ( 'to@cakephp.org' , 'To, CakePHP' );
2011-03-21 12:18:36 +00:00
$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-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> from (), array ( 'cake@cakephp.org' => 'CakePHP' ));
$this -> assertSame ( $this -> CakeEmail -> replyTo (), array ( 'replyto@cakephp.org' => 'ReplyTo CakePHP' ));
$this -> assertSame ( $this -> CakeEmail -> readReceipt (), array ( 'readreceipt@cakephp.org' => 'ReadReceipt CakePHP' ));
$this -> assertSame ( $this -> CakeEmail -> returnPath (), array ( 'returnpath@cakephp.org' => 'ReturnPath CakePHP' ));
2013-11-22 18:14:21 +00:00
$this -> assertSame ( $this -> CakeEmail -> to (), array ( 'to@cakephp.org' => 'To, CakePHP' , 'to2@cakephp.org' => 'To2 CakePHP' ));
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> cc (), array ( 'cc@cakephp.org' => 'Cc CakePHP' , 'cc2@cakephp.org' => 'Cc2 CakePHP' ));
$this -> assertSame ( $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 ));
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $headers [ 'From' ], 'CakePHP <cake@cakephp.org>' );
$this -> assertSame ( $headers [ 'Reply-To' ], 'ReplyTo CakePHP <replyto@cakephp.org>' );
$this -> assertSame ( $headers [ 'Disposition-Notification-To' ], 'ReadReceipt CakePHP <readreceipt@cakephp.org>' );
$this -> assertSame ( $headers [ 'Return-Path' ], 'ReturnPath CakePHP <returnpath@cakephp.org>' );
2013-11-22 18:14:21 +00:00
$this -> assertSame ( $headers [ 'To' ], '"To, CakePHP" <to@cakephp.org>, To2 CakePHP <to2@cakephp.org>' );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $headers [ 'Cc' ], 'Cc CakePHP <cc@cakephp.org>, Cc2 CakePHP <cc2@cakephp.org>' );
$this -> assertSame ( $headers [ 'Bcc' ], 'Bcc CakePHP <bcc@cakephp.org>, Bcc2 CakePHP <bcc2@cakephp.org>' );
2011-03-04 12:00:32 +00:00
}
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>' );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail , $result );
2011-03-01 23:57:45 +00:00
$result = $this -> CakeEmail -> getHeaders ();
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $result [ 'Message-ID' ], '<my-email@localhost>' );
2011-08-29 14:02:00 +00:00
$result = $this -> CakeEmail -> messageId ();
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $result , '<my-email@localhost>' );
2011-03-01 23:57:45 +00:00
}
/**
* 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
}
2012-04-20 01:38:26 +00:00
/**
* testDomain method
*
* @ return void
*/
public function testDomain () {
$result = $this -> CakeEmail -> domain ();
$expected = env ( 'HTTP_HOST' ) ? env ( 'HTTP_HOST' ) : php_uname ( 'n' );
$this -> assertSame ( $expected , $result );
2012-04-21 00:52:10 +00:00
2012-04-20 01:38:26 +00:00
$this -> CakeEmail -> domain ( 'example.org' );
$result = $this -> CakeEmail -> domain ();
$expected = 'example.org' ;
$this -> assertSame ( $expected , $result );
}
/**
* testMessageIdWithDomain method
*
* @ return void
2012-04-21 00:52:10 +00:00
*/
2012-04-20 01:38:26 +00:00
public function testMessageIdWithDomain () {
$this -> CakeEmail -> domain ( 'example.org' );
$result = $this -> CakeEmail -> getHeaders ();
$expected = '@example.org>' ;
$this -> assertTextContains ( $expected , $result [ 'Message-ID' ]);
2012-09-29 01:20:14 +00:00
$_SERVER [ 'HTTP_HOST' ] = 'example.org' ;
$result = $this -> CakeEmail -> getHeaders ();
$this -> assertTextContains ( 'example.org' , $result [ 'Message-ID' ]);
$_SERVER [ 'HTTP_HOST' ] = 'example.org:81' ;
$result = $this -> CakeEmail -> getHeaders ();
$this -> assertTextNotContains ( ':81' , $result [ 'Message-ID' ]);
2012-04-20 01:38:26 +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.' );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> subject (), 'You have a new message.' );
2011-03-01 17:20:13 +00:00
2012-02-11 15:15:53 +00:00
$this -> CakeEmail -> subject ( 'You have a new message, I think.' );
$this -> assertSame ( $this -> CakeEmail -> subject (), 'You have a new message, I think.' );
2011-03-21 12:18:36 +00:00
$this -> CakeEmail -> subject ( 1 );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> subject (), '1' );
2011-03-01 17:20:13 +00:00
2011-04-17 18:00:19 +00:00
$this -> CakeEmail -> subject ( 'هذه رسالة بعنوان طويل مرسل للمستلم' );
$expected = '=?UTF-8?B?2YfYsNmHINix2LPYp9mE2Kkg2KjYudmG2YjYp9mGINi32YjZitmEINmF2LE=?=' . " \r \n " . ' =?UTF-8?B?2LPZhCDZhNmE2YXYs9iq2YTZhQ==?=' ;
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> subject (), $expected );
2011-03-01 17:20:13 +00:00
}
2011-10-19 15:18:42 +00:00
/**
* testSubjectJapanese
*
* @ return void
*/
public function testSubjectJapanese () {
$this -> skipIf ( ! function_exists ( 'mb_convert_encoding' ));
2011-12-16 06:52:07 +00:00
mb_internal_encoding ( 'UTF-8' );
2011-10-19 15:18:42 +00:00
2011-12-16 06:52:07 +00:00
$this -> CakeEmail -> headerCharset = 'ISO-2022-JP' ;
2011-10-19 15:18:42 +00:00
$this -> CakeEmail -> subject ( '日本語のSubjectにも対応するよ' );
2011-12-16 06:52:07 +00:00
$expected = '=?ISO-2022-JP?B?GyRCRnxLXDhsJE4bKEJTdWJqZWN0GyRCJEskYkJQMX4kOSRrJGgbKEI=?=' ;
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> subject (), $expected );
2011-10-19 15:18:42 +00:00
$this -> CakeEmail -> subject ( '長い長い長いSubjectの場合はfoldingするのが正しいんだけどいったいどうなるんだろう? ' );
2012-03-17 02:19:01 +00:00
$expected = " =?ISO-2022-JP?B?GyRCRDkkJEQ5JCREOSQkGyhCU3ViamVjdBskQiROPmw5ZyRPGyhCZm9s?= \r \n " .
" =?ISO-2022-JP?B?ZGluZxskQiQ5JGskTiQsQDUkNyQkJHMkQCQxJEkkJCRDJD8kJCRJGyhC?= \r \n " .
" =?ISO-2022-JP?B?GyRCJCYkSiRrJHMkQCRtJCYhKRsoQg==?= " ;
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> subject (), $expected );
2011-12-16 06:52:07 +00:00
}
2011-10-19 15:18:42 +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' ,
2011-04-23 02:41:52 +00:00
'X-Mailer' => 'CakePHP Email' ,
2011-03-04 02:05:30 +00:00
'Date' => date ( DATE_RFC2822 ),
2011-04-20 01:47:48 +00:00
'MIME-Version' => '1.0' ,
2011-03-04 02:05:30 +00:00
'Content-Type' => 'text/plain; charset=UTF-8' ,
2011-10-19 04:20:09 +00:00
'Content-Transfer-Encoding' => '8bit'
2011-03-01 18:16:50 +00:00
);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> getHeaders (), $expected );
2011-03-01 18:16:50 +00:00
$this -> CakeEmail -> addHeaders ( array ( 'X-Something' => 'very nice' , 'X-Other' => 'cool' ));
$expected = array (
'X-Something' => 'very nice' ,
'X-Other' => 'cool' ,
2011-04-23 02:41:52 +00:00
'X-Mailer' => 'CakePHP Email' ,
2011-03-04 02:05:30 +00:00
'Date' => date ( DATE_RFC2822 ),
2011-04-20 01:47:48 +00:00
'MIME-Version' => '1.0' ,
2011-03-04 02:05:30 +00:00
'Content-Type' => 'text/plain; charset=UTF-8' ,
2011-10-19 04:20:09 +00:00
'Content-Transfer-Encoding' => '8bit'
2011-03-01 18:16:50 +00:00
);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> getHeaders (), $expected );
2011-03-01 18:16:50 +00:00
2011-03-21 12:18:36 +00:00
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> getHeaders (), $expected );
2011-03-01 18:16:50 +00:00
2011-03-02 00:10:34 +00:00
$expected = array (
'From' => 'cake@cakephp.org' ,
'X-Something' => 'very nice' ,
'X-Other' => 'cool' ,
2011-04-23 02:41:52 +00:00
'X-Mailer' => 'CakePHP Email' ,
2011-03-04 02:05:30 +00:00
'Date' => date ( DATE_RFC2822 ),
2011-04-20 01:47:48 +00:00
'MIME-Version' => '1.0' ,
2011-03-04 02:05:30 +00:00
'Content-Type' => 'text/plain; charset=UTF-8' ,
2011-10-19 04:20:09 +00:00
'Content-Transfer-Encoding' => '8bit'
2011-03-02 00:10:34 +00:00
);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> getHeaders ( array ( 'from' => true )), $expected );
2011-03-01 18:16:50 +00:00
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>' ;
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> getHeaders ( array ( 'from' => true )), $expected );
2011-03-01 18:16:50 +00:00
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' ,
2011-04-23 02:41:52 +00:00
'X-Mailer' => 'CakePHP Email' ,
2011-03-04 02:05:30 +00:00
'Date' => date ( DATE_RFC2822 ),
2011-04-20 01:47:48 +00:00
'MIME-Version' => '1.0' ,
2011-03-04 02:05:30 +00:00
'Content-Type' => 'text/plain; charset=UTF-8' ,
2011-10-19 04:20:09 +00:00
'Content-Transfer-Encoding' => '8bit'
2011-03-02 00:10:34 +00:00
);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> getHeaders ( array ( 'from' => true , 'to' => true )), $expected );
2011-08-29 14:02:00 +00:00
2011-10-19 15:18:42 +00:00
$this -> CakeEmail -> charset = 'ISO-2022-JP' ;
$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' ,
'Date' => date ( DATE_RFC2822 ),
'MIME-Version' => '1.0' ,
'Content-Type' => 'text/plain; charset=ISO-2022-JP' ,
'Content-Transfer-Encoding' => '7bit'
);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> getHeaders ( array ( 'from' => true , 'to' => true )), $expected );
2011-10-19 15:18:42 +00:00
2011-08-29 14:02:00 +00:00
$result = $this -> CakeEmail -> setHeaders ( array ());
2011-11-16 17:56:34 +00:00
$this -> assertInstanceOf ( 'CakeEmail' , $result );
2011-08-29 14:02:00 +00:00
}
/**
* Data provider function for testInvalidHeaders
*
* @ return array
*/
public static function invalidHeaders () {
return array (
array ( 10 ),
array ( '' ),
array ( 'string' ),
array ( false ),
array ( null )
);
}
/**
* testInvalidHeaders
*
* @ dataProvider invalidHeaders
* @ expectedException SocketException
* @ return void
*/
public function testInvalidHeaders ( $value ) {
$this -> CakeEmail -> setHeaders ( $value );
}
/**
* testInvalidAddHeaders
*
* @ dataProvider invalidHeaders
* @ expectedException SocketException
* @ return void
*/
public function testInvalidAddHeaders ( $value ) {
$this -> CakeEmail -> addHeaders ( $value );
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' );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> template (), $expected );
2011-04-17 23:40:18 +00:00
$this -> CakeEmail -> template ( 'new_template' );
$expected = array ( 'template' => 'new_template' , 'layout' => 'layout' );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> template (), $expected );
2011-04-17 23:40:18 +00:00
$this -> CakeEmail -> template ( 'template' , null );
$expected = array ( 'template' => 'template' , 'layout' => null );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> template (), $expected );
2011-04-17 23:40:18 +00:00
$this -> CakeEmail -> template ( null , null );
$expected = array ( 'template' => null , 'layout' => null );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> template (), $expected );
2011-04-17 23:40:18 +00:00
}
2012-03-28 05:22:55 +00:00
/**
* testTheme method
*
* @ return void
*/
public function testTheme () {
$this -> assertSame ( null , $this -> CakeEmail -> theme ());
$this -> CakeEmail -> theme ( 'default' );
$expected = 'default' ;
$this -> assertSame ( $expected , $this -> CakeEmail -> theme ());
}
2011-04-18 00:57:57 +00:00
/**
* testViewVars method
*
* @ return void
*/
public function testViewVars () {
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> viewVars (), array ());
2011-04-18 00:57:57 +00:00
$this -> CakeEmail -> viewVars ( array ( 'value' => 12345 ));
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> viewVars (), array ( 'value' => 12345 ));
2011-04-18 00:57:57 +00:00
$this -> CakeEmail -> viewVars ( array ( 'name' => 'CakePHP' ));
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> viewVars (), array ( 'value' => 12345 , 'name' => 'CakePHP' ));
2011-04-18 00:57:57 +00:00
$this -> CakeEmail -> viewVars ( array ( 'value' => 4567 ));
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> viewVars (), array ( 'value' => 4567 , 'name' => 'CakePHP' ));
2011-04-18 00:57:57 +00:00
}
2011-04-17 23:40:18 +00:00
/**
* testAttachments method
2011-03-01 21:51:12 +00:00
*
* @ return void
*/
public function testAttachments () {
2011-04-24 02:29:05 +00:00
$this -> CakeEmail -> attachments ( CAKE . 'basics.php' );
2012-07-22 01:22:04 +00:00
$expected = array (
'basics.php' => array (
'file' => CAKE . 'basics.php' ,
'mimetype' => 'application/octet-stream'
)
);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> attachments (), $expected );
2011-03-01 21:51:12 +00:00
2011-03-21 12:30:16 +00:00
$this -> CakeEmail -> attachments ( array ());
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> attachments (), array ());
2011-03-01 21:51:12 +00:00
2012-07-22 01:22:04 +00:00
$this -> CakeEmail -> attachments ( array (
array ( 'file' => CAKE . 'basics.php' , 'mimetype' => 'text/plain' )
));
2011-04-24 02:29:05 +00:00
$this -> CakeEmail -> addAttachments ( CAKE . 'bootstrap.php' );
$this -> CakeEmail -> addAttachments ( array ( CAKE . 'bootstrap.php' ));
$this -> CakeEmail -> addAttachments ( array ( 'other.txt' => CAKE . 'bootstrap.php' , 'license' => CAKE . 'LICENSE.txt' ));
2011-03-04 03:20:55 +00:00
$expected = array (
2011-04-24 02:29:05 +00:00
'basics.php' => array ( 'file' => CAKE . 'basics.php' , 'mimetype' => 'text/plain' ),
'bootstrap.php' => array ( 'file' => CAKE . 'bootstrap.php' , 'mimetype' => 'application/octet-stream' ),
'other.txt' => array ( 'file' => CAKE . 'bootstrap.php' , 'mimetype' => 'application/octet-stream' ),
'license' => array ( 'file' => CAKE . 'LICENSE.txt' , 'mimetype' => 'application/octet-stream' )
2011-03-04 03:20:55 +00:00
);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> attachments (), $expected );
2011-08-29 14:02:00 +00:00
$this -> setExpectedException ( 'SocketException' );
$this -> CakeEmail -> attachments ( array ( array ( 'nofile' => CAKE . 'basics.php' , 'mimetype' => 'text/plain' )));
2011-03-01 21:51:12 +00:00
}
2011-04-16 02:37:55 +00:00
/**
* testTransport method
*
* @ return void
*/
public function testTransport () {
2011-08-29 01:11:30 +00:00
$result = $this -> CakeEmail -> transport ( 'Debug' );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail , $result );
$this -> assertSame ( $this -> CakeEmail -> transport (), 'Debug' );
2011-04-16 02:37:55 +00:00
$result = $this -> CakeEmail -> transportClass ();
2011-11-16 17:56:34 +00:00
$this -> assertInstanceOf ( 'DebugTransport' , $result );
2011-08-29 14:02:00 +00:00
$this -> setExpectedException ( 'SocketException' );
$this -> CakeEmail -> transport ( 'Invalid' );
$result = $this -> CakeEmail -> transportClass ();
}
/**
* testExtendTransport method
*
* @ return void
*/
public function testExtendTransport () {
$this -> setExpectedException ( 'SocketException' );
$this -> CakeEmail -> transport ( 'Extend' );
2013-01-23 12:45:50 +00:00
$this -> CakeEmail -> transportClass ();
2011-04-16 02:37:55 +00:00
}
/**
* testConfig method
*
* @ return void
*/
public function testConfig () {
2011-08-29 01:11:30 +00:00
$transportClass = $this -> CakeEmail -> transport ( 'debug' ) -> transportClass ();
2011-04-16 02:37:55 +00:00
$config = array ( 'test' => 'ok' , 'test2' => true );
$this -> CakeEmail -> config ( $config );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $transportClass -> config (), $config );
$this -> assertSame ( $this -> CakeEmail -> config (), $config );
2011-04-17 15:53:12 +00:00
$this -> CakeEmail -> config ( array ());
2013-08-13 08:42:52 +00:00
$this -> assertSame ( $transportClass -> config (), $config );
2013-05-23 13:47:24 +00:00
$config = array ( 'test' => 'test@example.com' );
$this -> CakeEmail -> config ( $config );
$expected = array ( 'test' => 'test@example.com' , 'test2' => true );
$this -> assertSame ( $expected , $this -> CakeEmail -> config ());
2013-08-13 08:42:52 +00:00
$this -> assertSame ( $expected , $transportClass -> config ());
2011-04-16 02:37:55 +00:00
}
2011-08-25 14:03:39 +00:00
/**
* testConfigString method
*
* @ return void
*/
public function testConfigString () {
2013-09-28 02:22:23 +00:00
$configs = new TestEmailConfig ();
2011-08-25 14:03:39 +00:00
$this -> CakeEmail -> config ( 'test' );
$result = $this -> CakeEmail -> to ();
2011-08-26 00:31:18 +00:00
$this -> assertEquals ( $configs -> test [ 'to' ], $result );
2011-08-25 14:03:39 +00:00
$result = $this -> CakeEmail -> from ();
2011-08-26 00:31:18 +00:00
$this -> assertEquals ( $configs -> test [ 'from' ], $result );
2011-08-25 14:03:39 +00:00
$result = $this -> CakeEmail -> subject ();
2011-08-26 00:31:18 +00:00
$this -> assertEquals ( $configs -> test [ 'subject' ], $result );
2011-08-25 14:03:39 +00:00
2012-03-28 05:22:55 +00:00
$result = $this -> CakeEmail -> theme ();
$this -> assertEquals ( $configs -> test [ 'theme' ], $result );
2011-08-25 14:03:39 +00:00
$result = $this -> CakeEmail -> transport ();
2011-08-26 00:31:18 +00:00
$this -> assertEquals ( $configs -> test [ 'transport' ], $result );
2011-08-25 14:03:39 +00:00
$result = $this -> CakeEmail -> transportClass ();
2011-11-16 17:56:34 +00:00
$this -> assertInstanceOf ( 'DebugTransport' , $result );
2012-06-23 01:44:37 +00:00
$result = $this -> CakeEmail -> helpers ();
$this -> assertEquals ( $configs -> test [ 'helpers' ], $result );
2011-08-25 14:03:39 +00:00
}
2011-12-06 20:52:48 +00:00
2013-08-13 08:42:52 +00:00
/**
* Test updating config doesn 't reset transport' s config .
*
* @ return void
*/
public function testConfigMerge () {
$this -> CakeEmail -> config ( 'test2' );
$expected = array (
'host' => 'cakephp.org' ,
'port' => 25 ,
'timeout' => 60 ,
'username' => null ,
'password' => null ,
'client' => null ,
'tls' => false
);
$this -> assertEquals ( $expected , $this -> CakeEmail -> transportClass () -> config ());
$this -> CakeEmail -> config ( array ( 'log' => true ));
$result = $this -> CakeEmail -> transportClass () -> config ();
$expected += array ( 'log' => true );
$this -> assertEquals ( $expected , $this -> CakeEmail -> transportClass () -> config ());
$this -> CakeEmail -> config ( array ( 'timeout' => 45 ));
$result = $this -> CakeEmail -> transportClass () -> config ();
$this -> assertEquals ( 45 , $result [ 'timeout' ]);
}
2013-10-08 16:28:26 +00:00
/**
* Calling send () with no parameters should not overwrite the view variables .
*
* @ return void
*/
public function testSendWithNoContentDoesNotOverwriteViewVar () {
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'Debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( 'you@cakephp.org' );
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> emailFormat ( 'text' );
$this -> CakeEmail -> template ( 'default' );
$this -> CakeEmail -> viewVars ( array (
'content' => 'A message to you' ,
));
$result = $this -> CakeEmail -> send ();
$this -> assertContains ( 'A message to you' , $result [ 'message' ]);
}
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-08-29 01:11:30 +00:00
$this -> CakeEmail -> transport ( 'Debug' );
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-08-29 01:11:30 +00:00
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. " );
2011-08-29 01:11:30 +00:00
$expected = array ( 'headers' , 'message' );
$this -> assertEquals ( $expected , array_keys ( $result ));
2011-08-29 09:21:46 +00:00
$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 " ;
2011-03-04 11:06:09 +00:00
2011-08-29 01:11:30 +00:00
$this -> assertEquals ( $expected , $result [ 'message' ]);
$this -> assertTrue (( bool ) strpos ( $result [ 'headers' ], 'Date: ' ));
$this -> assertTrue (( bool ) strpos ( $result [ 'headers' ], 'Message-ID: ' ));
$this -> assertTrue (( bool ) strpos ( $result [ 'headers' ], 'To: ' ));
2011-03-04 11:06:09 +00:00
2011-08-29 01:11:30 +00:00
$result = $this -> CakeEmail -> send ( " Other body " );
2011-08-29 09:21:46 +00:00
$expected = " Other body \r \n \r \n " ;
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $result [ 'message' ], $expected );
2011-08-29 01:11:30 +00:00
$this -> assertTrue (( bool ) strpos ( $result [ 'headers' ], 'Message-ID: ' ));
$this -> assertTrue (( bool ) strpos ( $result [ 'headers' ], 'To: ' ));
2011-08-29 15:13:41 +00:00
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'Debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( array ( 'you@cakephp.org' => 'You' ));
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> config ( array ( 'empty' ));
$result = $this -> CakeEmail -> send ( array ( 'Sending content' , 'As array' ));
$expected = " Sending content \r \n As array \r \n \r \n \r \n " ;
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $result [ 'message' ], $expected );
2011-08-29 15:13:41 +00:00
}
/**
* testSendWithoutFrom method
*
* @ return void
*/
public function testSendWithoutFrom () {
$this -> CakeEmail -> transport ( 'Debug' );
$this -> CakeEmail -> to ( 'cake@cakephp.org' );
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> config ( array ( 'empty' ));
$this -> setExpectedException ( 'SocketException' );
$this -> CakeEmail -> send ( " Forgot to set From " );
}
/**
* testSendWithoutTo method
*
* @ return void
*/
public function testSendWithoutTo () {
$this -> CakeEmail -> transport ( 'Debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> config ( array ( 'empty' ));
$this -> setExpectedException ( 'SocketException' );
$this -> CakeEmail -> send ( " Forgot to set To " );
}
2011-12-27 00:36:35 +00:00
/**
* Test send () with no template .
*
* @ return void
*/
public function testSendNoTemplateWithAttachments () {
$this -> CakeEmail -> transport ( 'debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( 'cake@cakephp.org' );
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> emailFormat ( 'text' );
$this -> CakeEmail -> attachments ( array ( CAKE . 'basics.php' ));
$result = $this -> CakeEmail -> send ( 'Hello' );
$boundary = $this -> CakeEmail -> getBoundary ();
$this -> assertContains ( 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' , $result [ 'headers' ]);
$expected = " -- $boundary\r\n " .
" Content-Type: text/plain; charset=UTF-8 \r \n " .
" Content-Transfer-Encoding: 8bit \r \n " .
" \r \n " .
" Hello " .
" \r \n " .
" \r \n " .
" \r \n " .
" -- $boundary\r\n " .
" Content-Type: application/octet-stream \r \n " .
" Content-Transfer-Encoding: base64 \r \n " .
" Content-Disposition: attachment; filename= \" basics.php \" \r \n \r \n " ;
$this -> assertContains ( $expected , $result [ 'message' ]);
}
2013-06-27 22:46:34 +00:00
/**
* Test send () with no template and data string attachment
*
* @ return void
*/
public function testSendNoTemplateWithDataStringAttachment () {
$this -> CakeEmail -> transport ( 'debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( 'cake@cakephp.org' );
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> emailFormat ( 'text' );
$data = file_get_contents ( CAKE . 'Console/Templates/skel/webroot/img/cake.icon.png' );
$this -> CakeEmail -> attachments ( array ( 'cake.icon.png' => array (
'data' => $data ,
'mimetype' => 'image/png'
)));
$result = $this -> CakeEmail -> send ( 'Hello' );
$boundary = $this -> CakeEmail -> getBoundary ();
$this -> assertContains ( 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' , $result [ 'headers' ]);
$expected = " -- $boundary\r\n " .
" Content-Type: text/plain; charset=UTF-8 \r \n " .
" Content-Transfer-Encoding: 8bit \r \n " .
" \r \n " .
" Hello " .
" \r \n " .
" \r \n " .
" \r \n " .
" -- $boundary\r\n " .
" Content-Type: image/png \r \n " .
" Content-Transfer-Encoding: base64 \r \n " .
" Content-Disposition: attachment; filename= \" cake.icon.png \" \r \n \r \n " ;
$expected .= chunk_split ( base64_encode ( $data ), 76 , " \r \n " );
$this -> assertContains ( $expected , $result [ 'message' ]);
}
2011-12-27 00:36:35 +00:00
/**
* Test send () with no template as both
*
* @ return void
*/
public function testSendNoTemplateWithAttachmentsAsBoth () {
$this -> CakeEmail -> transport ( 'debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( 'cake@cakephp.org' );
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> emailFormat ( 'both' );
$this -> CakeEmail -> attachments ( array ( CAKE . 'VERSION.txt' ));
$result = $this -> CakeEmail -> send ( 'Hello' );
$boundary = $this -> CakeEmail -> getBoundary ();
$this -> assertContains ( 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' , $result [ 'headers' ]);
$expected = " -- $boundary\r\n " .
" Content-Type: multipart/alternative; boundary= \" alt- $boundary\ " \r\n " .
2011-12-27 03:07:52 +00:00
" \r \n " .
" --alt- $boundary\r\n " .
" Content-Type: text/plain; charset=UTF-8 \r \n " .
2011-12-27 00:36:35 +00:00
" Content-Transfer-Encoding: 8bit \r \n " .
" \r \n " .
" Hello " .
" \r \n " .
" \r \n " .
" \r \n " .
2011-12-27 03:07:52 +00:00
" --alt- $boundary\r\n " .
" Content-Type: text/html; charset=UTF-8 \r \n " .
" Content-Transfer-Encoding: 8bit \r \n " .
" \r \n " .
" Hello " .
" \r \n " .
" \r \n " .
" \r \n " .
" --alt- { $boundary } -- \r \n " .
" \r \n " .
2011-12-27 00:36:35 +00:00
" -- $boundary\r\n " .
" Content-Type: application/octet-stream \r \n " .
" Content-Transfer-Encoding: base64 \r \n " .
" Content-Disposition: attachment; filename= \" VERSION.txt \" \r \n \r \n " ;
$this -> assertContains ( $expected , $result [ 'message' ]);
}
2011-12-27 03:52:29 +00:00
/**
* Test setting inline attachments and messages .
*
* @ return void
*/
public function testSendWithInlineAttachments () {
$this -> CakeEmail -> transport ( 'debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( 'cake@cakephp.org' );
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> emailFormat ( 'both' );
$this -> CakeEmail -> attachments ( array (
'cake.png' => array (
'file' => CAKE . 'VERSION.txt' ,
'contentId' => 'abc123'
)
));
$result = $this -> CakeEmail -> send ( 'Hello' );
$boundary = $this -> CakeEmail -> getBoundary ();
$this -> assertContains ( 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' , $result [ 'headers' ]);
$expected = " -- $boundary\r\n " .
" Content-Type: multipart/related; boundary= \" rel- $boundary\ " \r\n " .
" \r \n " .
" --rel- $boundary\r\n " .
" Content-Type: multipart/alternative; boundary= \" alt- $boundary\ " \r\n " .
" \r \n " .
" --alt- $boundary\r\n " .
" Content-Type: text/plain; charset=UTF-8 \r \n " .
" Content-Transfer-Encoding: 8bit \r \n " .
" \r \n " .
" Hello " .
" \r \n " .
" \r \n " .
" \r \n " .
" --alt- $boundary\r\n " .
" Content-Type: text/html; charset=UTF-8 \r \n " .
" Content-Transfer-Encoding: 8bit \r \n " .
" \r \n " .
" Hello " .
" \r \n " .
" \r \n " .
" \r \n " .
" --alt- { $boundary } -- \r \n " .
" \r \n " .
2012-01-12 01:44:42 +00:00
" --rel- $boundary\r\n " .
2011-12-27 03:52:29 +00:00
" Content-Type: application/octet-stream \r \n " .
" Content-Transfer-Encoding: base64 \r \n " .
" Content-ID: <abc123> \r \n " .
" Content-Disposition: inline; filename= \" cake.png \" \r \n \r \n " ;
$this -> assertContains ( $expected , $result [ 'message' ]);
$this -> assertContains ( '--rel-' . $boundary . '--' , $result [ 'message' ]);
$this -> assertContains ( '--' . $boundary . '--' , $result [ 'message' ]);
2012-03-17 02:19:01 +00:00
}
2011-12-27 03:52:29 +00:00
2014-05-14 13:42:25 +00:00
/**
* Test setting inline attachments and HTML only messages .
*
* @ return void
*/
public function testSendWithInlineAttachmentsHtmlOnly () {
$this -> CakeEmail -> transport ( 'debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( 'cake@cakephp.org' );
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> emailFormat ( 'html' );
$this -> CakeEmail -> attachments ( array (
'cake.png' => array (
'file' => CAKE . 'VERSION.txt' ,
'contentId' => 'abc123'
)
));
$result = $this -> CakeEmail -> send ( 'Hello' );
$boundary = $this -> CakeEmail -> getBoundary ();
$this -> assertContains ( 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' , $result [ 'headers' ]);
$expected = " -- $boundary\r\n " .
" Content-Type: multipart/related; boundary= \" rel- $boundary\ " \r\n " .
" \r \n " .
" --rel- $boundary\r\n " .
" Content-Type: text/html; charset=UTF-8 \r \n " .
" Content-Transfer-Encoding: 8bit \r \n " .
" \r \n " .
" Hello " .
" \r \n " .
" \r \n " .
" \r \n " .
" --rel- $boundary\r\n " .
" Content-Type: application/octet-stream \r \n " .
" Content-Transfer-Encoding: base64 \r \n " .
" Content-ID: <abc123> \r \n " .
" Content-Disposition: inline; filename= \" cake.png \" \r \n \r \n " ;
$this -> assertContains ( $expected , $result [ 'message' ]);
$this -> assertContains ( '--rel-' . $boundary . '--' , $result [ 'message' ]);
$this -> assertContains ( '--' . $boundary . '--' , $result [ 'message' ]);
}
2012-07-22 01:22:04 +00:00
/**
* Test disabling content - disposition .
*
* @ return void
*/
public function testSendWithNoContentDispositionAttachments () {
$this -> CakeEmail -> transport ( 'debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( 'cake@cakephp.org' );
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> emailFormat ( 'text' );
$this -> CakeEmail -> attachments ( array (
'cake.png' => array (
'file' => CAKE . 'VERSION.txt' ,
'contentDisposition' => false
)
));
$result = $this -> CakeEmail -> send ( 'Hello' );
$boundary = $this -> CakeEmail -> getBoundary ();
$this -> assertContains ( 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' , $result [ 'headers' ]);
$expected = " -- $boundary\r\n " .
" Content-Type: text/plain; charset=UTF-8 \r \n " .
" Content-Transfer-Encoding: 8bit \r \n " .
" \r \n " .
" Hello " .
" \r \n " .
" \r \n " .
" \r \n " .
" -- { $boundary } \r \n " .
" Content-Type: application/octet-stream \r \n " .
" Content-Transfer-Encoding: base64 \r \n " .
" \r \n " ;
$this -> assertContains ( $expected , $result [ 'message' ]);
$this -> assertContains ( '--' . $boundary . '--' , $result [ 'message' ]);
}
2011-08-29 15:13:41 +00:00
/**
* testSendWithLog method
*
* @ return void
*/
public function testSendWithLog () {
CakeLog :: config ( 'email' , array (
2013-06-21 14:39:51 +00:00
'engine' => 'File' ,
2011-09-01 19:24:39 +00:00
'path' => TMP
2011-08-29 15:13:41 +00:00
));
CakeLog :: drop ( 'default' );
$this -> CakeEmail -> transport ( 'Debug' );
$this -> CakeEmail -> to ( 'me@cakephp.org' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> subject ( 'My title' );
2011-09-01 19:24:39 +00:00
$this -> CakeEmail -> config ( array ( 'log' => 'cake_test_emails' ));
2011-08-29 15:13:41 +00:00
$result = $this -> CakeEmail -> send ( " Logging This " );
App :: uses ( 'File' , 'Utility' );
2013-02-15 00:46:10 +00:00
$File = new File ( TMP . 'cake_test_emails.log' );
$log = $File -> read ();
$this -> assertTrue ( strpos ( $log , $result [ 'headers' ]) !== false );
$this -> assertTrue ( strpos ( $log , $result [ 'message' ]) !== false );
$File -> delete ();
CakeLog :: drop ( 'email' );
}
/**
* testSendWithLogAndScope method
*
* @ return void
*/
public function testSendWithLogAndScope () {
CakeLog :: config ( 'email' , array (
2013-06-21 14:39:51 +00:00
'engine' => 'File' ,
2013-02-15 00:46:10 +00:00
'path' => TMP ,
'types' => array ( 'cake_test_emails' ),
'scopes' => array ( 'email' )
));
CakeLog :: drop ( 'default' );
$this -> CakeEmail -> transport ( 'Debug' );
$this -> CakeEmail -> to ( 'me@cakephp.org' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> config ( array ( 'log' => array ( 'level' => 'cake_test_emails' , 'scope' => 'email' )));
$result = $this -> CakeEmail -> send ( " Logging This " );
App :: uses ( 'File' , 'Utility' );
2011-09-01 19:24:39 +00:00
$File = new File ( TMP . 'cake_test_emails.log' );
2011-08-29 15:13:41 +00:00
$log = $File -> read ();
$this -> assertTrue ( strpos ( $log , $result [ 'headers' ]) !== false );
$this -> assertTrue ( strpos ( $log , $result [ 'message' ]) !== false );
$File -> delete ();
CakeLog :: drop ( 'email' );
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
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 ();
2011-12-26 22:59:50 +00:00
$this -> assertContains ( 'This email was sent using the CakePHP Framework' , $result [ 'message' ]);
$this -> assertContains ( 'Message-ID: ' , $result [ 'headers' ]);
$this -> assertContains ( 'To: ' , $result [ 'headers' ]);
2011-03-04 11:29:38 +00:00
}
2013-08-13 18:01:33 +00:00
/**
* test sending and rendering with no layout
*
* @ return void
*/
public function testSendRenderNoLayout () {
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( array ( 'you@cakephp.org' => 'You' ));
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> config ( array ( 'empty' ));
$this -> CakeEmail -> template ( 'default' , null );
$result = $this -> CakeEmail -> send ( 'message body.' );
$this -> assertContains ( 'message body.' , $result [ 'message' ]);
$this -> assertNotContains ( 'This email was sent using the CakePHP Framework' , $result [ 'message' ]);
}
2014-05-13 21:47:11 +00:00
/**
* testSendRender both method
*
* @ return void
*/
public function testSendRenderBoth () {
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( array ( 'you@cakephp.org' => 'You' ));
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> config ( array ( 'empty' ));
$this -> CakeEmail -> template ( 'default' , 'default' );
$this -> CakeEmail -> emailFormat ( 'both' );
$result = $this -> CakeEmail -> send ();
$this -> assertContains ( 'Message-ID: ' , $result [ 'headers' ]);
$this -> assertContains ( 'To: ' , $result [ 'headers' ]);
$boundary = $this -> CakeEmail -> getBoundary ();
$this -> assertContains ( 'Content-Type: multipart/alternative; boundary="' . $boundary . '"' , $result [ 'headers' ]);
$expected = " -- $boundary\r\n " .
" Content-Type: text/plain; charset=UTF-8 \r \n " .
" Content-Transfer-Encoding: 8bit \r \n " .
" \r \n " .
" \r \n " .
" \r \n " .
" This email was sent using the CakePHP Framework, http://cakephp.org. " .
" \r \n " .
" \r \n " .
" -- $boundary\r\n " .
" Content-Type: text/html; charset=UTF-8 \r \n " .
" Content-Transfer-Encoding: 8bit \r \n " .
" \r \n " .
" <!DOCTYPE html " ;
$this -> assertStringStartsWith ( $expected , $result [ 'message' ]);
$expected = " </html> \r \n " .
" \r \n " .
" \r \n " .
" -- $boundary -- \r \n " ;
$this -> assertStringEndsWith ( $expected , $result [ 'message' ]);
}
2011-10-19 15:18:42 +00:00
/**
* testSendRender method for ISO - 2022 - JP
*
* @ return void
*/
public function testSendRenderJapanese () {
$this -> skipIf ( ! function_exists ( 'mb_convert_encoding' ));
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( array ( 'you@cakephp.org' => 'You' ));
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> config ( array ( 'empty' ));
$this -> CakeEmail -> template ( 'default' , 'japanese' );
$this -> CakeEmail -> charset = 'ISO-2022-JP' ;
$result = $this -> CakeEmail -> send ();
2011-12-27 03:07:52 +00:00
$expected = mb_convert_encoding ( 'CakePHP Framework を使って送信したメールです。 http://cakephp.org.' , 'ISO-2022-JP' );
2011-12-26 22:59:50 +00:00
$this -> assertContains ( $expected , $result [ 'message' ]);
$this -> assertContains ( 'Message-ID: ' , $result [ 'headers' ]);
$this -> assertContains ( 'To: ' , $result [ 'headers' ]);
2011-10-19 15:18:42 +00:00
}
2012-03-28 05:22:55 +00:00
/**
* testSendRenderThemed method
*
* @ return void
*/
public function testSendRenderThemed () {
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( array ( 'you@cakephp.org' => 'You' ));
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> config ( array ( 'empty' ));
$this -> CakeEmail -> theme ( 'TestTheme' );
$this -> CakeEmail -> template ( 'themed' , 'default' );
$result = $this -> CakeEmail -> send ();
$this -> assertContains ( 'In TestTheme' , $result [ 'message' ]);
$this -> assertContains ( 'Message-ID: ' , $result [ 'headers' ]);
$this -> assertContains ( 'To: ' , $result [ 'headers' ]);
2014-03-18 13:22:24 +00:00
$this -> assertContains ( '/theme/TestTheme/img/test.jpg' , $result [ 'message' ]);
2012-03-28 05:22:55 +00:00
}
2013-04-29 14:18:00 +00:00
/**
* testSendRenderWithHTML method and assert line length is kept below the required limit
*
* @ return void
*/
public function testSendRenderWithHTML () {
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( array ( 'you@cakephp.org' => 'You' ));
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> config ( array ( 'empty' ));
$this -> CakeEmail -> emailFormat ( 'html' );
$this -> CakeEmail -> template ( 'html' , 'default' );
$result = $this -> CakeEmail -> send ();
$this -> assertTextContains ( '<h1>HTML Ipsum Presents</h1>' , $result [ 'message' ]);
2013-05-23 16:34:39 +00:00
$this -> assertLineLengths ( $result [ 'message' ]);
2013-04-29 14:18:00 +00:00
}
2011-04-17 21:22:20 +00:00
/**
* testSendRenderWithVars method
*
* @ return void
*/
public function testSendRenderWithVars () {
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'debug' );
$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 ();
2011-12-26 22:59:50 +00:00
$this -> assertContains ( 'Here is your value: 12345' , $result [ 'message' ]);
2011-04-17 21:22:20 +00:00
}
2011-10-19 15:18:42 +00:00
/**
* testSendRenderWithVars method for ISO - 2022 - JP
*
* @ return void
*/
public function testSendRenderWithVarsJapanese () {
2011-10-22 06:52:41 +00:00
$this -> skipIf ( ! function_exists ( 'mb_convert_encoding' ));
2011-10-19 15:18:42 +00:00
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( array ( 'you@cakephp.org' => 'You' ));
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> config ( array ( 'empty' ));
$this -> CakeEmail -> template ( 'japanese' , 'default' );
$this -> CakeEmail -> viewVars ( array ( 'value' => '日本語の差し込み123' ));
$this -> CakeEmail -> charset = 'ISO-2022-JP' ;
$result = $this -> CakeEmail -> send ();
$expected = mb_convert_encoding ( 'ここにあなたの設定した値が入ります: 日本語の差し込み123' , 'ISO-2022-JP' );
$this -> assertTrue (( bool ) strpos ( $result [ 'message' ], $expected ));
}
2011-06-19 22:43:11 +00:00
/**
* testSendRenderWithHelpers method
*
* @ return void
*/
public function testSendRenderWithHelpers () {
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'debug' );
$timestamp = time ();
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( array ( 'you@cakephp.org' => 'You' ));
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> config ( array ( 'empty' ));
$this -> CakeEmail -> template ( 'custom_helper' , 'default' );
$this -> CakeEmail -> viewVars ( array ( 'time' => $timestamp ));
2011-08-29 14:02:00 +00:00
$result = $this -> CakeEmail -> helpers ( array ( 'Time' ));
2011-11-16 17:56:34 +00:00
$this -> assertInstanceOf ( 'CakeEmail' , $result );
2011-08-29 14:02:00 +00:00
$result = $this -> CakeEmail -> send ();
2011-08-29 01:11:30 +00:00
$this -> assertTrue (( bool ) strpos ( $result [ 'message' ], 'Right now: ' . date ( 'Y-m-d\TH:i:s\Z' , $timestamp )));
2011-08-29 14:02:00 +00:00
$result = $this -> CakeEmail -> helpers ();
$this -> assertEquals ( array ( 'Time' ), $result );
2011-06-19 22:43:11 +00:00
}
2012-06-03 08:52:21 +00:00
/**
* testSendRenderWithImage method
*
* @ return void
*/
public function testSendRenderWithImage () {
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'Debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( array ( 'you@cakephp.org' => 'You' ));
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> config ( array ( 'empty' ));
$this -> CakeEmail -> template ( 'image' );
$this -> CakeEmail -> emailFormat ( 'html' );
2012-07-06 02:56:45 +00:00
$server = env ( 'SERVER_NAME' ) ? env ( 'SERVER_NAME' ) : 'localhost' ;
2012-09-01 11:14:15 +00:00
2012-09-21 22:30:43 +00:00
if ( env ( 'SERVER_PORT' ) && env ( 'SERVER_PORT' ) != 80 ) {
2012-08-25 23:23:32 +00:00
$server .= ':' . env ( 'SERVER_PORT' );
}
2012-09-01 11:14:15 +00:00
2012-07-06 02:56:45 +00:00
$expected = '<img src="http://' . $server . '/img/image.gif" alt="cool image" width="100" height="100" />' ;
2012-06-03 08:52:21 +00:00
$result = $this -> CakeEmail -> send ();
$this -> assertContains ( $expected , $result [ 'message' ]);
}
2011-06-01 02:55:58 +00:00
/**
* testSendRenderPlugin method
*
* @ return void
*/
public function testSendRenderPlugin () {
App :: build ( array (
2012-02-18 12:31:29 +00:00
'Plugin' => array ( CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS )
2011-06-01 02:55:58 +00:00
));
2014-04-05 01:45:04 +00:00
CakePlugin :: load ( array ( 'TestPlugin' , 'TestPluginTwo' ));
2011-06-01 02:55:58 +00:00
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'debug' );
$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-08-29 01:11:30 +00:00
$result = $this -> CakeEmail -> template ( 'TestPlugin.test_plugin_tpl' , 'default' ) -> send ();
2011-12-26 22:59:50 +00:00
$this -> assertContains ( 'Into TestPlugin.' , $result [ 'message' ]);
$this -> assertContains ( 'This email was sent using the CakePHP Framework' , $result [ 'message' ]);
2011-06-01 02:55:58 +00:00
2011-08-29 01:11:30 +00:00
$result = $this -> CakeEmail -> template ( 'TestPlugin.test_plugin_tpl' , 'TestPlugin.plug_default' ) -> send ();
2011-12-26 22:59:50 +00:00
$this -> assertContains ( 'Into TestPlugin.' , $result [ 'message' ]);
$this -> assertContains ( 'This email was sent using the TestPlugin.' , $result [ 'message' ]);
2011-06-01 02:55:58 +00:00
2011-08-29 01:11:30 +00:00
$result = $this -> CakeEmail -> template ( 'TestPlugin.test_plugin_tpl' , 'plug_default' ) -> send ();
2011-12-26 22:59:50 +00:00
$this -> assertContains ( 'Into TestPlugin.' , $result [ 'message' ]);
$this -> assertContains ( 'This email was sent using the TestPlugin.' , $result [ 'message' ]);
2011-06-01 02:55:58 +00:00
2014-04-05 01:45:04 +00:00
$this -> CakeEmail -> template (
'TestPlugin.test_plugin_tpl' ,
'TestPluginTwo.default'
);
$result = $this -> CakeEmail -> send ();
$this -> assertContains ( 'Into TestPlugin.' , $result [ 'message' ]);
$this -> assertContains ( 'This email was sent using TestPluginTwo.' , $result [ 'message' ]);
2012-03-28 05:22:55 +00:00
// test plugin template overridden by theme
$this -> CakeEmail -> theme ( 'TestTheme' );
$result = $this -> CakeEmail -> send ();
$this -> assertContains ( 'Into TestPlugin. (themed)' , $result [ 'message' ]);
2011-06-01 02:55:58 +00:00
$this -> CakeEmail -> viewVars ( array ( 'value' => 12345 ));
2011-08-29 01:11:30 +00:00
$result = $this -> CakeEmail -> template ( 'custom' , 'TestPlugin.plug_default' ) -> send ();
2011-12-26 22:59:50 +00:00
$this -> assertContains ( 'Here is your value: 12345' , $result [ 'message' ]);
$this -> assertContains ( 'This email was sent using the TestPlugin.' , $result [ 'message' ]);
2011-06-01 02:55:58 +00:00
2011-08-29 14:02:00 +00:00
$this -> setExpectedException ( 'MissingViewException' );
2011-06-01 02:55:58 +00:00
$this -> CakeEmail -> template ( 'test_plugin_tpl' , 'plug_default' ) -> send ();
}
2011-04-19 13:22:42 +00:00
/**
* testSendMultipleMIME method
*
* @ return void
*/
public function testSendMultipleMIME () {
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'debug' );
$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' );
2013-01-23 12:45:50 +00:00
$this -> CakeEmail -> send ();
2011-04-19 13:22:42 +00:00
$message = $this -> CakeEmail -> message ();
$boundary = $this -> CakeEmail -> getBoundary ();
$this -> assertFalse ( empty ( $boundary ));
2011-12-27 03:07:52 +00:00
$this -> assertContains ( '--' . $boundary , $message );
2011-12-28 04:38:21 +00:00
$this -> assertContains ( '--' . $boundary . '--' , $message );
2011-04-19 13:22:42 +00:00
$this -> CakeEmail -> attachments ( array ( 'fake.php' => __FILE__ ));
$this -> CakeEmail -> send ();
$message = $this -> CakeEmail -> message ();
$boundary = $this -> CakeEmail -> getBoundary ();
$this -> assertFalse ( empty ( $boundary ));
2011-12-26 22:59:50 +00:00
$this -> assertContains ( '--' . $boundary , $message );
$this -> assertContains ( '--' . $boundary . '--' , $message );
$this -> assertContains ( '--alt-' . $boundary , $message );
$this -> assertContains ( '--alt-' . $boundary . '--' , $message );
2011-04-19 13:22:42 +00:00
}
2011-04-21 01:51:30 +00:00
/**
* testSendAttachment method
*
* @ return void
*/
public function testSendAttachment () {
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( array ( 'you@cakephp.org' => 'You' ));
$this -> CakeEmail -> subject ( 'My title' );
$this -> CakeEmail -> config ( array ());
2011-04-24 02:29:05 +00:00
$this -> CakeEmail -> attachments ( array ( CAKE . 'basics.php' ));
2011-08-29 01:11:30 +00:00
$result = $this -> CakeEmail -> send ( 'body' );
2011-12-26 17:03:48 +00:00
$this -> assertContains ( " Content-Type: application/octet-stream \r \n Content-Transfer-Encoding: base64 \r \n Content-Disposition: attachment; filename= \" basics.php \" " , $result [ 'message' ]);
2011-04-21 01:51:30 +00:00
2011-04-24 02:29:05 +00:00
$this -> CakeEmail -> attachments ( array ( 'my.file.txt' => CAKE . 'basics.php' ));
2011-08-29 01:11:30 +00:00
$result = $this -> CakeEmail -> send ( 'body' );
2011-12-26 17:03:48 +00:00
$this -> assertContains ( " Content-Type: application/octet-stream \r \n Content-Transfer-Encoding: base64 \r \n Content-Disposition: attachment; filename= \" my.file.txt \" " , $result [ 'message' ]);
2011-04-21 01:51:30 +00:00
2011-04-24 02:29:05 +00:00
$this -> CakeEmail -> attachments ( array ( 'file.txt' => array ( 'file' => CAKE . 'basics.php' , 'mimetype' => 'text/plain' )));
2011-08-29 01:11:30 +00:00
$result = $this -> CakeEmail -> send ( 'body' );
2011-12-26 17:03:48 +00:00
$this -> assertContains ( " Content-Type: text/plain \r \n Content-Transfer-Encoding: base64 \r \n Content-Disposition: attachment; filename= \" file.txt \" " , $result [ 'message' ]);
2011-04-21 01:51:30 +00:00
2011-08-29 09:21:46 +00:00
$this -> CakeEmail -> attachments ( array ( 'file2.txt' => array ( 'file' => CAKE . 'basics.php' , 'mimetype' => 'text/plain' , 'contentId' => 'a1b1c1' )));
$result = $this -> CakeEmail -> send ( 'body' );
2011-12-26 17:03:48 +00:00
$this -> assertContains ( " Content-Type: text/plain \r \n Content-Transfer-Encoding: base64 \r \n Content-ID: <a1b1c1> \r \n Content-Disposition: inline; filename= \" file2.txt \" " , $result [ 'message' ]);
2011-04-21 01:51:30 +00:00
}
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-11-16 17:56:34 +00:00
$this -> assertInstanceOf ( 'CakeEmail' , $instance );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $instance -> to (), array ( 'all@cakephp.org' => 'all@cakephp.org' ));
$this -> assertSame ( $instance -> subject (), 'About' );
$this -> assertSame ( $instance -> from (), array ( 'root@cakephp.org' => 'root@cakephp.org' ));
2011-04-18 01:23:48 +00:00
$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-11-16 00:07:56 +00:00
$this -> assertSame ( $instance -> from (), array ( 'cake@cakephp.org' => 'cake@cakephp.org' ));
$this -> assertSame ( $instance -> to (), array ( 'debug@cakephp.org' => 'debug@cakephp.org' ));
$this -> assertSame ( $instance -> subject (), 'Update ok' );
$this -> assertSame ( $instance -> template (), array ( 'template' => 'custom' , 'layout' => 'custom_layout' ));
$this -> assertSame ( $instance -> viewVars (), array ( 'value' => 123 , 'name' => 'CakePHP' ));
$this -> assertSame ( $instance -> cc (), array ( 'cake@cakephp.org' => 'Myself' ));
2011-08-29 15:13:41 +00:00
$configs = array ( 'from' => 'root@cakephp.org' , 'message' => 'Message from configs' , 'transport' => 'Debug' );
$instance = CakeEmail :: deliver ( 'all@cakephp.org' , 'About' , null , $configs , true );
$message = $instance -> message ();
$this -> assertEquals ( $configs [ 'message' ], $message [ 0 ]);
2011-04-18 01:23:48 +00:00
}
2011-04-17 21:53:51 +00:00
/**
* testMessage method
*
* @ return void
*/
public function testMessage () {
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'debug' );
$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' );
2013-01-23 12:45:50 +00:00
$this -> CakeEmail -> send ();
2011-04-17 21:53:51 +00:00
$expected = '<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>' ;
2011-12-26 22:59:50 +00:00
$this -> assertContains ( $expected , $this -> CakeEmail -> message ( CakeEmail :: MESSAGE_HTML ));
2011-04-17 21:53:51 +00:00
$expected = 'This email was sent using the CakePHP Framework, http://cakephp.org.' ;
2011-12-26 22:59:50 +00:00
$this -> assertContains ( $expected , $this -> CakeEmail -> message ( CakeEmail :: MESSAGE_TEXT ));
2011-04-17 21:53:51 +00:00
$message = $this -> CakeEmail -> message ();
2012-05-21 10:21:02 +00:00
$this -> assertContains ( 'Content-Type: text/plain; charset=UTF-8' , $message );
$this -> assertContains ( 'Content-Type: text/html; charset=UTF-8' , $message );
2011-10-19 15:18:42 +00:00
2011-10-19 04:49:30 +00:00
// UTF-8 is 8bit
2012-04-09 01:01:25 +00:00
$this -> assertTrue ( $this -> _checkContentTransferEncoding ( $message , '8bit' ));
2011-10-19 04:49:30 +00:00
$this -> CakeEmail -> charset = 'ISO-2022-JP' ;
$this -> CakeEmail -> send ();
$message = $this -> CakeEmail -> message ();
2011-12-26 22:59:50 +00:00
$this -> assertContains ( 'Content-Type: text/plain; charset=ISO-2022-JP' , $message );
$this -> assertContains ( 'Content-Type: text/html; charset=ISO-2022-JP' , $message );
2011-10-19 04:49:30 +00:00
// ISO-2022-JP is 7bit
2012-04-09 01:01:25 +00:00
$this -> assertTrue ( $this -> _checkContentTransferEncoding ( $message , '7bit' ));
2011-04-17 21:53:51 +00:00
}
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' );
2012-03-28 05:22:55 +00:00
$this -> CakeEmail -> theme ( 'TestTheme' );
2013-06-30 15:03:18 +00:00
$this -> CakeEmail -> emailPattern ( '/.+@.+\..+/i' );
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> to (), array ( 'cake@cakephp.org' => 'cake@cakephp.org' ));
2011-03-01 17:25:25 +00:00
$this -> CakeEmail -> reset ();
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $this -> CakeEmail -> to (), array ());
2012-03-28 05:22:55 +00:00
$this -> assertSame ( null , $this -> CakeEmail -> theme ());
2013-06-30 15:03:18 +00:00
$this -> assertSame ( null , $this -> CakeEmail -> emailPattern ());
2011-02-27 18:25:23 +00:00
}
2012-04-01 23:42:18 +00:00
/**
* testReset with charset
*
* @ return void
*/
public function testResetWithCharset () {
$this -> CakeEmail -> charset = 'ISO-2022-JP' ;
$this -> CakeEmail -> reset ();
$this -> assertSame ( $this -> CakeEmail -> charset , 'utf-8' , $this -> CakeEmail -> charset );
$this -> assertSame ( $this -> CakeEmail -> headerCharset , null , $this -> CakeEmail -> headerCharset );
}
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.' ;
2012-12-18 01:54:38 +00:00
$result = $this -> CakeEmail -> wrap ( $text , CakeEmail :: LINE_LENGTH_SHOULD );
2011-03-03 16:30:23 +00:00
$expected = array (
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac turpis orci,' ,
'non commodo odio. Morbi nibh nisi, vehicula pellentesque accumsan amet.' ,
''
);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $expected , $result );
2011-03-03 16:30:23 +00:00
$text = 'Lorem ipsum dolor sit amet, consectetur < adipiscing elit. Donec ac turpis orci, non commodo odio. Morbi nibh nisi, vehicula > pellentesque accumsan amet.' ;
2012-12-18 01:54:38 +00:00
$result = $this -> CakeEmail -> wrap ( $text , CakeEmail :: LINE_LENGTH_SHOULD );
2011-03-03 16:30:23 +00:00
$expected = array (
'Lorem ipsum dolor sit amet, consectetur < adipiscing elit. Donec ac turpis' ,
'orci, non commodo odio. Morbi nibh nisi, vehicula > pellentesque accumsan' ,
'amet.' ,
''
);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $expected , $result );
2011-03-03 16:30:23 +00:00
$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>' ;
2012-12-18 01:54:38 +00:00
$result = $this -> CakeEmail -> wrap ( $text , CakeEmail :: LINE_LENGTH_SHOULD );
2011-03-03 16:30:23 +00:00
$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>' ,
''
);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $expected , $result );
2011-03-03 16:30:23 +00:00
$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.' ;
2012-12-18 01:54:38 +00:00
$result = $this -> CakeEmail -> wrap ( $text , CakeEmail :: LINE_LENGTH_SHOULD );
2011-03-03 16:30:23 +00:00
$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.' ,
''
);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $expected , $result );
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>' ;
2012-12-18 01:54:38 +00:00
$result = $this -> CakeEmail -> wrap ( $text , CakeEmail :: LINE_LENGTH_SHOULD );
2011-03-04 12:48:51 +00:00
$expected = array (
'Lorem ipsum' ,
'<a href="http://www.cakephp.org/controller/action/param1/param2" class="nice cool fine amazing awesome">' ,
'ok</a>' ,
''
);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $expected , $result );
2011-03-04 12:48:51 +00:00
$text = 'Lorem ipsum withonewordverybigMorethanthelineshouldsizeofrfcspecificationbyieeeavailableonieeesite ok.' ;
2012-12-18 01:54:38 +00:00
$result = $this -> CakeEmail -> wrap ( $text , CakeEmail :: LINE_LENGTH_SHOULD );
2011-03-04 12:48:51 +00:00
$expected = array (
'Lorem ipsum' ,
'withonewordverybigMorethanthelineshouldsizeofrfcspecificationbyieeeavailableonieeesite' ,
'ok.' ,
''
);
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $expected , $result );
2011-03-03 16:30:23 +00:00
}
2013-06-29 13:16:58 +00:00
/**
* testRender method
*
* @ return void
*/
public function testRenderWithLayoutAndAttachment () {
$this -> CakeEmail -> emailFormat ( 'html' );
$this -> CakeEmail -> template ( 'html' , 'default' );
$this -> CakeEmail -> attachments ( array ( CAKE . 'basics.php' ));
$result = $this -> CakeEmail -> render ( array ());
$this -> assertNotEmpty ( $result );
$result = $this -> CakeEmail -> getBoundary ();
$this -> assertNotEmpty ( $result );
}
2011-08-25 14:03:39 +00:00
/**
* testConstructWithConfigArray method
*
* @ return void
*/
public function testConstructWithConfigArray () {
$configs = array (
'from' => array ( 'some@example.com' => 'My website' ),
'to' => 'test@example.com' ,
'subject' => 'Test mail subject' ,
'transport' => 'Debug' ,
);
$this -> CakeEmail = new CakeEmail ( $configs );
$result = $this -> CakeEmail -> to ();
2011-08-26 00:31:18 +00:00
$this -> assertEquals ( array ( $configs [ 'to' ] => $configs [ 'to' ]), $result );
2011-08-25 14:03:39 +00:00
$result = $this -> CakeEmail -> from ();
2011-08-26 00:31:18 +00:00
$this -> assertEquals ( $configs [ 'from' ], $result );
2011-08-25 14:03:39 +00:00
$result = $this -> CakeEmail -> subject ();
2011-08-26 00:31:18 +00:00
$this -> assertEquals ( $configs [ 'subject' ], $result );
2011-08-25 14:03:39 +00:00
$result = $this -> CakeEmail -> transport ();
2011-08-26 00:31:18 +00:00
$this -> assertEquals ( $configs [ 'transport' ], $result );
2011-08-25 14:03:39 +00:00
$result = $this -> CakeEmail -> transportClass ();
$this -> assertTrue ( $result instanceof DebugTransport );
$result = $this -> CakeEmail -> send ( 'This is the message' );
2011-08-29 01:11:30 +00:00
$this -> assertTrue (( bool ) strpos ( $result [ 'headers' ], 'Message-ID: ' ));
$this -> assertTrue (( bool ) strpos ( $result [ 'headers' ], 'To: ' ));
2011-08-25 14:03:39 +00:00
}
2014-04-22 14:20:18 +00:00
/**
* testConfigArrayWithLayoutWithoutTemplate method
*
* @ return void
*/
public function testConfigArrayWithLayoutWithoutTemplate () {
$configs = array (
'from' => array ( 'some@example.com' => 'My website' ),
'to' => 'test@example.com' ,
'subject' => 'Test mail subject' ,
'transport' => 'Debug' ,
'layout' => 'custom'
);
$this -> CakeEmail = new CakeEmail ( $configs );
$result = $this -> CakeEmail -> template ();
$this -> assertEquals ( '' , $result [ 'template' ]);
$this -> assertEquals ( $configs [ 'layout' ], $result [ 'layout' ]);
}
2011-08-25 14:03:39 +00:00
/**
* testConstructWithConfigString method
*
* @ return void
*/
public function testConstructWithConfigString () {
2013-09-28 02:22:23 +00:00
$configs = new TestEmailConfig ();
$this -> CakeEmail = new TestCakeEmail ( 'test' );
2011-08-25 14:03:39 +00:00
$result = $this -> CakeEmail -> to ();
2011-08-26 00:31:18 +00:00
$this -> assertEquals ( $configs -> test [ 'to' ], $result );
2011-08-25 14:03:39 +00:00
$result = $this -> CakeEmail -> from ();
2011-08-26 00:31:18 +00:00
$this -> assertEquals ( $configs -> test [ 'from' ], $result );
2011-08-25 14:03:39 +00:00
$result = $this -> CakeEmail -> subject ();
2011-08-26 00:31:18 +00:00
$this -> assertEquals ( $configs -> test [ 'subject' ], $result );
2011-08-25 14:03:39 +00:00
$result = $this -> CakeEmail -> transport ();
2011-08-26 00:31:18 +00:00
$this -> assertEquals ( $configs -> test [ 'transport' ], $result );
2011-08-25 14:03:39 +00:00
$result = $this -> CakeEmail -> transportClass ();
$this -> assertTrue ( $result instanceof DebugTransport );
2011-08-29 01:11:30 +00:00
$result = $this -> CakeEmail -> send ( 'This is the message' );
2011-08-25 14:03:39 +00:00
2011-08-29 01:11:30 +00:00
$this -> assertTrue (( bool ) strpos ( $result [ 'headers' ], 'Message-ID: ' ));
$this -> assertTrue (( bool ) strpos ( $result [ 'headers' ], 'To: ' ));
2011-08-25 14:03:39 +00:00
}
2011-12-06 20:52:48 +00:00
2011-08-29 14:02:00 +00:00
/**
* testViewRender method
*
* @ return void
*/
public function testViewRender () {
$result = $this -> CakeEmail -> viewRender ();
$this -> assertEquals ( 'View' , $result );
$result = $this -> CakeEmail -> viewRender ( 'Theme' );
2011-11-16 17:56:34 +00:00
$this -> assertInstanceOf ( 'CakeEmail' , $result );
2011-08-29 14:02:00 +00:00
$result = $this -> CakeEmail -> viewRender ();
$this -> assertEquals ( 'Theme' , $result );
}
/**
* testEmailFormat method
*
* @ return void
*/
public function testEmailFormat () {
$result = $this -> CakeEmail -> emailFormat ();
$this -> assertEquals ( 'text' , $result );
$result = $this -> CakeEmail -> emailFormat ( 'html' );
2011-11-16 17:56:34 +00:00
$this -> assertInstanceOf ( 'CakeEmail' , $result );
2011-08-29 14:02:00 +00:00
$result = $this -> CakeEmail -> emailFormat ();
$this -> assertEquals ( 'html' , $result );
$this -> setExpectedException ( 'SocketException' );
$result = $this -> CakeEmail -> emailFormat ( 'invalid' );
}
2011-08-25 14:03:39 +00:00
2011-10-16 20:11:59 +00:00
/**
* Tests that it is possible to add charset configuration to a CakeEmail object
*
* @ return void
*/
public function testConfigCharset () {
$email = new CakeEmail ();
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( Configure :: read ( 'App.encoding' ), $email -> charset );
$this -> assertEquals ( Configure :: read ( 'App.encoding' ), $email -> headerCharset );
2011-10-16 20:11:59 +00:00
$email = new CakeEmail ( array ( 'charset' => 'iso-2022-jp' , 'headerCharset' => 'iso-2022-jp-ms' ));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'iso-2022-jp' , $email -> charset );
$this -> assertEquals ( 'iso-2022-jp-ms' , $email -> headerCharset );
2011-10-16 20:11:59 +00:00
$email = new CakeEmail ( array ( 'charset' => 'iso-2022-jp' ));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'iso-2022-jp' , $email -> charset );
$this -> assertEquals ( 'iso-2022-jp' , $email -> headerCharset );
2011-10-16 20:11:59 +00:00
$email = new CakeEmail ( array ( 'headerCharset' => 'iso-2022-jp-ms' ));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( Configure :: read ( 'App.encoding' ), $email -> charset );
$this -> assertEquals ( 'iso-2022-jp-ms' , $email -> headerCharset );
2011-10-16 20:11:59 +00:00
}
/**
* Tests that the header is encoded using the configured headerCharset
*
* @ return void
*/
public function testHeaderEncoding () {
$this -> skipIf ( ! function_exists ( 'mb_convert_encoding' ));
$email = new CakeEmail ( array ( 'headerCharset' => 'iso-2022-jp-ms' , 'transport' => 'Debug' ));
$email -> subject ( 'あれ?もしかしての前と' );
$headers = $email -> getHeaders ( array ( 'subject' ));
$expected = " ?ISO-2022-JP?B?GyRCJCIkbCEpJGIkNyQrJDckRiROQTAkSBsoQg==?= " ;
$this -> assertContains ( $expected , $headers [ 'Subject' ]);
$email -> to ( 'someone@example.com' ) -> from ( 'someone@example.com' );
$result = $email -> send ( 'ってテーブルを作ってやってたらう' );
$this -> assertContains ( 'ってテーブルを作ってやってたらう' , $result [ 'message' ]);
}
/**
* Tests that the body is encoded using the configured charset
*
* @ return void
*/
public function testBodyEncoding () {
$this -> skipIf ( ! function_exists ( 'mb_convert_encoding' ));
$email = new CakeEmail ( array (
'charset' => 'iso-2022-jp' ,
'headerCharset' => 'iso-2022-jp-ms' ,
'transport' => 'Debug'
));
$email -> subject ( 'あれ?もしかしての前と' );
$headers = $email -> getHeaders ( array ( 'subject' ));
$expected = " ?ISO-2022-JP?B?GyRCJCIkbCEpJGIkNyQrJDckRiROQTAkSBsoQg==?= " ;
$this -> assertContains ( $expected , $headers [ 'Subject' ]);
$email -> to ( 'someone@example.com' ) -> from ( 'someone@example.com' );
$result = $email -> send ( 'ってテーブルを作ってやってたらう' );
2012-05-21 10:21:02 +00:00
$this -> assertContains ( 'Content-Type: text/plain; charset=ISO-2022-JP' , $result [ 'headers' ]);
2013-08-07 23:03:21 +00:00
$this -> assertContains ( mb_convert_encoding ( 'ってテーブルを作ってやってたらう' , 'ISO-2022-JP' ), $result [ 'message' ]);
2011-10-16 20:11:59 +00:00
}
2011-10-19 04:49:30 +00:00
2012-05-21 10:21:02 +00:00
/**
* Tests that the body is encoded using the configured charset ( Japanese standard encoding )
*
* @ return void
*/
public function testBodyEncodingIso2022Jp () {
$this -> skipIf ( ! function_exists ( 'mb_convert_encoding' ));
$email = new CakeEmail ( array (
'charset' => 'iso-2022-jp' ,
'headerCharset' => 'iso-2022-jp' ,
'transport' => 'Debug'
));
$email -> subject ( 'あれ?もしかしての前と' );
$headers = $email -> getHeaders ( array ( 'subject' ));
$expected = " ?ISO-2022-JP?B?GyRCJCIkbCEpJGIkNyQrJDckRiROQTAkSBsoQg==?= " ;
$this -> assertContains ( $expected , $headers [ 'Subject' ]);
$email -> to ( 'someone@example.com' ) -> from ( 'someone@example.com' );
$result = $email -> send ( '①㈱' );
$this -> assertTextContains ( " Content-Type: text/plain; charset=ISO-2022-JP " , $result [ 'headers' ]);
$this -> assertTextNotContains ( " Content-Type: text/plain; charset=ISO-2022-JP-MS " , $result [ 'headers' ]); // not charset=iso-2022-jp-ms
2013-08-07 23:03:21 +00:00
$this -> assertTextNotContains ( mb_convert_encoding ( '①㈱' , 'ISO-2022-JP-MS' ), $result [ 'message' ]);
2012-05-21 10:21:02 +00:00
}
/**
* Tests that the body is encoded using the configured charset ( Japanese irregular encoding , but sometime use this )
*
* @ return void
*/
public function testBodyEncodingIso2022JpMs () {
$this -> skipIf ( ! function_exists ( 'mb_convert_encoding' ));
$email = new CakeEmail ( array (
'charset' => 'iso-2022-jp-ms' ,
'headerCharset' => 'iso-2022-jp-ms' ,
'transport' => 'Debug'
));
$email -> subject ( 'あれ?もしかしての前と' );
$headers = $email -> getHeaders ( array ( 'subject' ));
$expected = " ?ISO-2022-JP?B?GyRCJCIkbCEpJGIkNyQrJDckRiROQTAkSBsoQg==?= " ;
$this -> assertContains ( $expected , $headers [ 'Subject' ]);
$email -> to ( 'someone@example.com' ) -> from ( 'someone@example.com' );
$result = $email -> send ( '①㈱' );
$this -> assertTextContains ( " Content-Type: text/plain; charset=ISO-2022-JP " , $result [ 'headers' ]);
$this -> assertTextNotContains ( " Content-Type: text/plain; charset=iso-2022-jp-ms " , $result [ 'headers' ]); // not charset=iso-2022-jp-ms
2013-08-07 23:03:21 +00:00
$this -> assertContains ( mb_convert_encoding ( '①㈱' , 'ISO-2022-JP-MS' ), $result [ 'message' ]);
2012-05-21 10:21:02 +00:00
}
2012-04-09 01:01:25 +00:00
protected function _checkContentTransferEncoding ( $message , $charset ) {
2014-05-13 21:47:11 +00:00
$boundary = '--' . $this -> CakeEmail -> getBoundary ();
2011-10-19 04:49:30 +00:00
$result [ 'text' ] = false ;
$result [ 'html' ] = false ;
2012-04-03 03:19:05 +00:00
$length = count ( $message );
for ( $i = 0 ; $i < $length ; ++ $i ) {
2011-10-19 04:49:30 +00:00
if ( $message [ $i ] == $boundary ) {
$flag = false ;
$type = '' ;
while ( ! preg_match ( '/^$/' , $message [ $i ])) {
if ( preg_match ( '/^Content-Type: text\/plain/' , $message [ $i ])) {
$type = 'text' ;
}
if ( preg_match ( '/^Content-Type: text\/html/' , $message [ $i ])) {
$type = 'html' ;
}
if ( $message [ $i ] === 'Content-Transfer-Encoding: ' . $charset ) {
$flag = true ;
}
++ $i ;
}
$result [ $type ] = $flag ;
}
}
return $result [ 'text' ] && $result [ 'html' ];
}
2011-10-19 15:18:42 +00:00
/**
* Test CakeEmail :: _encode function
*
2012-04-09 01:01:25 +00:00
* @ return void
2011-10-19 15:18:42 +00:00
*/
public function testEncode () {
$this -> skipIf ( ! function_exists ( 'mb_convert_encoding' ));
$this -> CakeEmail -> headerCharset = 'ISO-2022-JP' ;
$result = $this -> CakeEmail -> encode ( '日本語' );
$expected = '=?ISO-2022-JP?B?GyRCRnxLXDhsGyhC?=' ;
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $expected , $result );
2011-10-19 15:18:42 +00:00
$this -> CakeEmail -> headerCharset = 'ISO-2022-JP' ;
$result = $this -> CakeEmail -> encode ( '長い長い長いSubjectの場合はfoldingするのが正しいんだけどいったいどうなるんだろう? ' );
2012-03-17 02:19:01 +00:00
$expected = " =?ISO-2022-JP?B?GyRCRDkkJEQ5JCREOSQkGyhCU3ViamVjdBskQiROPmw5ZyRPGyhCZm9s?= \r \n " .
" =?ISO-2022-JP?B?ZGluZxskQiQ5JGskTiQsQDUkNyQkJHMkQCQxJEkkJCRDJD8kJCRJGyhC?= \r \n " .
" =?ISO-2022-JP?B?GyRCJCYkSiRrJHMkQCRtJCYhKRsoQg==?= " ;
2011-11-16 00:07:56 +00:00
$this -> assertSame ( $expected , $result );
2011-10-19 15:18:42 +00:00
}
2012-03-16 12:54:30 +00:00
/**
* Tests charset setter / getter
*
* @ return void
*/
public function testCharset () {
$this -> CakeEmail -> charset ( 'UTF-8' );
$this -> assertSame ( $this -> CakeEmail -> charset (), 'UTF-8' );
$this -> CakeEmail -> charset ( 'ISO-2022-JP' );
$this -> assertSame ( $this -> CakeEmail -> charset (), 'ISO-2022-JP' );
$charset = $this -> CakeEmail -> charset ( 'Shift_JIS' );
$this -> assertSame ( $charset , 'Shift_JIS' );
}
/**
* Tests headerCharset setter / getter
*
* @ return void
*/
public function testHeaderCharset () {
$this -> CakeEmail -> headerCharset ( 'UTF-8' );
$this -> assertSame ( $this -> CakeEmail -> headerCharset (), 'UTF-8' );
$this -> CakeEmail -> headerCharset ( 'ISO-2022-JP' );
$this -> assertSame ( $this -> CakeEmail -> headerCharset (), 'ISO-2022-JP' );
$charset = $this -> CakeEmail -> headerCharset ( 'Shift_JIS' );
$this -> assertSame ( $charset , 'Shift_JIS' );
}
/**
* Tests for compatible check .
* charset property and charset () method .
* headerCharset property and headerCharset () method .
2014-04-02 01:02:37 +00:00
*
* @ return void
2012-03-16 12:54:30 +00:00
*/
public function testCharsetsCompatible () {
$this -> skipIf ( ! function_exists ( 'mb_convert_encoding' ));
$checkHeaders = array (
'from' => true ,
'to' => true ,
'cc' => true ,
'subject' => true ,
);
// Header Charset : null (used by default UTF-8)
// Body Charset : ISO-2022-JP
$oldStyleEmail = $this -> _getEmailByOldStyleCharset ( 'iso-2022-jp' , null );
$oldStyleHeaders = $oldStyleEmail -> getHeaders ( $checkHeaders );
$newStyleEmail = $this -> _getEmailByNewStyleCharset ( 'iso-2022-jp' , null );
$newStyleHeaders = $newStyleEmail -> getHeaders ( $checkHeaders );
2012-11-21 14:39:03 +00:00
$this -> assertSame ( $oldStyleHeaders [ 'From' ], $newStyleHeaders [ 'From' ]);
$this -> assertSame ( $oldStyleHeaders [ 'To' ], $newStyleHeaders [ 'To' ]);
$this -> assertSame ( $oldStyleHeaders [ 'Cc' ], $newStyleHeaders [ 'Cc' ]);
2012-03-16 12:54:30 +00:00
$this -> assertSame ( $oldStyleHeaders [ 'Subject' ], $newStyleHeaders [ 'Subject' ]);
// Header Charset : UTF-8
// Boby Charset : ISO-2022-JP
$oldStyleEmail = $this -> _getEmailByOldStyleCharset ( 'iso-2022-jp' , 'utf-8' );
$oldStyleHeaders = $oldStyleEmail -> getHeaders ( $checkHeaders );
$newStyleEmail = $this -> _getEmailByNewStyleCharset ( 'iso-2022-jp' , 'utf-8' );
$newStyleHeaders = $newStyleEmail -> getHeaders ( $checkHeaders );
2012-11-21 14:39:03 +00:00
$this -> assertSame ( $oldStyleHeaders [ 'From' ], $newStyleHeaders [ 'From' ]);
$this -> assertSame ( $oldStyleHeaders [ 'To' ], $newStyleHeaders [ 'To' ]);
$this -> assertSame ( $oldStyleHeaders [ 'Cc' ], $newStyleHeaders [ 'Cc' ]);
2012-03-16 12:54:30 +00:00
$this -> assertSame ( $oldStyleHeaders [ 'Subject' ], $newStyleHeaders [ 'Subject' ]);
// Header Charset : ISO-2022-JP
// Boby Charset : UTF-8
$oldStyleEmail = $this -> _getEmailByOldStyleCharset ( 'utf-8' , 'iso-2022-jp' );
$oldStyleHeaders = $oldStyleEmail -> getHeaders ( $checkHeaders );
$newStyleEmail = $this -> _getEmailByNewStyleCharset ( 'utf-8' , 'iso-2022-jp' );
$newStyleHeaders = $newStyleEmail -> getHeaders ( $checkHeaders );
2012-11-21 14:39:03 +00:00
$this -> assertSame ( $oldStyleHeaders [ 'From' ], $newStyleHeaders [ 'From' ]);
$this -> assertSame ( $oldStyleHeaders [ 'To' ], $newStyleHeaders [ 'To' ]);
$this -> assertSame ( $oldStyleHeaders [ 'Cc' ], $newStyleHeaders [ 'Cc' ]);
2012-03-16 12:54:30 +00:00
$this -> assertSame ( $oldStyleHeaders [ 'Subject' ], $newStyleHeaders [ 'Subject' ]);
}
2014-04-02 01:02:37 +00:00
/**
* @ param mixed $charset
* @ param mixed $headerCharset
* @ return CakeEmail
*/
2012-04-03 03:19:05 +00:00
protected function _getEmailByOldStyleCharset ( $charset , $headerCharset ) {
2012-03-16 12:54:30 +00:00
$email = new CakeEmail ( array ( 'transport' => 'Debug' ));
if ( ! empty ( $charset )) {
$email -> charset = $charset ;
}
if ( ! empty ( $headerCharset )) {
$email -> headerCharset = $headerCharset ;
}
$email -> from ( 'someone@example.com' , 'どこかの誰か' );
$email -> to ( 'someperson@example.jp' , 'どこかのどなたか' );
$email -> cc ( 'miku@example.net' , 'ミク' );
$email -> subject ( 'テストメール' );
$email -> send ( 'テストメールの本文' );
return $email ;
}
2014-04-02 01:02:37 +00:00
/**
* @ param mixed $charset
* @ param mixed $headerCharset
* @ return CakeEmail
*/
2012-04-03 03:19:05 +00:00
protected function _getEmailByNewStyleCharset ( $charset , $headerCharset ) {
2012-03-16 12:54:30 +00:00
$email = new CakeEmail ( array ( 'transport' => 'Debug' ));
if ( ! empty ( $charset )) {
$email -> charset ( $charset );
}
if ( ! empty ( $headerCharset )) {
$email -> headerCharset ( $headerCharset );
}
$email -> from ( 'someone@example.com' , 'どこかの誰か' );
$email -> to ( 'someperson@example.jp' , 'どこかのどなたか' );
$email -> cc ( 'miku@example.net' , 'ミク' );
$email -> subject ( 'テストメール' );
$email -> send ( 'テストメールの本文' );
return $email ;
}
2014-04-02 01:02:37 +00:00
/**
* testWrapLongLine ()
*
* @ return void
*/
2013-05-21 01:50:46 +00:00
public function testWrapLongLine () {
$message = '<a href="http://cakephp.org">' . str_repeat ( 'x' , CakeEmail :: LINE_LENGTH_MUST ) . " </a> " ;
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'Debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( 'cake@cakephp.org' );
$this -> CakeEmail -> subject ( 'Wordwrap Test' );
$this -> CakeEmail -> config ( array ( 'empty' ));
$result = $this -> CakeEmail -> send ( $message );
2013-05-23 16:34:39 +00:00
$expected = " <a \r \n " . 'href="http://cakephp.org">' . str_repeat ( 'x' , CakeEmail :: LINE_LENGTH_MUST - 26 ) . " \r \n " .
str_repeat ( 'x' , 26 ) . " \r \n </a> \r \n \r \n " ;
2013-05-21 01:50:46 +00:00
$this -> assertEquals ( $expected , $result [ 'message' ]);
2013-05-23 16:34:39 +00:00
$this -> assertLineLengths ( $result [ 'message' ]);
2013-05-21 01:50:46 +00:00
$str1 = " a " ;
$str2 = " b " ;
2013-05-23 16:34:39 +00:00
$length = strlen ( $str1 ) + strlen ( $str2 );
$message = $str1 . str_repeat ( 'x' , CakeEmail :: LINE_LENGTH_MUST - $length - 1 ) . $str2 ;
2013-05-21 01:50:46 +00:00
$result = $this -> CakeEmail -> send ( $message );
$expected = " { $message } \r \n \r \n " ;
$this -> assertEquals ( $expected , $result [ 'message' ]);
2013-05-23 16:34:39 +00:00
$this -> assertLineLengths ( $result [ 'message' ]);
2013-05-21 01:50:46 +00:00
2013-05-23 16:34:39 +00:00
$message = $str1 . str_repeat ( 'x' , CakeEmail :: LINE_LENGTH_MUST - $length ) . $str2 ;
2013-05-21 01:50:46 +00:00
$result = $this -> CakeEmail -> send ( $message );
$expected = " { $message } \r \n \r \n " ;
$this -> assertEquals ( $expected , $result [ 'message' ]);
2013-05-23 16:34:39 +00:00
$this -> assertLineLengths ( $result [ 'message' ]);
2013-05-21 01:50:46 +00:00
2013-05-23 16:34:39 +00:00
$message = $str1 . str_repeat ( 'x' , CakeEmail :: LINE_LENGTH_MUST - $length + 1 ) . $str2 ;
2013-05-21 01:50:46 +00:00
$result = $this -> CakeEmail -> send ( $message );
2013-05-23 16:34:39 +00:00
$expected = $str1 . str_repeat ( 'x' , CakeEmail :: LINE_LENGTH_MUST - $length + 1 ) . sprintf ( " \r \n %s \r \n \r \n " , trim ( $str2 ));
2013-05-21 01:50:46 +00:00
$this -> assertEquals ( $expected , $result [ 'message' ]);
2013-05-23 16:34:39 +00:00
$this -> assertLineLengths ( $result [ 'message' ]);
}
2013-05-21 01:50:46 +00:00
2014-04-02 01:02:37 +00:00
/**
* testWrapWithTagsAcrossLines ()
*
* @ return void
*/
2013-05-23 16:34:39 +00:00
public function testWrapWithTagsAcrossLines () {
$str = <<< HTML
< table >
< th align = " right " valign = " top "
style = " font-weight: bold " > The tag is across multiple lines </ th >
</ table >
HTML ;
$length = strlen ( $str );
$message = $str . str_repeat ( 'x' , CakeEmail :: LINE_LENGTH_MUST + 1 );
2013-05-21 01:50:46 +00:00
2013-05-23 16:34:39 +00:00
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'Debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( 'cake@cakephp.org' );
$this -> CakeEmail -> subject ( 'Wordwrap Test' );
$this -> CakeEmail -> config ( array ( 'empty' ));
2013-05-21 01:50:46 +00:00
$result = $this -> CakeEmail -> send ( $message );
2013-05-23 16:34:39 +00:00
$message = str_replace ( " \r \n " , " \n " , substr ( $message , 0 , - 9 ));
$message = str_replace ( " \n " , " \r \n " , $message );
$expected = " { $message } \r \n xxxxxxxxx \r \n \r \n " ;
2013-05-21 01:50:46 +00:00
$this -> assertEquals ( $expected , $result [ 'message' ]);
2013-05-23 16:34:39 +00:00
$this -> assertLineLengths ( $result [ 'message' ]);
2013-05-21 01:50:46 +00:00
}
2014-04-02 01:02:37 +00:00
/**
* CakeEmailTest :: testWrapIncludeLessThanSign ()
*
* @ return void
*/
2013-05-21 01:50:46 +00:00
public function testWrapIncludeLessThanSign () {
$str = 'foo<bar' ;
2013-05-23 16:34:39 +00:00
$length = strlen ( $str );
$message = $str . str_repeat ( 'x' , CakeEmail :: LINE_LENGTH_MUST - $length + 1 );
2013-05-21 01:50:46 +00:00
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'Debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( 'cake@cakephp.org' );
$this -> CakeEmail -> subject ( 'Wordwrap Test' );
$this -> CakeEmail -> config ( array ( 'empty' ));
$result = $this -> CakeEmail -> send ( $message );
2013-05-23 16:34:39 +00:00
$message = substr ( $message , 0 , - 1 );
$expected = " { $message } \r \n x \r \n \r \n " ;
2013-05-21 01:50:46 +00:00
$this -> assertEquals ( $expected , $result [ 'message' ]);
2013-05-23 16:34:39 +00:00
$this -> assertLineLengths ( $result [ 'message' ]);
2013-05-21 01:50:46 +00:00
}
2014-04-02 01:02:37 +00:00
/**
* CakeEmailTest :: testWrapForJapaneseEncoding ()
*
* @ return void
*/
2013-05-21 01:50:46 +00:00
public function testWrapForJapaneseEncoding () {
$this -> skipIf ( ! function_exists ( 'mb_convert_encoding' ));
$message = mb_convert_encoding ( '受け付けました' , 'iso-2022-jp' , 'UTF-8' );
$this -> CakeEmail -> reset ();
$this -> CakeEmail -> transport ( 'Debug' );
$this -> CakeEmail -> from ( 'cake@cakephp.org' );
$this -> CakeEmail -> to ( 'cake@cakephp.org' );
$this -> CakeEmail -> subject ( 'Wordwrap Test' );
$this -> CakeEmail -> config ( array ( 'empty' ));
$this -> CakeEmail -> charset ( 'iso-2022-jp' );
$this -> CakeEmail -> headerCharset ( 'iso-2022-jp' );
$result = $this -> CakeEmail -> send ( $message );
$expected = " { $message } \r \n \r \n " ;
$this -> assertEquals ( $expected , $result [ 'message' ]);
}
2013-05-23 16:34:39 +00:00
/**
* CakeEmailTest :: assertLineLengths ()
*
* @ param string $message
* @ return void
*/
public function assertLineLengths ( $message ) {
$lines = explode ( " \r \n " , $message );
foreach ( $lines as $line ) {
$this -> assertTrue ( strlen ( $line ) <= CakeEmail :: LINE_LENGTH_MUST ,
2013-05-28 01:25:52 +00:00
'Line length exceeds the max. limit of CakeEmail::LINE_LENGTH_MUST' );
2013-05-23 16:34:39 +00:00
}
}
2011-02-27 18:25:23 +00:00
}