|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Live Mailbox - PHPUnit tests. |
| 4 | + * |
| 5 | + * Runs tests on a live mailbox |
| 6 | + * |
| 7 | + * @author BAPCLTD-Marv |
| 8 | + */ |
| 9 | +declare(strict_types=1); |
| 10 | + |
| 11 | +namespace PhpImap; |
| 12 | + |
| 13 | +use const ENC8BIT; |
| 14 | +use const ENCBASE64; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | +use const TYPEIMAGE; |
| 17 | + |
| 18 | +class Issue519Test extends TestCase |
| 19 | +{ |
| 20 | + const HEADER_VALUES = [ |
| 21 | + 'inline', |
| 22 | + 'Inline', |
| 23 | + 'iNline', |
| 24 | + 'INline', |
| 25 | + 'inLine', |
| 26 | + 'InLine', |
| 27 | + 'iNLine', |
| 28 | + 'INLine', |
| 29 | + 'inlIne', |
| 30 | + 'InlIne', |
| 31 | + 'iNlIne', |
| 32 | + 'INlIne', |
| 33 | + 'inLIne', |
| 34 | + 'InLIne', |
| 35 | + 'iNLIne', |
| 36 | + 'INLIne', |
| 37 | + 'inliNe', |
| 38 | + 'InliNe', |
| 39 | + 'iNliNe', |
| 40 | + 'INliNe', |
| 41 | + 'inLiNe', |
| 42 | + 'InLiNe', |
| 43 | + 'iNLiNe', |
| 44 | + 'INLiNe', |
| 45 | + 'inlINe', |
| 46 | + 'InlINe', |
| 47 | + 'iNlINe', |
| 48 | + 'INlINe', |
| 49 | + 'inLINe', |
| 50 | + 'InLINe', |
| 51 | + 'iNLINe', |
| 52 | + 'INLINe', |
| 53 | + 'inlinE', |
| 54 | + 'InlinE', |
| 55 | + 'iNlinE', |
| 56 | + 'INlinE', |
| 57 | + 'inLinE', |
| 58 | + 'InLinE', |
| 59 | + 'iNLinE', |
| 60 | + 'INLinE', |
| 61 | + 'inlInE', |
| 62 | + 'InlInE', |
| 63 | + 'iNlInE', |
| 64 | + 'INlInE', |
| 65 | + 'inLInE', |
| 66 | + 'InLInE', |
| 67 | + 'iNLInE', |
| 68 | + 'INLInE', |
| 69 | + 'inliNE', |
| 70 | + 'InliNE', |
| 71 | + 'iNliNE', |
| 72 | + 'INliNE', |
| 73 | + 'inLiNE', |
| 74 | + 'InLiNE', |
| 75 | + 'iNLiNE', |
| 76 | + 'INLiNE', |
| 77 | + 'inlINE', |
| 78 | + 'InlINE', |
| 79 | + 'iNlINE', |
| 80 | + 'INlINE', |
| 81 | + 'inLINE', |
| 82 | + 'InLINE', |
| 83 | + 'iNLINE', |
| 84 | + 'INLINE', |
| 85 | + ]; |
| 86 | + |
| 87 | + const CID = 'cid:foo.jpg'; |
| 88 | + |
| 89 | + const ID = 'foo.jpg'; |
| 90 | + |
| 91 | + const SUBTYPE = 'jpeg'; |
| 92 | + |
| 93 | + const SIZE_IN_BYTES = 0; |
| 94 | + |
| 95 | + const HTML = 'foo.html'; |
| 96 | + |
| 97 | + const HTML_EMBED = '<img src="data:image/jpeg;base64, ">'; |
| 98 | + |
| 99 | + const MIME = 'image/jpeg'; |
| 100 | + |
| 101 | + const EXPECTED_ATTACHMENT_COUNT = 1; |
| 102 | + |
| 103 | + const EXPECTED_ATTACHMENT_COUNT_AFTER_EMBED = 0; |
| 104 | + |
| 105 | + /** |
| 106 | + * @psalm-return array<string, array{0:string}> |
| 107 | + */ |
| 108 | + public function provider(): array |
| 109 | + { |
| 110 | + $out = []; |
| 111 | + |
| 112 | + foreach (self::HEADER_VALUES as $value) { |
| 113 | + $out[$value] = [$value]; |
| 114 | + } |
| 115 | + |
| 116 | + return $out; |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * @dataProvider provider |
| 121 | + */ |
| 122 | + public function test(string $header_value): void |
| 123 | + { |
| 124 | + $mailbox = new Mailbox('', '', ''); |
| 125 | + $mail = new IncomingMail(); |
| 126 | + $attachment = new Fixtures\IncomingMailAttachment(); |
| 127 | + $part = new Fixtures\DataPartInfo( |
| 128 | + $mailbox, |
| 129 | + 0, |
| 130 | + 0, |
| 131 | + ENCBASE64, |
| 132 | + 0 |
| 133 | + ); |
| 134 | + |
| 135 | + $html = new Fixtures\DataPartInfo( |
| 136 | + $mailbox, |
| 137 | + 0, |
| 138 | + 0, |
| 139 | + ENC8BIT, |
| 140 | + 0 |
| 141 | + ); |
| 142 | + |
| 143 | + $html_string = '<img src="'.self::CID.'">'; |
| 144 | + |
| 145 | + $html->setData($html_string); |
| 146 | + $part->setData(''); |
| 147 | + |
| 148 | + $attachment->id = self::ID; |
| 149 | + $attachment->contentId = self::ID; |
| 150 | + $attachment->type = TYPEIMAGE; |
| 151 | + $attachment->encoding = ENCBASE64; |
| 152 | + $attachment->subtype = self::SUBTYPE; |
| 153 | + $attachment->description = self::ID; |
| 154 | + $attachment->name = self::ID; |
| 155 | + $attachment->sizeInBytes = self::SIZE_IN_BYTES; |
| 156 | + $attachment->disposition = $header_value; |
| 157 | + $attachment->override_getFileInfo_mime = self::MIME; |
| 158 | + |
| 159 | + $attachment->addDataPartInfo($part); |
| 160 | + |
| 161 | + $mail->addDataPartInfo($html, DataPartInfo::TEXT_HTML); |
| 162 | + $mail->addAttachment($attachment); |
| 163 | + |
| 164 | + $this->assertTrue($mail->hasAttachments()); |
| 165 | + |
| 166 | + $this->assertCount( |
| 167 | + self::EXPECTED_ATTACHMENT_COUNT, |
| 168 | + $mail->getAttachments() |
| 169 | + ); |
| 170 | + |
| 171 | + $this->assertSame($html_string, $mail->textHtml); |
| 172 | + |
| 173 | + $mail->embedImageAttachments(); |
| 174 | + |
| 175 | + $this->assertCount( |
| 176 | + self::EXPECTED_ATTACHMENT_COUNT_AFTER_EMBED, |
| 177 | + $mail->getAttachments() |
| 178 | + ); |
| 179 | + |
| 180 | + $this->assertSame(self::HTML_EMBED, $mail->textHtml); |
| 181 | + } |
| 182 | +} |
0 commit comments