Created
October 11, 2013 16:29
-
-
Save nitriques/6937850 to your computer and use it in GitHub Desktop.
Simple test case for https://github.com/symphonycms/symphony-2/issues/1821
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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