Skip to content

Commit

Permalink
fix email template variables
Browse files Browse the repository at this point in the history
the email templates do not get populated with the correct variables into the template, resulting in the email being generated with empty variable fields.
  • Loading branch information
vaidas-lungis committed Jan 5, 2015
1 parent 013e9c7 commit ddc3ec3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/bb-modules/Email/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,10 @@ private function _getVarsString()
return $str;
}

private function _parse($t, $vars)
private function _parse(\Model_EmailTemplate $t, $vars)
{
$dd = $vars;
$pc = $this->di['twig']->render($t->content);

$dd = $vars;
$ps = $this->di['twig']->render($t->subject);

$pc = $this->di['twig']->render($t->content, $vars);
$ps = $this->di['twig']->render($t->subject, $vars);
return array($ps, $pc);
}

Expand Down
24 changes: 24 additions & 0 deletions tests/integration/bb-modules/mod_email/Api_AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,30 @@ public function testTemplateGeneralSend()

$bool = $this->api_admin->email_template_send($params);
$this->assertTrue($bool);

}

public function testTemplate_populateVariables()
{
$params = array();
$params['to'] = 'client@boxbilling.com';
$params['to_name'] = 'Client PHPUnit';

$params['code'] = 'mod_client_signup';

$params['default_template'] = 'Hello, message from {{ admin.client_get({"id":client_id}).first_name }}, {{subject}}';
$params['default_subject'] = 'My subject for client';

$params['to_client'] = 1;

$bool = $this->api_admin->email_template_send($params);
$this->assertTrue($bool);

$emailModel = $this->di['db']->findOne('ModEmailQueue', ' order by id desc');

$clientModel = $this->di['db']->load('Client', $params['to_client']);

$this->assertTrue(strpos($emailModel->subject, $clientModel->first_name) !== false, 'Template variables were not populated');
}

public function testSendToClient()
Expand Down

0 comments on commit ddc3ec3

Please sign in to comment.