public function testQueue() { $user = $this->getMock('CM_Model_User', array('getEmail', 'getSite'), array(CMTest_TH::createUser()->getId())); $user->expects($this->any())->method('getEmail')->will($this->returnValue('*****@*****.**')); $user->expects($this->any())->method('getSite')->will($this->returnValue(CM_Site_Abstract::factory())); $msg = new CM_Mail($user, null); $msg->setSubject('testSubject'); $msg->setHtml('<b>hallo</b>'); $msg->addReplyTo('*****@*****.**'); $msg->addCc('*****@*****.**', 'foobar'); $msg->addBcc('*****@*****.**'); $msg->sendDelayed(); $this->assertRow('cm_mail', array('subject' => 'testSubject', 'text' => 'hallo', 'html' => '<b>hallo</b>', 'to' => serialize($msg->getTo()), 'replyTo' => serialize($msg->getReplyTo()), 'cc' => serialize($msg->getCc()), 'bcc' => serialize($msg->getBcc()))); $this->assertEquals(1, CM_Db_Db::count('cm_mail', 'id')); CM_Mail::processQueue(1); $this->assertEquals(0, CM_Db_Db::count('cm_mail', 'id')); }
/** * @param int $limit */ public static function processQueue($limit) { $limit = (int) $limit; $result = CM_Db_Db::execRead('SELECT * FROM `cm_mail` ORDER BY `createStamp` LIMIT ' . $limit); while ($row = $result->fetch()) { $mail = new CM_Mail(); foreach (unserialize($row['to']) as $to) { $mail->addTo($to['address'], $to['name']); } foreach (unserialize($row['replyTo']) as $replyTo) { $mail->addReplyTo($replyTo['address'], $replyTo['name']); } foreach (unserialize($row['cc']) as $cc) { $mail->addCc($cc['address'], $cc['name']); } foreach (unserialize($row['bcc']) as $bcc) { $mail->addBcc($bcc['address'], $bcc['name']); } if ($headerList = unserialize($row['customHeaders'])) { foreach ($headerList as $label => $valueList) { foreach ($valueList as $value) { $mail->addCustomHeader($label, $value); } } } $sender = unserialize($row['sender']); $mail->setSender($sender['address'], $sender['name']); $mail->_send($row['subject'], $row['text'], $row['html']); CM_Db_Db::delete('cm_mail', array('id' => $row['id'])); } }