mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
Adjust partial of test case for EmailComponent.
This commit is contained in:
parent
0bf8e3483b
commit
b2f948dfeb
1 changed files with 117 additions and 116 deletions
|
@ -20,6 +20,7 @@
|
|||
*/
|
||||
App::uses('Controller', 'Controller');
|
||||
App::uses('EmailComponent', 'Controller/Component');
|
||||
App::uses('AbstractTransport', 'Network/Email');
|
||||
|
||||
/**
|
||||
* EmailTestComponent class
|
||||
|
@ -40,6 +41,49 @@ class EmailTestComponent extends EmailComponent {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* DebugCompTransport class
|
||||
*
|
||||
* @package cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class DebugCompTransport extends AbstractTransport {
|
||||
|
||||
/**
|
||||
* Last email
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $lastEmail = null;
|
||||
|
||||
/**
|
||||
* Send mail
|
||||
*
|
||||
* @params object $email CakeEmail
|
||||
* @return boolean
|
||||
*/
|
||||
public function send(CakeEmail $email) {
|
||||
$headers = $email->getHeaders(array_fill_keys(array('from', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject'), true));
|
||||
$to = $headers['To'];
|
||||
$subject = $headers['Subject'];
|
||||
unset($headers['To'], $headers['Subject']);
|
||||
|
||||
$message = implode("\n", $email->message());
|
||||
|
||||
$last = '<pre>';
|
||||
$last .= sprintf("%s %s\n", 'To:', $to);
|
||||
$last .= sprintf("%s %s\n", 'From:', $headers['From']);
|
||||
$last .= sprintf("%s %s\n", 'Subject:', $subject);
|
||||
$last .= sprintf("%s\n\n%s", 'Header:', $this->_headersToString($headers, "\n"));
|
||||
$last .= sprintf("%s\n\n%s", 'Message:', $message);
|
||||
$last .= '</pre>';
|
||||
|
||||
self::$lastEmail = $last;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* EmailTestController class
|
||||
*
|
||||
|
@ -71,13 +115,6 @@ class EmailTestController extends Controller {
|
|||
*/
|
||||
public $components = array('Session', 'EmailTest');
|
||||
|
||||
/**
|
||||
* pageTitle property
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
public $pageTitle = 'EmailTest';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -134,7 +171,6 @@ class EmailComponentTest extends CakeTestCase {
|
|||
function tearDown() {
|
||||
Configure::write('App.encoding', $this->_appEncoding);
|
||||
App::build();
|
||||
$this->Controller->Session->delete('Message');
|
||||
ClassRegistry::flush();
|
||||
}
|
||||
|
||||
|
@ -156,50 +192,48 @@ class EmailComponentTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testSendFormats() {
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->subject = 'Cake SMTP test';
|
||||
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->template = null;
|
||||
$this->Controller->EmailTest->delivery = 'debug';
|
||||
$this->Controller->EmailTest->delivery = 'DebugComp';
|
||||
$this->Controller->EmailTest->messageId = false;
|
||||
|
||||
$date = date(DATE_RFC2822);
|
||||
$message = <<<MSGBLOC
|
||||
<pre>To: postmaster@localhost
|
||||
<pre>To: postmaster@example.com
|
||||
From: noreply@example.com
|
||||
Subject: Cake SMTP test
|
||||
Header:
|
||||
|
||||
From: noreply@example.com
|
||||
Reply-To: noreply@example.com
|
||||
Date: $date
|
||||
X-Mailer: CakePHP Email Component
|
||||
Date: $date
|
||||
Content-Type: {CONTENTTYPE}
|
||||
Content-Transfer-Encoding: 7bitParameters:
|
||||
|
||||
Message:
|
||||
Content-Transfer-Encoding: 7bitMessage:
|
||||
|
||||
This is the body of the message
|
||||
|
||||
</pre>
|
||||
MSGBLOC;
|
||||
|
||||
$this->Controller->EmailTest->sendAs = 'text';
|
||||
$expect = str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $message);
|
||||
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
||||
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
||||
$this->assertEqual(DebugCompTransport::$lastEmail, $this->__osFix($expect));
|
||||
|
||||
$this->Controller->EmailTest->sendAs = 'html';
|
||||
$expect = str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $message);
|
||||
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
||||
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
||||
$this->assertEqual(DebugCompTransport::$lastEmail, $this->__osFix($expect));
|
||||
|
||||
// TODO: better test for format of message sent?
|
||||
$this->Controller->EmailTest->sendAs = 'both';
|
||||
$expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"', $message);
|
||||
|
||||
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
||||
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
||||
$this->assertEqual(DebugCompTransport::$lastEmail, $this->__osFix($expect));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -211,29 +245,27 @@ MSGBLOC;
|
|||
function testTemplates() {
|
||||
ClassRegistry::flush();
|
||||
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->subject = 'Cake SMTP test';
|
||||
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
||||
|
||||
$this->Controller->EmailTest->delivery = 'debug';
|
||||
$this->Controller->EmailTest->delivery = 'DebugComp';
|
||||
$this->Controller->EmailTest->messageId = false;
|
||||
|
||||
$date = date(DATE_RFC2822);
|
||||
$header = <<<HEADBLOC
|
||||
To: postmaster@localhost
|
||||
To: postmaster@example.com
|
||||
From: noreply@example.com
|
||||
Subject: Cake SMTP test
|
||||
Header:
|
||||
|
||||
From: noreply@example.com
|
||||
Reply-To: noreply@example.com
|
||||
Date: $date
|
||||
X-Mailer: CakePHP Email Component
|
||||
Date: $date
|
||||
Content-Type: {CONTENTTYPE}
|
||||
Content-Transfer-Encoding: 7bitParameters:
|
||||
|
||||
Message:
|
||||
Content-Transfer-Encoding: 7bitMessage:
|
||||
|
||||
|
||||
HEADBLOC;
|
||||
|
@ -266,12 +298,12 @@ HTMLBLOC;
|
|||
$this->Controller->EmailTest->sendAs = 'text';
|
||||
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $header) . $text . "\n" . '</pre>';
|
||||
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
||||
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
||||
$this->assertEqual(DebugCompTransport::$lastEmail, $this->__osFix($expect));
|
||||
|
||||
$this->Controller->EmailTest->sendAs = 'html';
|
||||
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . "\n" . '</pre>';
|
||||
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
||||
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
||||
$this->assertEqual(DebugCompTransport::$lastEmail, $this->__osFix($expect));
|
||||
|
||||
$this->Controller->EmailTest->sendAs = 'both';
|
||||
$expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"', $header);
|
||||
|
@ -280,7 +312,7 @@ HTMLBLOC;
|
|||
$expect = '<pre>' . $expect . '--alt---' . "\n\n" . '</pre>';
|
||||
|
||||
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
||||
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
||||
$this->assertEqual(DebugCompTransport::$lastEmail, $this->__osFix($expect));
|
||||
|
||||
$html = <<<HTMLBLOC
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
||||
|
@ -301,7 +333,7 @@ HTMLBLOC;
|
|||
$this->Controller->EmailTest->sendAs = 'html';
|
||||
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . '</pre>';
|
||||
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message', 'default', 'thin'));
|
||||
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
||||
$this->assertEqual(DebugCompTransport::$lastEmail, $this->__osFix($expect));
|
||||
|
||||
$result = ClassRegistry::getObject('view');
|
||||
$this->assertFalse($result);
|
||||
|
@ -313,12 +345,12 @@ HTMLBLOC;
|
|||
* @return void
|
||||
*/
|
||||
function testTemplateNestedElements() {
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->subject = 'Cake SMTP test';
|
||||
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
||||
|
||||
$this->Controller->EmailTest->delivery = 'debug';
|
||||
$this->Controller->EmailTest->delivery = 'DebugComp';
|
||||
$this->Controller->EmailTest->messageId = false;
|
||||
$this->Controller->EmailTest->layout = 'default';
|
||||
$this->Controller->EmailTest->template = 'nested_element';
|
||||
|
@ -326,7 +358,7 @@ HTMLBLOC;
|
|||
$this->Controller->helpers = array('Html');
|
||||
|
||||
$this->Controller->EmailTest->send();
|
||||
$result = $this->Controller->Session->read('Message.email.message');
|
||||
$result = DebugCompTransport::$lastEmail;
|
||||
$this->assertPattern('/Test/', $result);
|
||||
$this->assertPattern('/http\:\/\/example\.com/', $result);
|
||||
}
|
||||
|
@ -338,7 +370,7 @@ HTMLBLOC;
|
|||
* @return void
|
||||
*/
|
||||
function testSendDebug() {
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->cc = 'cc@example.com';
|
||||
$this->Controller->EmailTest->bcc = 'bcc@example.com';
|
||||
|
@ -346,11 +378,11 @@ HTMLBLOC;
|
|||
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->template = null;
|
||||
|
||||
$this->Controller->EmailTest->delivery = 'debug';
|
||||
$this->Controller->EmailTest->delivery = 'DebugComp';
|
||||
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
||||
$result = $this->Controller->Session->read('Message.email.message');
|
||||
$result = DebugCompTransport::$lastEmail;
|
||||
|
||||
$this->assertPattern('/To: postmaster@localhost\n/', $result);
|
||||
$this->assertPattern('/To: postmaster@example.com\n/', $result);
|
||||
$this->assertPattern('/Subject: Cake Debug Test\n/', $result);
|
||||
$this->assertPattern('/Reply-To: noreply@example.com\n/', $result);
|
||||
$this->assertPattern('/From: noreply@example.com\n/', $result);
|
||||
|
@ -359,7 +391,7 @@ HTMLBLOC;
|
|||
$this->assertPattern('/Date: ' . preg_quote(date(DATE_RFC2822)) . '\n/', $result);
|
||||
$this->assertPattern('/X-Mailer: CakePHP Email Component\n/', $result);
|
||||
$this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
|
||||
$this->assertPattern('/Content-Transfer-Encoding: 7bitParameters:\n/', $result);
|
||||
$this->assertPattern('/Content-Transfer-Encoding: 7bitMessage:\n/', $result);
|
||||
$this->assertPattern('/This is the body of the message/', $result);
|
||||
}
|
||||
|
||||
|
@ -371,23 +403,24 @@ HTMLBLOC;
|
|||
function testSendDebugWithNoSessions() {
|
||||
$session = $this->Controller->Session;
|
||||
unset($this->Controller->Session);
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->subject = 'Cake Debug Test';
|
||||
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->template = null;
|
||||
|
||||
$this->Controller->EmailTest->delivery = 'debug';
|
||||
$result = $this->Controller->EmailTest->send('This is the body of the message');
|
||||
$this->Controller->EmailTest->delivery = 'DebugComp';
|
||||
$this->Controller->EmailTest->send('This is the body of the message');
|
||||
$result = DebugCompTransport::$lastEmail;
|
||||
|
||||
$this->assertPattern('/To: postmaster@localhost\n/', $result);
|
||||
$this->assertPattern('/To: postmaster@example.com\n/', $result);
|
||||
$this->assertPattern('/Subject: Cake Debug Test\n/', $result);
|
||||
$this->assertPattern('/Reply-To: noreply@example.com\n/', $result);
|
||||
$this->assertPattern('/From: noreply@example.com\n/', $result);
|
||||
$this->assertPattern('/Date: ' . preg_quote(date(DATE_RFC2822)) . '\n/', $result);
|
||||
$this->assertPattern('/X-Mailer: CakePHP Email Component\n/', $result);
|
||||
$this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
|
||||
$this->assertPattern('/Content-Transfer-Encoding: 7bitParameters:\n/', $result);
|
||||
$this->assertPattern('/Content-Transfer-Encoding: 7bitMessage:\n/', $result);
|
||||
$this->assertPattern('/This is the body of the message/', $result);
|
||||
$this->Controller->Session = $session;
|
||||
}
|
||||
|
@ -403,14 +436,14 @@ HTMLBLOC;
|
|||
'View' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'View'. DS)
|
||||
));
|
||||
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->subject = 'Cake Debug Test';
|
||||
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->layout = 'default';
|
||||
$this->Controller->EmailTest->template = null;
|
||||
|
||||
$this->Controller->EmailTest->delivery = 'debug';
|
||||
$this->Controller->EmailTest->delivery = 'DebugComp';
|
||||
|
||||
$text = $html = 'This is the body of the message';
|
||||
|
||||
|
@ -444,14 +477,14 @@ HTMLBLOC;
|
|||
$this->Controller->set('value', 22091985);
|
||||
$this->Controller->set('title_for_layout', 'EmailTest');
|
||||
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->subject = 'Cake Debug Test';
|
||||
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->layout = 'default';
|
||||
$this->Controller->EmailTest->template = 'custom';
|
||||
|
||||
$this->Controller->EmailTest->delivery = 'debug';
|
||||
$this->Controller->EmailTest->delivery = 'DebugComp';
|
||||
|
||||
$text = <<<TEXTBLOC
|
||||
|
||||
|
@ -497,24 +530,24 @@ HTMLBLOC;
|
|||
* @return void
|
||||
*/
|
||||
function testSendContentArray() {
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->subject = 'Cake Debug Test';
|
||||
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->template = null;
|
||||
$this->Controller->EmailTest->delivery = 'debug';
|
||||
$this->Controller->EmailTest->delivery = 'DebugComp';
|
||||
|
||||
$content = array('First line', 'Second line', 'Third line');
|
||||
$this->assertTrue($this->Controller->EmailTest->send($content));
|
||||
$result = $this->Controller->Session->read('Message.email.message');
|
||||
$result = DebugCompTransport::$lastEmail;
|
||||
|
||||
$this->assertPattern('/To: postmaster@localhost\n/', $result);
|
||||
$this->assertPattern('/To: postmaster@example.com\n/', $result);
|
||||
$this->assertPattern('/Subject: Cake Debug Test\n/', $result);
|
||||
$this->assertPattern('/Reply-To: noreply@example.com\n/', $result);
|
||||
$this->assertPattern('/From: noreply@example.com\n/', $result);
|
||||
$this->assertPattern('/X-Mailer: CakePHP Email Component\n/', $result);
|
||||
$this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
|
||||
$this->assertPattern('/Content-Transfer-Encoding: 7bitParameters:\n/', $result);
|
||||
$this->assertPattern('/Content-Transfer-Encoding: 7bitMessage:\n/', $result);
|
||||
$this->assertPattern('/First line\n/', $result);
|
||||
$this->assertPattern('/Second line\n/', $result);
|
||||
$this->assertPattern('/Third line\n/', $result);
|
||||
|
@ -526,15 +559,15 @@ HTMLBLOC;
|
|||
* @return void
|
||||
*/
|
||||
function testDateProperty() {
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->subject = 'Cake Debug Test';
|
||||
$this->Controller->EmailTest->date = 'Today!';
|
||||
$this->Controller->EmailTest->template = null;
|
||||
$this->Controller->EmailTest->delivery = 'debug';
|
||||
$this->Controller->EmailTest->delivery = 'DebugComp';
|
||||
|
||||
$this->assertTrue($this->Controller->EmailTest->send('test message'));
|
||||
$result = $this->Controller->Session->read('Message.email.message');
|
||||
$result = DebugCompTransport::$lastEmail;
|
||||
$this->assertPattern('/Date: Today!\n/', $result);
|
||||
}
|
||||
|
||||
|
@ -578,19 +611,19 @@ HTMLBLOC;
|
|||
mb_internal_encoding('ISO-8859-1');
|
||||
|
||||
$this->Controller->charset = 'UTF-8';
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->subject = 'هذه رسالة بعنوان طويل مرسل للمستلم';
|
||||
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->template = null;
|
||||
$this->Controller->EmailTest->delivery = 'debug';
|
||||
$this->Controller->EmailTest->delivery = 'DebugComp';
|
||||
|
||||
$this->Controller->EmailTest->sendAs = 'text';
|
||||
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
||||
|
||||
$subject = '=?UTF-8?B?2YfYsNmHINix2LPYp9mE2Kkg2KjYudmG2YjYp9mGINi32YjZitmEINmF2LE=?=' . "\r\n" . ' =?UTF-8?B?2LPZhCDZhNmE2YXYs9iq2YTZhQ==?=';
|
||||
|
||||
preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches);
|
||||
preg_match('/Subject: (.*)Header:/s', DebugCompTransport::$lastEmail, $matches);
|
||||
$this->assertEqual(trim($matches[1]), $subject);
|
||||
|
||||
$result = mb_internal_encoding();
|
||||
|
@ -607,28 +640,28 @@ HTMLBLOC;
|
|||
*/
|
||||
function testMultibyte() {
|
||||
$this->Controller->charset = 'UTF-8';
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->subject = 'هذه رسالة بعنوان طويل مرسل للمستلم';
|
||||
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->template = null;
|
||||
$this->Controller->EmailTest->delivery = 'debug';
|
||||
$this->Controller->EmailTest->delivery = 'DebugComp';
|
||||
|
||||
$subject = '=?UTF-8?B?2YfYsNmHINix2LPYp9mE2Kkg2KjYudmG2YjYp9mGINi32YjZitmEINmF2LE=?=' . "\r\n" . ' =?UTF-8?B?2LPZhCDZhNmE2YXYs9iq2YTZhQ==?=';
|
||||
|
||||
$this->Controller->EmailTest->sendAs = 'text';
|
||||
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
||||
preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches);
|
||||
preg_match('/Subject: (.*)Header:/s', DebugCompTransport::$lastEmail, $matches);
|
||||
$this->assertEqual(trim($matches[1]), $subject);
|
||||
|
||||
$this->Controller->EmailTest->sendAs = 'html';
|
||||
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
||||
preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches);
|
||||
preg_match('/Subject: (.*)Header:/s', DebugCompTransport::$lastEmail, $matches);
|
||||
$this->assertEqual(trim($matches[1]), $subject);
|
||||
|
||||
$this->Controller->EmailTest->sendAs = 'both';
|
||||
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
||||
preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches);
|
||||
preg_match('/Subject: (.*)Header:/s', DebugCompTransport::$lastEmail, $matches);
|
||||
$this->assertEqual(trim($matches[1]), $subject);
|
||||
}
|
||||
|
||||
|
@ -638,12 +671,12 @@ HTMLBLOC;
|
|||
* @return void
|
||||
*/
|
||||
public function testSendWithAttachments() {
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->subject = 'Attachment Test';
|
||||
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->template = null;
|
||||
$this->Controller->EmailTest->delivery = 'debug';
|
||||
$this->Controller->EmailTest->delivery = 'DebugComp';
|
||||
$this->Controller->EmailTest->attachments = array(
|
||||
__FILE__,
|
||||
'some-name.php' => __FILE__
|
||||
|
@ -652,7 +685,7 @@ HTMLBLOC;
|
|||
|
||||
$this->Controller->EmailTest->sendAs = 'text';
|
||||
$this->assertTrue($this->Controller->EmailTest->send($body));
|
||||
$msg = $this->Controller->Session->read('Message.email.message');
|
||||
$msg = DebugCompTransport::$lastEmail;
|
||||
$this->assertPattern('/' . preg_quote('Content-Disposition: attachment; filename="EmailComponentTest.php"') . '/', $msg);
|
||||
$this->assertPattern('/' . preg_quote('Content-Disposition: attachment; filename="some-name.php"') . '/', $msg);
|
||||
}
|
||||
|
@ -663,30 +696,30 @@ HTMLBLOC;
|
|||
* @return void
|
||||
*/
|
||||
public function testSendAsIsNotIgnoredIfAttachmentsPresent() {
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->subject = 'Attachment Test';
|
||||
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->template = null;
|
||||
$this->Controller->EmailTest->delivery = 'debug';
|
||||
$this->Controller->EmailTest->delivery = 'DebugComp';
|
||||
$this->Controller->EmailTest->attachments = array(__FILE__);
|
||||
$body = '<p>This is the body of the message</p>';
|
||||
|
||||
$this->Controller->EmailTest->sendAs = 'html';
|
||||
$this->assertTrue($this->Controller->EmailTest->send($body));
|
||||
$msg = $this->Controller->Session->read('Message.email.message');
|
||||
$msg = DebugCompTransport::$lastEmail;
|
||||
$this->assertNoPattern('/text\/plain/', $msg);
|
||||
$this->assertPattern('/text\/html/', $msg);
|
||||
|
||||
$this->Controller->EmailTest->sendAs = 'text';
|
||||
$this->assertTrue($this->Controller->EmailTest->send($body));
|
||||
$msg = $this->Controller->Session->read('Message.email.message');
|
||||
$msg = DebugCompTransport::$lastEmail;
|
||||
$this->assertPattern('/text\/plain/', $msg);
|
||||
$this->assertNoPattern('/text\/html/', $msg);
|
||||
|
||||
$this->Controller->EmailTest->sendAs = 'both';
|
||||
$this->assertTrue($this->Controller->EmailTest->send($body));
|
||||
$msg = $this->Controller->Session->read('Message.email.message');
|
||||
$msg = DebugCompTransport::$lastEmail;
|
||||
|
||||
$this->assertNoPattern('/text\/plain/', $msg);
|
||||
$this->assertNoPattern('/text\/html/', $msg);
|
||||
|
@ -699,17 +732,17 @@ HTMLBLOC;
|
|||
* @return void
|
||||
*/
|
||||
public function testNoDoubleNewlinesInHeaders() {
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->subject = 'Attachment Test';
|
||||
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->template = null;
|
||||
$this->Controller->EmailTest->delivery = 'debug';
|
||||
$this->Controller->EmailTest->delivery = 'DebugComp';
|
||||
$body = '<p>This is the body of the message</p>';
|
||||
|
||||
$this->Controller->EmailTest->sendAs = 'both';
|
||||
$this->assertTrue($this->Controller->EmailTest->send($body));
|
||||
$msg = $this->Controller->Session->read('Message.email.message');
|
||||
$msg = DebugCompTransport::$lastEmail;
|
||||
|
||||
$this->assertNoPattern('/\n\nContent-Transfer-Encoding/', $msg);
|
||||
$this->assertPattern('/\nContent-Transfer-Encoding/', $msg);
|
||||
|
@ -773,14 +806,14 @@ HTMLBLOC;
|
|||
|
||||
$this->Controller->view = 'TestPlugin.Email';
|
||||
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->subject = 'CustomViewClass test';
|
||||
$this->Controller->EmailTest->delivery = 'debug';
|
||||
$this->Controller->EmailTest->delivery = 'DebugComp';
|
||||
$body = 'Body of message';
|
||||
|
||||
$this->assertTrue($this->Controller->EmailTest->send($body));
|
||||
$result = $this->Controller->Session->read('Message.email.message');
|
||||
$result = DebugCompTransport::$lastEmail;
|
||||
|
||||
$this->assertPattern('/Body of message/', $result);
|
||||
|
||||
|
@ -803,63 +836,31 @@ HTMLBLOC;
|
|||
* @return void
|
||||
*/
|
||||
function testMessageId() {
|
||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->subject = 'Cake Debug Test';
|
||||
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
||||
$this->Controller->EmailTest->template = null;
|
||||
|
||||
$this->Controller->EmailTest->delivery = 'debug';
|
||||
$this->Controller->EmailTest->delivery = 'DebugComp';
|
||||
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
||||
$result = $this->Controller->Session->read('Message.email.message');
|
||||
$result = DebugCompTransport::$lastEmail;
|
||||
|
||||
$this->assertPattern('/Message-ID: \<[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}@' . env('HTTP_HOST') . '\>\n/', $result);
|
||||
|
||||
$this->Controller->EmailTest->messageId = '<22091985.998877@localhost>';
|
||||
$this->Controller->EmailTest->messageId = '<22091985.998877@example.com>';
|
||||
|
||||
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
||||
$result = $this->Controller->Session->read('Message.email.message');
|
||||
$result = DebugCompTransport::$lastEmail;
|
||||
|
||||
$this->assertPattern('/Message-ID: <22091985.998877@localhost>\n/', $result);
|
||||
$this->assertPattern('/Message-ID: <22091985.998877@example.com>\n/', $result);
|
||||
|
||||
$this->Controller->EmailTest->messageId = false;
|
||||
|
||||
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
||||
$result = $this->Controller->Session->read('Message.email.message');
|
||||
$result = DebugCompTransport::$lastEmail;
|
||||
|
||||
$this->assertNoPattern('/Message-ID:/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSendMessage method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSendMessage() {
|
||||
$this->Controller->EmailTest->delivery = 'getMessage';
|
||||
$this->Controller->EmailTest->lineLength = 70;
|
||||
|
||||
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
|
||||
$this->Controller->EmailTest->sendAs = 'text';
|
||||
$result = $this->Controller->EmailTest->send($text);
|
||||
$expected = array(
|
||||
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do',
|
||||
'eiusmod tempor incididunt ut labore et dolore magna aliqua.',
|
||||
'',
|
||||
''
|
||||
);
|
||||
$this->assertEqual($expected, $result);
|
||||
|
||||
$text = 'Lorem ipsum dolor sit amet, <b>consectetur</b> adipisicing elit, sed do <span>eiusmod tempor</span> incididunt ut labore et dolore magna aliqua.';
|
||||
$this->Controller->EmailTest->sendAs = 'html';
|
||||
$result = $this->Controller->EmailTest->send($text);
|
||||
$expected = array(
|
||||
$text,
|
||||
'',
|
||||
''
|
||||
);
|
||||
$this->assertEqual($expected, $result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue