Skip to content

Commit

Permalink
fixing test to ensure tests dont fail on 1 second timestamp diff
Browse files Browse the repository at this point in the history
  • Loading branch information
ceeram committed Nov 22, 2011
1 parent 7d6637f commit f57c287
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/Cake/Test/Case/Controller/Component/EmailComponentTest.php
Expand Up @@ -61,6 +61,7 @@ class DebugCompTransport extends AbstractTransport {
* @return boolean
*/
public function send(CakeEmail $email) {
$email->addHeaders(array('Date' => EmailComponentTest::$sentDate));
$headers = $email->getHeaders(array_fill_keys(array('from', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject'), true));
$to = $headers['To'];
$subject = $headers['Subject'];
Expand Down Expand Up @@ -134,6 +135,13 @@ class EmailComponentTest extends CakeTestCase {
*/
public $name = 'Email';

/**
* sentDate
*
* @var string
*/
public static $sentDate = null;

/**
* setUp method
*
Expand All @@ -149,6 +157,8 @@ public function setUp() {

$this->Controller->EmailTest->initialize($this->Controller, array());

self::$sentDate = date(DATE_RFC2822);

App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
));
Expand Down Expand Up @@ -189,7 +199,7 @@ public function testSendFormats() {
$this->Controller->EmailTest->delivery = 'DebugComp';
$this->Controller->EmailTest->messageId = false;

$date = date(DATE_RFC2822);
$date = self::$sentDate;
$message = <<<MSGBLOC
<pre>To: postmaster@example.com
From: noreply@example.com
Expand Down Expand Up @@ -242,7 +252,7 @@ public function testTemplates() {
$this->Controller->EmailTest->delivery = 'DebugComp';
$this->Controller->EmailTest->messageId = false;

$date = date(DATE_RFC2822);
$date = self::$sentDate;
$header = <<<HEADBLOC
To: postmaster@example.com
From: noreply@example.com
Expand Down Expand Up @@ -375,7 +385,7 @@ public function testSendDebug() {
$this->assertRegExp('/From: noreply@example.com\n/', $result);
$this->assertRegExp('/Cc: cc@example.com\n/', $result);
$this->assertRegExp('/Bcc: bcc@example.com\n/', $result);
$this->assertRegExp('/Date: ' . preg_quote(date(DATE_RFC2822)) . '\n/', $result);
$this->assertRegExp('/Date: ' . preg_quote(self::$sentDate) . '\n/', $result);
$this->assertRegExp('/X-Mailer: CakePHP Email Component\n/', $result);
$this->assertRegExp('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
$this->assertRegExp('/Content-Transfer-Encoding: 8bitMessage:\n/', $result);
Expand Down Expand Up @@ -404,7 +414,7 @@ public function testSendDebugWithNoSessions() {
$this->assertRegExp('/Subject: Cake Debug Test\n/', $result);
$this->assertRegExp('/Reply-To: noreply@example.com\n/', $result);
$this->assertRegExp('/From: noreply@example.com\n/', $result);
$this->assertRegExp('/Date: ' . preg_quote(date(DATE_RFC2822)) . '\n/', $result);
$this->assertRegExp('/Date: ' . preg_quote(self::$sentDate) . '\n/', $result);
$this->assertRegExp('/X-Mailer: CakePHP Email Component\n/', $result);
$this->assertRegExp('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
$this->assertRegExp('/Content-Transfer-Encoding: 8bitMessage:\n/', $result);
Expand Down Expand Up @@ -575,7 +585,7 @@ public function testDateProperty() {
$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->date = self::$sentDate = 'Today!';
$this->Controller->EmailTest->template = null;
$this->Controller->EmailTest->delivery = 'DebugComp';

Expand Down

0 comments on commit f57c287

Please sign in to comment.