|
21 | 21 | use PHPUnit\Framework\Attributes\DataProvider; |
22 | 22 | use PHPUnit\Framework\Attributes\Group; |
23 | 23 | use ReflectionException; |
| 24 | +use ReflectionMethod; |
24 | 25 |
|
25 | 26 | /** |
26 | 27 | * @internal |
@@ -220,6 +221,41 @@ public function testSetAttachmentCIDBufferString(): void |
220 | 221 | ); |
221 | 222 | } |
222 | 223 |
|
| 224 | + /** |
| 225 | + * @see https://github.com/codeigniter4/CodeIgniter4/issues/9644 |
| 226 | + * |
| 227 | + * @throws ReflectionException |
| 228 | + */ |
| 229 | + public function testAppendAttachmentsWithoutCID(): void |
| 230 | + { |
| 231 | + $email = $this->createMockEmail(); |
| 232 | + |
| 233 | + // Manually inject an attachment without 'cid' |
| 234 | + $this->setPrivateProperty($email, 'attachments', [ |
| 235 | + [ |
| 236 | + 'multipart' => 'mixed', |
| 237 | + 'content' => 'VGhpcyBpcyBhIHRlc3QgZmlsZSBjb250ZW50Lg==', // base64 for "This is a test file content." |
| 238 | + 'filename' => '', |
| 239 | + 'type' => 'application/pdf', |
| 240 | + 'name' => ['testfile.pdf'], |
| 241 | + 'disposition' => 'attachment', |
| 242 | + ], |
| 243 | + ]); |
| 244 | + |
| 245 | + $body = ''; |
| 246 | + $boundary = 'test-boundary'; |
| 247 | + |
| 248 | + // Use ReflectionMethod to call protected method with pass-by-reference |
| 249 | + $refMethod = new ReflectionMethod($email, 'appendAttachments'); |
| 250 | + $refMethod->invokeArgs($email, [&$body, $boundary, 'mixed']); |
| 251 | + |
| 252 | + // Assertion: Should not include a Content-ID header |
| 253 | + $this->assertStringContainsString('Content-Type: application/pdf; name="testfile.pdf"', $body); |
| 254 | + $this->assertStringContainsString('Content-Disposition: attachment;', $body); |
| 255 | + $this->assertStringNotContainsString('Content-ID:', $body); |
| 256 | + $this->assertStringContainsString('--' . $boundary . '--', $body); |
| 257 | + } |
| 258 | + |
223 | 259 | /** |
224 | 260 | * @throws ReflectionException |
225 | 261 | */ |
|
0 commit comments