Пример #1
0
 public function testFromArray()
 {
     $message = CM_Mail_Message::fromArray(['subject' => null, 'html' => null, 'text' => null, 'sender' => null, 'from' => [], 'replyTo' => null, 'to' => null, 'cc' => null, 'bcc' => null, 'customHeaders' => []]);
     $this->assertInstanceOf('CM_Mail_Message', $message);
     $this->assertSame((new CM_Mail_Message())->toArray(), $message->toArray());
     $message = CM_Mail_Message::fromArray(['subject' => 'foo', 'html' => '<p>content</p>', 'text' => 'content', 'sender' => ['*****@*****.**' => null], 'from' => ['*****@*****.**' => null], 'replyTo' => ['*****@*****.**' => null], 'to' => ['*****@*****.**' => 'Bar'], 'cc' => ['*****@*****.**' => null, '*****@*****.**' => 'Bar2'], 'bcc' => null, 'customHeaders' => ['X-foo' => ['bar'], 'X-bar' => ['foo', 'foobar']]]);
     $expectedMessage = new CM_Mail_Message();
     $expectedMessage->setSubject('foo')->setSender('*****@*****.**')->setFrom('*****@*****.**')->setReplyTo('*****@*****.**')->addTo('*****@*****.**', 'Bar')->addCc('*****@*****.**')->addCc('*****@*****.**', 'Bar2');
     $expectedMessage->setBody('<p>content</p>', 'text/html');
     $expectedMessage->addPart('content', 'text/plain');
     $expectedMessage->getHeaders()->addTextHeader('foo', 'bar');
     $expectedMessage->getHeaders()->addTextHeader('X-foo', 'bar');
     $expectedMessage->getHeaders()->addTextHeader('X-bar', 'foo');
     $expectedMessage->getHeaders()->addTextHeader('X-bar', 'foobar');
     $this->assertInstanceOf('CM_Mail_Message', $message);
     $this->assertSame($expectedMessage->toArray(), $message->toArray());
 }
Пример #2
0
 public function testSend()
 {
     $logger = $this->mockObject('CM_Log_Logger');
     $transport = new CM_Mail_Transport_Log($logger);
     $message = new CM_Mail_Message();
     $message->setSubject('foo')->setSender('*****@*****.**')->setReplyTo('*****@*****.**')->addTo('*****@*****.**', 'Bar')->addCc('*****@*****.**')->addCc('*****@*****.**', 'Bar2');
     $message->setBody('<p>content</p>', 'text/html');
     $message->addPart('content', 'text/plain');
     $failedRecipients = [];
     $logger->mockMethod('addMessage')->set(function ($message, $level, CM_Log_Context $context = null) {
         $this->assertSame('* foo *' . PHP_EOL . PHP_EOL . 'content' . PHP_EOL, $message);
         $this->assertSame(CM_Log_Logger::INFO, $level);
         $this->assertSame(['type' => CM_Paging_Log_Mail::getTypeStatic(), 'sender' => ['*****@*****.**' => null], 'replyTo' => ['*****@*****.**' => null], 'to' => ['*****@*****.**' => 'Bar'], 'cc' => ['*****@*****.**' => null, '*****@*****.**' => 'Bar2'], 'bcc' => null], $context->getExtra());
     });
     $numSent = $transport->send($message, $failedRecipients);
     $this->assertSame(3, $numSent);
     $this->assertSame([], $failedRecipients);
 }