public function testGenerate()
 {
     $msg = new Zend_Mime_Message();
     // No Parts
     $p1 = new Zend_Mime_Part('This is a test');
     $p2 = new Zend_Mime_Part('This is another test');
     $msg->addPart($p1);
     $msg->addPart($p2);
     $res = $msg->generateMessage();
     $mime = $msg->getMime();
     $boundary = $mime->boundary();
     $p1 = strpos($res, $boundary);
     // $boundary must appear once for every mime part
     $this->assertTrue($p1 !== false);
     if ($p1) {
         $p2 = strpos($res, $boundary, $p1 + strlen($boundary));
         $this->assertTrue($p2 !== false);
     }
     // check if the two test messages appear:
     $this->assertTrue(strpos($res, 'This is a test') !== false);
     $this->assertTrue(strpos($res, 'This is another test') !== false);
     // ... more in ZMailTest
 }
示例#2
0
文件: Zend.php 项目: nos3/ai-zend
 /**
  * Returns the internal Zend mail object.
  *
  * @return Zend_Mail Zend mail object
  */
 public function getObject()
 {
     if (!empty($this->_embedded)) {
         $parts = array();
         if ($this->_html != null) {
             $part = new Zend_Mime_Part($this->_html);
             $part->charset = $this->_object->getCharset();
             $part->encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE;
             $part->disposition = Zend_Mime::DISPOSITION_INLINE;
             $part->type = Zend_Mime::TYPE_HTML;
             $parts = array($part);
         }
         $msg = new Zend_Mime_Message();
         $msg->setParts(array_merge($parts, $this->_embedded));
         // create html body (text and maybe embedded), modified afterwards to set it to multipart/related
         $this->_object->setBodyHtml($msg->generateMessage());
         $related = $this->_object->getBodyHtml();
         $related->type = Zend_Mime::MULTIPART_RELATED;
         $related->encoding = Zend_Mime::ENCODING_8BIT;
         $related->boundary = $msg->getMime()->boundary();
         $related->disposition = null;
         $related->charset = null;
     } else {
         if ($this->_html != null) {
             $this->_object->setBodyHtml($this->_html);
         }
     }
     return $this->_object;
 }
 public function testCSVFileUpload()
 {
     $this->markTestIncomplete('The implementation is not yet finished and needs adaptation to new unit tests system.');
     try {
         $this->_httpClient->setUri($this->_baseUri . '/files');
         $this->_httpClient->setMethod(Zend_Http_Client::POST);
         $msg = new Zend_Mime_Message();
         $jsonPart = new Zend_Mime_Part('{}');
         $jsonPart->type = 'application/json';
         $jsonPart->filename = microtime(true) . '.json';
         $jsonPart->disposition = 'attachment';
         $msg->addPart($jsonPart);
         $xmlPart = new Zend_Mime_Part($this->_icc . ',GEM17223,2,SIM_Model,APN1,10.1.2.1,1,TM SPAIN');
         $xmlPart->type = 'text/plain';
         $xmlPart->filename = microtime(true) . '.csv';
         $xmlPart->disposition = 'attachment';
         $msg->addPart($xmlPart);
         $this->_httpClient->setHeaders('Content-Type', 'multipart/mixed; boundary="' . $msg->getMime()->boundary() . '"');
         $this->_httpClient->setRawData($msg->generateMessage());
         $res = $this->_httpClient->request();
         $this->assertEquals(200, $res->getStatus());
         $obj = json_decode($res->getBody());
         $this->assertTrue(is_object($obj));
         $this->assertNotEmpty($obj->customerData);
     } catch (Exception $e) {
         $this->fail($e->getMessage());
     }
 }