| 1 | <?php |
| 2 | |
| 3 | namespace Liuch\DmarcSrg; |
| 4 | |
| 5 | use Liuch\DmarcSrg\Mail\MailBody; |
| 6 | |
| 7 | class MailBodyTest extends \PHPUnit\Framework\TestCase |
| 8 | { |
| 9 | private $text = null; |
| 10 | private $html = null; |
| 11 | |
| 12 | public function setUp(): void |
| 13 | { |
| 14 | $this->text = [ 'text string' ]; |
| 15 | $this->html = [ 'html string' ]; |
| 16 | } |
| 17 | |
| 18 | public function testTextContentType(): void |
| 19 | { |
| 20 | $body = new MailBody(); |
| 21 | $body->text = $this->text; |
| 22 | $this->assertSame('text/plain; charset=utf-8', $body->contentType()); |
| 23 | } |
| 24 | |
| 25 | public function testHtmlContentType(): void |
| 26 | { |
| 27 | $body = new MailBody(); |
| 28 | $body->html = $this->html; |
| 29 | $this->assertSame('text/html; charset=utf-8', $body->contentType()); |
| 30 | } |
| 31 | |
| 32 | public function testMultipartContentType(): void |
| 33 | { |
| 34 | $body = new MailBody(); |
| 35 | $body->text = $this->text; |
| 36 | $body->html = $this->html; |
| 37 | $this->assertStringStartsWith('multipart/alternative; boundary=', $body->contentType()); |
| 38 | } |
| 39 | |
| 40 | public function testTextContent(): void |
| 41 | { |
| 42 | $body = new MailBody(); |
| 43 | $body->text = $this->text; |
| 44 | $content = $body->content(); |
| 45 | $this->assertCount(1, $content); |
| 46 | $this->assertSame('text string', $content[0]); |
| 47 | } |
| 48 | |
| 49 | public function testHtmlContent(): void |
| 50 | { |
| 51 | $body = new MailBody(); |
| 52 | $body->html = $this->html; |
| 53 | $content = $body->content(); |
| 54 | $this->assertCount(1, $content); |
| 55 | $this->assertSame('html string', $content[0]); |
| 56 | } |
| 57 | |
| 58 | public function testMultipartContent(): void |
| 59 | { |
| 60 | $body = new MailBody(); |
| 61 | $body->text = $this->text; |
| 62 | $body->html = $this->html; |
| 63 | $boundary = substr($body->contentType(), 33, -1); |
| 64 | $content = $body->content(); |
| 65 | $this->assertCount(10, $content); |
| 66 | $this->assertSame('--' . $boundary, $content[0]); |
| 67 | $this->assertSame('Content-Type: text/plain; charset=utf-8', $content[1]); |
| 68 | $this->assertSame('Content-Transfer-Encoding: 7bit', $content[2]); |
| 69 | $this->assertSame('', $content[3]); |
| 70 | $this->assertSame('text string', $content[4]); |
| 71 | $this->assertSame('--' . $boundary, $content[5]); |
| 72 | $this->assertSame('Content-Type: text/html; charset=utf-8', $content[6]); |
| 73 | $this->assertSame('Content-Transfer-Encoding: 7bit', $content[7]); |
| 74 | $this->assertSame('', $content[8]); |
| 75 | $this->assertSame('html string', $content[9]); |
| 76 | } |
| 77 | } |