Skip to content

Commit

Permalink
adding more testcases for CakeEmail
Browse files Browse the repository at this point in the history
  • Loading branch information
ceeram committed Aug 29, 2011
1 parent c5d0955 commit 4b093a8
Showing 1 changed file with 127 additions and 3 deletions.
130 changes: 127 additions & 3 deletions lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
Expand Up @@ -77,6 +77,15 @@ class EmailConfig {

}

/*
* ExtendTransport class
* test class to ensure the class has send() method
*
*/
class ExtendTransport {

}

/**
* CakeEmailTest class
*
Expand Down Expand Up @@ -130,6 +139,9 @@ public function testFrom() {
$result = $this->CakeEmail->from(array('cake@cakephp.org' => 'CakePHP'));
$this->assertIdentical($this->CakeEmail->from(), $expected);
$this->assertIdentical($this->CakeEmail, $result);

$this->setExpectedException('SocketException');
$result = $this->CakeEmail->from(array('cake@cakephp.org' => 'CakePHP', 'fail@cakephp.org' => 'From can only be one address'));
}

/**
Expand Down Expand Up @@ -213,6 +225,7 @@ public static function invalidEmails() {
array('string'),
array('<tag>'),
array('some@one.whereis'),
array('wrong@key' => 'Name'),
array(array('ok@cakephp.org', 1.0, '', 'string'))
);
}
Expand All @@ -228,6 +241,17 @@ public function testInvalidEmail($value) {
$this->CakeEmail->to($value);
}

/**
* testBuildInvalidData
*
* @dataProvider invalidEmails
* @expectedException SocketException
* @return void
*/
public function testInvalidEmailAdd($value) {
$this->CakeEmail->addTo($value);
}

/**
* testFormatAddress method
*
Expand Down Expand Up @@ -305,6 +329,9 @@ public function testMessageId() {
$this->assertIdentical($this->CakeEmail, $result);
$result = $this->CakeEmail->getHeaders();
$this->assertIdentical($result['Message-ID'], '<my-email@localhost>');

$result = $this->CakeEmail->messageId();
$this->assertIdentical($result, '<my-email@localhost>');
}

/**
Expand Down Expand Up @@ -400,6 +427,46 @@ public function testHeaders() {
'Content-Transfer-Encoding' => '7bit'
);
$this->assertIdentical($this->CakeEmail->getHeaders(array('from' => true, 'to' => true)), $expected);

$result = $this->CakeEmail->setHeaders(array());
$this->assertIsA($result, 'CakeEmail');
}

/**
* 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);
}

/**
Expand Down Expand Up @@ -467,6 +534,9 @@ public function testAttachments() {
'license' => array('file' => CAKE . 'LICENSE.txt', 'mimetype' => 'application/octet-stream')
);
$this->assertIdentical($this->CakeEmail->attachments(), $expected);

$this->setExpectedException('SocketException');
$this->CakeEmail->attachments(array(array('nofile' => CAKE . 'basics.php', 'mimetype' => 'text/plain')));
}

/**
Expand All @@ -481,6 +551,21 @@ public function testTransport() {

$result = $this->CakeEmail->transportClass();
$this->assertIsA($result, 'DebugTransport');

$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');
$result = $this->CakeEmail->transportClass();
}

/**
Expand Down Expand Up @@ -613,10 +698,15 @@ public function testSendRenderWithHelpers() {
$this->CakeEmail->config(array('empty'));
$this->CakeEmail->template('custom_helper', 'default');
$this->CakeEmail->viewVars(array('time' => $timestamp));
$this->CakeEmail->helpers(array('Time'));
$result = $this->CakeEmail->send();

$result = $this->CakeEmail->helpers(array('Time'));
$this->assertIsA($result, 'CakeEmail');

$result = $this->CakeEmail->send();
$this->assertTrue((bool)strpos($result['message'], 'Right now: ' . date('Y-m-d\TH:i:s\Z', $timestamp)));

$result = $this->CakeEmail->helpers();
$this->assertEquals(array('Time'), $result);
}

/**
Expand Down Expand Up @@ -654,7 +744,7 @@ public function testSendRenderPlugin() {
$this->assertTrue((bool)strpos($result['message'], 'Here is your value: 12345'));
$this->assertTrue((bool)strpos($result['message'], 'This email was sent using the TestPlugin.'));

$this->expectException();
$this->setExpectedException('MissingViewException');
$this->CakeEmail->template('test_plugin_tpl', 'plug_default')->send();
}

Expand Down Expand Up @@ -925,5 +1015,39 @@ public function testConstructWithConfigString() {
$this->assertTrue((bool)strpos($result['headers'], 'Message-ID: '));
$this->assertTrue((bool)strpos($result['headers'], 'To: '));
}
/**
* testViewRender method
*
* @return void
*/
public function testViewRender() {
$result = $this->CakeEmail->viewRender();
$this->assertEquals('View', $result);

$result = $this->CakeEmail->viewRender('Theme');
$this->assertIsA($result, 'CakeEmail');

$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');
$this->assertIsA($result, 'CakeEmail');

$result = $this->CakeEmail->emailFormat();
$this->assertEquals('html', $result);

$this->setExpectedException('SocketException');
$result = $this->CakeEmail->emailFormat('invalid');
}

}

0 comments on commit 4b093a8

Please sign in to comment.