public function testFormatFull() { $time = time(); $date = date('Y-m-d H:i:s'); $message = new Message(array('to' => 'to', 'from' => 'from', 'sender' => 'sender', 'cc' => 'cc', 'bcc' => 'bcc', 'date' => $time, 'subject' => 'subject')); $message->body('text', 'text body'); $message->body('html', 'html body'); $debug = new Debug(); $result = $debug->invokeMethod('format', array($message, 'full')); $expected = "Mail sent to to from from (sender: sender, cc: cc, bcc: bcc)\n" . "with date {$date} and subject `subject` in formats html, text, text message body:\n" . "text body\nhtml message body:\nhtml body\n"; $this->assertEqual($expected, $result); }
public function testAttachments() { $simple = new Simple(); $path = tempnam('/tmp', 'li3_mailer_test'); file_put_contents($path, 'file data'); $message = new Message(array('attach' => array(array('data' => 'my data', 'filename' => 'cool.txt'), $path => array('filename' => 'file.txt', 'content-type' => 'text/plain', 'id' => 'foo@bar')))); $message->body('text', 'text body'); $message->body('html', 'html body'); $params = $simple->deliver($message); extract($params); $c_type = 'Content-Type: text\\/plain; name="cool.txt"'; $c_disposition = 'Content-Disposition: attachment; filename="cool.txt"'; $preg = '/\\n' . $c_type . '\\n' . $c_disposition . '\\n\\nmy data\\n/'; $this->assertPattern($preg, $body); $c_type = 'Content-Type: text\\/plain; name="file.txt"'; $c_disposition = 'Content-Disposition: attachment; filename="file.txt"'; $c_id = 'Content-ID: \\<foo@bar\\>'; $preg = '/\\n' . $c_type . '\\n' . $c_disposition . '\\n' . $c_id . '\\n\\nfile data\\n/'; $this->assertPattern($preg, $body); unlink($path); }
public function testAttachments() { $path = tempnam('/tmp', 'li3_mailer_test'); file_put_contents($path, 'file data'); $message = new Message(array('attach' => array(array('data' => 'my data', 'filename' => 'cool.txt'), $path => array('filename' => 'file.txt', 'content-type' => 'text/plain', 'id' => 'foo@bar')))); $message->body('text', 'text body'); $message->body('html', 'html body'); $swift = new Swift(); $swift_message = $swift->invokeMethod('message', array($message)); $children = $swift_message->getChildren(); $attachments = array_filter($children, function ($child) { return in_array($child->getBody(), array('file data', 'my data')); }); $this->assertEqual(2, count($attachments)); list($file, $data) = array_values($attachments); if ($data->getBody() != 'my data') { list($file, $data) = array($data, $file); } //swift wipes out body for files, maybe a bug? //$this->assertEqual('file data', $file->getBody()); $this->assertEqual('file.txt', $file->getFilename()); $this->assertEqual('text/plain', $file->getContentType()); $this->assertEqual('foo@bar', $file->getId()); $this->assertEqual('my data', $data->getBody()); $this->assertEqual('cool.txt', $data->getFilename()); $this->assertEqual('text/plain', $data->getContentType()); unlink($path); }
public function testAttachmentWithoutFilename() { $simple = $this->_adapter(); $message = new Message(array('attach' => array(array('data' => 'my data', 'content-type' => 'text/plain')))); $message->body('text', 'text body'); $message->body('html', 'html body'); $params = $simple->deliver($message); extract($params); $type = 'Content-Type: text\\/plain'; $disposition = 'Content-Disposition: attachment'; $data = 'my data'; $content = $type . '\\n' . $disposition . '\\n\\n' . $data; $expected = '/\\n' . $content . '\\n/'; $this->assertPattern($expected, $body); }
public function testEmbed() { $message = new Message(); $result = $message->embed('foo/bar', array('check' => false)); $this->assertPattern('/^[^@]+@li3_mailer.generated$/', $result); $attachments = $message->attachments(); $this->assertEqual(1, count($attachments)); $this->assertEqual('foo/bar', $attachments[0]['attach_path']); $this->assertEqual('inline', $attachments[0]['disposition']); }