Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding email format as an option for EmailQueue

  • Loading branch information...
commit 9df4ca5ea6c9c4d1343321457a1f2ea05ceb6d67 1 parent 4d66717
@lorenzo lorenzo authored
View
1  Config/Schema/schema.sql
@@ -6,6 +6,7 @@ CREATE TABLE IF NOT EXISTS `email_queue` (
`config` varchar(30) NOT NULL,
`template` varchar(50) NOT NULL,
`layout` varchar(50) NOT NULL,
+ `format` varchar(5) NOT NULL,
`template_vars` text NOT NULL,
`sent` tinyint(1) NOT NULL,
`locked` tinyint(1) NOT NULL DEFAULT 0,
View
1  Console/Command/SenderShell.php
@@ -56,6 +56,7 @@ public function main() {
->to($e['EmailQueue']['to'])
->subject($e['EmailQueue']['subject'])
->template($template, $layout)
+ ->emailFormat($e['EmailQueue']['format'])
->viewVars($e['EmailQueue']['template_vars'])
->send();
} catch (SocketException $exception) {
View
2  Model/EmailQueue.php
@@ -35,6 +35,7 @@ class EmailQueue extends AppModel {
* - send_at : date time sting representing the time this email should be sent at (in UTC)
* - template : the name of the element to use as template for the email message
* - layout : the name of the layout to be used to wrap email message
+ * - format: Type of template to use (html, text or both)
* - config : the name of the email config to be used for sending
*
* @return void
@@ -45,6 +46,7 @@ public function enqueue($to, array $data, $options = array()) {
'send_at' => gmdate('Y-m-d H:i:s'),
'template' => 'default',
'layout' => 'default',
+ 'format' => 'both',
'template_vars' => $data,
'config' => 'default'
);
View
1  README.md
@@ -67,6 +67,7 @@ and queue a new one by storing the correct data:
* `send_at` : date time sting representing the time this email should be sent at (in UTC)
* `template` : the name of the element to use as template for the email message
* `layout` : the name of the layout to be used to wrap email message
+ * `format` : Type of template to use (html, text or both)
* `config` : the name of the email config to be used for sending
### Sending emails
View
9 Test/Case/Console/Command/SenderShellTest.php
@@ -42,12 +42,13 @@ public function setUp() {
}
public function testMainAllFail() {
- $email = $this->getMock('CakeEmail', array('to', 'template', 'viewVars', 'send', 'subject'));
+ $email = $this->getMock('CakeEmail', array('to', 'template', 'viewVars', 'send', 'subject', 'emailFormat'));
$this->Sender->expects($this->exactly(3))->method('_newEmail')->with('default')->will($this->returnValue($email));
$email->expects($this->exactly(3))->method('send')->will($this->returnValue(false));
$email->expects($this->exactly(3))->method('to')->will($this->returnSelf());
$email->expects($this->exactly(3))->method('subject')->with('Free dealz')->will($this->returnSelf());
+ $email->expects($this->exactly(3))->method('emailFormat')->with('both')->will($this->returnSelf());
$email->expects($this->exactly(3))->method('template')
->with('default', 'default')
@@ -76,7 +77,7 @@ public function testMainAllFail() {
public function testMainAllWin() {
- $email = $this->getMock('CakeEmail', array('to', 'template', 'viewVars', 'send', 'subject'));
+ $email = $this->getMock('CakeEmail', array('to', 'template', 'viewVars', 'send', 'subject', 'emailFormat'));
$this->Sender->params['template'] = 'other';
$this->Sender->params['layout'] = 'custom';
@@ -89,6 +90,7 @@ public function testMainAllWin() {
$email->expects($this->exactly(3))->method('send')->will($this->returnValue(true));
$email->expects($this->exactly(3))->method('to')->will($this->returnSelf());
$email->expects($this->exactly(3))->method('subject')->with('Free dealz')->will($this->returnSelf());
+ $email->expects($this->exactly(3))->method('emailFormat')->with('both')->will($this->returnSelf());
$email->expects($this->exactly(3))->method('template')
->with('other', 'custom')
->will($this->returnSelf());
@@ -116,7 +118,7 @@ public function testMainAllWin() {
}
public function testMainAllFailWithException() {
- $email = $this->getMock('CakeEmail', array('to', 'template', 'viewVars', 'send', 'subject'));
+ $email = $this->getMock('CakeEmail', array('to', 'template', 'viewVars', 'send', 'subject', 'emailFormat'));
$this->Sender->expects($this->exactly(3))->method('_newEmail')->with('default')->will($this->returnValue($email));
@@ -124,6 +126,7 @@ public function testMainAllFailWithException() {
$email->expects($this->exactly(3))->method('to')->will($this->returnSelf());
$email->expects($this->exactly(3))->method('subject')->with('Free dealz')->will($this->returnSelf());
+ $email->expects($this->exactly(3))->method('emailFormat')->with('both')->will($this->returnSelf());
$email->expects($this->exactly(3))->method('template')
->with('default', 'default')
->will($this->returnSelf());
View
1  Test/Case/Model/EmailQueueTest.php
@@ -53,6 +53,7 @@ public function testEnqueue() {
'subject' => 'Hey!',
'template' => 'default',
'layout' => 'default',
+ 'format' => 'both',
'template_vars' => array('a' => 'variable', 'some' => 'thing'),
'sent' => false,
'locked' => false,
View
7 Test/Fixture/EmailQueueFixture.php
@@ -24,6 +24,7 @@ class EmailQueueFixture extends CakeTestFixture {
'config' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 30, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
'template' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 50, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
'layout' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 50, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
+ 'format' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 5, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
'template_vars' => array('type' => 'text', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
'sent' => array('type' => 'boolean', 'null' => false, 'default' => null),
'locked' => array('type' => 'boolean', 'null' => false, 'default' => 0),
@@ -50,6 +51,7 @@ class EmailQueueFixture extends CakeTestFixture {
'config' => 'default',
'template' => 'default',
'layout' => 'default',
+ 'format' => 'both',
'template_vars' => '{"a":1,"b":2}',
'sent' => 0,
'locked' => 0,
@@ -65,6 +67,7 @@ class EmailQueueFixture extends CakeTestFixture {
'config' => 'default',
'template' => 'default',
'layout' => 'default',
+ 'format' => 'both',
'template_vars' => '{"a":1,"b":2}',
'sent' => 0,
'locked' => 0,
@@ -80,6 +83,7 @@ class EmailQueueFixture extends CakeTestFixture {
'config' => 'default',
'template' => 'default',
'layout' => 'default',
+ 'format' => 'both',
'template_vars' => '{"a":1,"b":2}',
'sent' => 0,
'locked' => 0,
@@ -95,6 +99,7 @@ class EmailQueueFixture extends CakeTestFixture {
'config' => 'default',
'template' => 'default',
'layout' => 'default',
+ 'format' => 'both',
'template_vars' => '{"a":1,"b":2}',
'sent' => 1,
'locked' => 0,
@@ -110,6 +115,7 @@ class EmailQueueFixture extends CakeTestFixture {
'config' => 'default',
'template' => 'default',
'layout' => 'default',
+ 'format' => 'both',
'template_vars' => '{"a":1,"b":2}',
'sent' => 0,
'locked' => 1,
@@ -125,6 +131,7 @@ class EmailQueueFixture extends CakeTestFixture {
'config' => 'default',
'template' => 'default',
'layout' => 'default',
+ 'format' => 'both',
'template_vars' => '{"a":1,"b":2}',
'sent' => 0,
'locked' => 0,
Please sign in to comment.
Something went wrong with that request. Please try again.