示例#1
0
文件: SenderTest.php 项目: jyxo/php
 /**
  * Tests a complete email message with all settings.
  */
 public function testCompleteEmail()
 {
     // Email
     $from = new Email\Address('*****@*****.**', 'Blog.cz');
     $email = $this->getEmail();
     $email->setFrom($from)->addReplyTo($from)->setPriority(Email::PRIORITY_NORMAL)->setInReplyTo('*****@*****.**', ['*****@*****.**', '*****@*****.**'])->setConfirmReadingTo($from)->addHeader(new Email\Header('Organization', 'Blog.cz'))->addTo(new Email\Address('*****@*****.**'))->addCc(new Email\Address('*****@*****.**', 'Test Test3'))->addCc(new Email\Address('*****@*****.**'))->addBcc(new Email\Address('*****@*****.**', 'Příliš žluťoučký kůň'));
     // Charset
     $sender = new Sender();
     $charset = 'iso-8859-2';
     $sender->setCharset($charset);
     $this->assertEquals($charset, $sender->getCharset());
     // X-mailer
     $xmailer = 'Blog.cz';
     $sender->setXmailer($xmailer);
     $this->assertEquals($xmailer, $sender->getXmailer());
     // Hostname
     $this->assertEquals('localhost', $sender->getHostname());
     $hostname = 'blog.cz';
     $sender->setHostname($hostname);
     $this->assertEquals($hostname, $sender->getHostname());
     // Encoding
     $reflection = new \ReflectionClass(\Jyxo\Mail\Encoding::class);
     foreach ($reflection->getConstants() as $encoding) {
         $sender->setEncoding($encoding);
         $this->assertEquals($encoding, $sender->getEncoding());
     }
     try {
         $sender->setEncoding('dummy-encoding');
         $this->fail(sprintf('Expected exception %s.', \InvalidArgumentException::class));
     } catch (\PHPUnit_Framework_AssertionFailedError $e) {
         throw $e;
     } catch (\Exception $e) {
         // Correctly thrown exception
         $this->assertInstanceOf(\InvalidArgumentException::class, $e);
     }
     // Email
     $sender->setEmail($email);
     $this->assertSame($email, $sender->getEmail());
     // Sending
     $sender->setEncoding(Encoding::BASE64);
     $result = $sender->send(Sender::MODE_NONE);
     $this->assertResult('sender-complete.eml', $result);
 }