Example #1
0
 public function testAttachmentAccessors()
 {
     $message = new SendGrid\Mail();
     $attachments = array("path/to/file/file_1.txt", "../file_2.txt", "../file_3.txt");
     $message->setAttachments($attachments);
     $msg_attachments = $message->getAttachments();
     $this->assertEquals(count($attachments), count($msg_attachments));
     for ($i = 0; $i < count($attachments); $i++) {
         $this->assertEquals($attachments[$i], $msg_attachments[$i]['file']);
     }
     //ensure that addAttachment appends to the list of attachments
     $message->addAttachment("../file_4.png");
     $attachments[] = "../file_4.png";
     $msg_attachments = $message->getAttachments();
     $this->assertEquals($attachments[count($attachments) - 1], $msg_attachments[count($msg_attachments) - 1]['file']);
     //Setting an attachment removes all other files
     $message->setAttachment("only_attachment.sad");
     $this->assertEquals(1, count($message->getAttachments()));
     //Remove an attachment
     $message->removeAttachment("only_attachment.sad");
     $this->assertEquals(0, count($message->getAttachments()));
 }