Пример #1
0
 /**
  * Runs the test.
  */
 public function test()
 {
     $html = file_get_contents(DIR_FILES . '/mail/email.html');
     $text = \Jyxo\Html::toText($html);
     // HTML and plaintext given
     $body = new Body($html, $text);
     $this->assertEquals($html, $body->getMain());
     $this->assertEquals($text, $body->getAlternative());
     $this->assertTrue($body->isHtml());
     // Only HTML
     $body = new Body($html);
     $this->assertEquals($html, $body->getMain());
     $this->assertTrue($body->isHtml());
     // Only plaintext
     $body = new Body($text);
     $this->assertEquals($text, $body->getMain());
     $this->assertFalse($body->isHtml());
 }
Пример #2
0
 /**
  * Creates a basic email.
  *
  * @return \Jyxo\Mail\Email
  */
 private function getEmail() : \Jyxo\Mail\Email
 {
     $email = new Email();
     $email->setSubject('Novinky září 2009 ... a kreslící soutěž')->setFrom(new Email\Address('*****@*****.**', 'Blog.cz'))->addTo(new Email\Address('*****@*****.**', 'Test Test'))->setBody(new Email\Body(\Jyxo\Html::toText($this->content)));
     return $email;
 }
Пример #3
0
Файл: Body.php Проект: jyxo/php
 /**
  * Returns if the contents is in HTML format.
  *
  * @return boolean
  */
 public function isHtml() : bool
 {
     return \Jyxo\Html::is($this->main);
 }
Пример #4
0
 /**
  * Runs the test.
  */
 public function test()
 {
     $filePath = DIR_FILES . '/mail';
     $subject = 'Novinky září 2009 ... a kreslící soutěž';
     $from = new Email\Address('*****@*****.**', 'Blog.cz');
     $to = array(new Email\Address('*****@*****.**', 'Test Test1'), new Email\Address('*****@*****.**'));
     $cc = array(new Email\Address('*****@*****.**', 'Test Test3'), new Email\Address('*****@*****.**'));
     $bcc = array(new Email\Address('*****@*****.**', 'Test Test5'));
     $headers = array(new Email\Header('Organization', 'Blog.cz'));
     $inReplyTo = '*****@*****.**';
     $references = array('*****@*****.**', '*****@*****.**');
     $html = file_get_contents($filePath . '/email.html');
     $body = new Email\Body($html, \Jyxo\Html::toText($html));
     $attachments = array(new Email\Attachment\File($filePath . '/logo.gif', 'logo.gif', 'image/gif'), new Email\Attachment\String(file_get_contents($filePath . '/star.gif'), 'star.gif', 'image/gif'));
     $inlineAttachments = array(new Email\Attachment\InlineFile($filePath . '/logo.gif', 'logo.gif', 'logo.gif', 'image/gif'), new Email\Attachment\InlineString(file_get_contents($filePath . '/star.gif'), 'star.gif', 'star.gif', 'image/gif'));
     // Basic settings
     $email = new Email();
     $email->setSubject($subject)->setFrom($from)->addReplyTo($from)->setInReplyTo($inReplyTo, $references)->setConfirmReadingTo($from);
     $this->assertEquals($subject, $email->getSubject());
     $this->assertSame($from, $email->getFrom());
     $this->assertSame(array($from), $email->getReplyTo());
     $this->assertSame($from, $email->getConfirmReadingTo());
     $this->assertEquals($inReplyTo, $email->getInReplyTo());
     $this->assertSame($references, $email->getReferences());
     // Recipients
     foreach ($to as $address) {
         $email->addTo($address);
     }
     foreach ($cc as $address) {
         $email->addCc($address);
     }
     foreach ($bcc as $address) {
         $email->addBcc($address);
     }
     $this->assertSame($to, $email->getTo());
     $this->assertSame($cc, $email->getCc());
     $this->assertSame($bcc, $email->getBcc());
     // Priority
     $reflection = new \ReflectionClass('\\Jyxo\\Mail\\Email');
     foreach ($reflection->getConstants() as $name => $value) {
         if (0 === strpos($name, 'PRIORITY_')) {
             $email->setPriority($value);
             $this->assertEquals($value, $email->getPriority());
         }
     }
     try {
         $email->setPriority('dummy-priority');
         $this->fail('Expected exception \\InvalidArgumentException.');
     } catch (\PHPUnit_Framework_AssertionFailedError $e) {
         throw $e;
     } catch (\Exception $e) {
         // Correctly thrown exception
         $this->assertInstanceOf('\\InvalidArgumentException', $e);
     }
     // Headers
     foreach ($headers as $header) {
         $email->addHeader($header);
     }
     $this->assertSame($headers, $email->getHeaders());
     // Body
     $email->setBody($body);
     $this->assertSame($body, $email->getBody());
     // Attachments
     foreach ($attachments as $attachment) {
         $email->addAttachment($attachment);
     }
     $this->assertSame($attachments, $email->getAttachments());
     $this->assertFalse($email->hasInlineAttachments());
     foreach ($inlineAttachments as $attachment) {
         $email->addAttachment($attachment);
     }
     $this->assertSame(array_merge($attachments, $inlineAttachments), $email->getAttachments());
     $this->assertTrue($email->hasInlineAttachments());
 }