Example #1
0
 public static function sendTemplateMail($template, $to, $from, $params = array(), $context = null)
 {
     if (!$to) {
         return false;
     }
     if (empty($params['target'])) {
         $target = opToolkit::isMobileEmailAddress($to) ? 'mobile' : 'pc';
     } else {
         $target = $params['target'];
     }
     if (in_array($target . '_' . $template, Doctrine::getTable('NotificationMail')->getDisabledNotificationNames())) {
         return false;
     }
     if (null === $context) {
         $context = sfContext::getInstance();
     }
     $body = self::getMailTemplate($template, $target, $params, false, $context);
     $signature = self::getMailTemplate('signature', $target, array(), true, $context);
     if ($signature) {
         $signature = "\n" . $signature;
     }
     $subject = $params['subject'];
     $notificationMail = Doctrine::getTable('NotificationMail')->fetchTemplate($target . '_' . $template);
     if ($notificationMail instanceof NotificationMail && $notificationMail->getTitle()) {
         $subject = $notificationMail->getTitle();
         $templateStorage = new sfTemplateStorageString($subject);
         $renderer = new opTemplateRendererTwig();
         $params['sf_type'] = null;
         $parameterHolder = new sfViewParameterHolder($context->getEventDispatcher(), $params);
         $subject = $renderer->evaluate($templateStorage, $parameterHolder->toArray());
         $notificationMail->free(true);
     }
     return self::execute($subject, $to, $from, $body . $signature);
 }
$p->setEscapingMethod('');
$t->is($p->getEscapingMethod(), '', '->getEscapingMethod() returns an empty value if the method is empty');
try {
    $p->setEscapingMethod('nonexistant');
    $p->getEscapingMethod();
    $t->fail('->getEscapingMethod() throws an InvalidArgumentException if the escaping method does not exist');
} catch (InvalidArgumentException $e) {
    $t->pass('->getEscapingMethod() throws an InvalidArgumentException if the escaping method does not exist');
}
// ->toArray()
$t->diag('->toArray()');
$p->initialize($dispatcher, array('foo' => 'bar'));
$a = $p->toArray();
$t->is($a['foo'], 'bar', '->toArray() returns an array representation of the parameter holder');
// escaping strategies
$p = new sfViewParameterHolder(new sfEventDispatcher(), array('foo' => 'bar'));
try {
    $p->setEscaping('null');
    $p->toArray();
    $t->fail('->toArray() throws an InvalidArgumentException if the escaping strategy does not exist');
} catch (InvalidArgumentException $e) {
    $t->pass('->toArray() throws an InvalidArgumentException if the escaping strategy does not exist');
}
$t->diag('Escaping strategy to on');
$p->setEscaping('on');
$values = $p->toArray();
$t->is(count($values), 2, '->toArray() knows about the "on" strategy');
$t->is(count($values['sf_data']), 1, '->toArray() knows about the "on" strategy');
$t->is($values['foo'], '-ESCAPED-bar-ESCAPED-', '->toArray() knows about the "on" strategy');
$t->is($values['sf_data']['foo'], '-ESCAPED-bar-ESCAPED-', '->toArray() knows about the "on" strategy');
$t->diag('Escaping strategy to off');