Skip to content

Instantly share code, notes, and snippets.

@nitriques
Created October 11, 2013 16:29
Show Gist options
  • Save nitriques/6937850 to your computer and use it in GitHub Desktop.
Save nitriques/6937850 to your computer and use it in GitHub Desktop.
<?php
if(!defined('__IN_SYMPHONY__')) die('<h2>Error</h2><p>You cannot directly access this file</p>');
require_once(TOOLKIT . '/class.event.php');
define('DIR', rtrim(dirname(__FILE__), '\\/'));
Class eventemailTestCase extends Event {
public static function about(){
return array(
'name' => 'Email Test Case For #1821',
'version' => '1.0',
'release-date' => '2010-01-10'
);
}
public function load() {
return $this->__trigger();
}
protected function __trigger(){
$result = new XMLElement('issue-1821');
//try {
$result->appendChild(new XMLElement('test-1-string', $this->__sendEmail_setAttachments_string() ? 'passed' : 'failed'));
$result->appendChild(new XMLElement('test-1-array', $this->__sendEmail_setAttachments_array() ? 'passed' : 'failed'));
$result->appendChild(new XMLElement('test-2', $this->__sendEmail_appendAttachment() ? 'passed' : 'failed'));
/*} catch(Exception $e) {
$result->setAttribute("result", "error");
$result->appendChild(new XMLElement('error',$e->getMessage()));
}*/
return $result;
}
private function getTestEmail() {
return '[email protected]';
}
private function createMail($count) {
$email = Email::create();
$email->setSenderEmailAddress($this->getTestEmail());
$email->setFrom($this->getTestEmail(), 'TEST #1821');
$email->setReplyToEmailAddress($this->getTestEmail());
$email->setRecipients($this->getTestEmail());
$email->setSubject('test ' . $count);
$email->setTextPlain('Attachment test');
return $email;
}
private function __sendEmail_setAttachments_string() {
$email = $this->createMail('1 - string');
$email->setAttachments(DIR . '/test');
$email->setAttachments(null);
$email->setAttachments(array(
'text.txt' => DIR . '/test',
'test.csv' => DIR . '/test'
));
if ($email->validate()) {
$email->send();
} else {
return false;
}
return true;
}
private function __sendEmail_setAttachments_array() {
$email = $this->createMail('1 - array');
$email->setAttachments(array(
DIR . '/test',
array(
'file' => DIR . 'test',
'filename' => 'wont-be-seen.html',
'charset' => 'utf-8'
)
));
$email->setAttachments(null);
$email->setAttachments(array(
DIR . '/test',
array(
'file' => 'http://example.org/index.html',
'filename' => 'exemple.html',
'charset' => 'utf-8'
)
));
if ($email->validate()) {
$email->send();
} else {
return false;
}
return true;
}
private function __sendEmail_appendAttachment() {
$email = $this->createMail(2);
$email->appendAttachment('http://example.org/index.html');
$email->appendAttachment(
array(
'file' => 'http://example.org/index.html',
'filename' => 'exemple.html',
'charset' => 'utf-8'
)
);
$email->appendAttachment(array(
'test.html' => 'http://example.org/index.html'
));
if ($email->validate()) {
$email->send();
} else {
return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment