Skip to content

Commit 1741648

Browse files
committed
test: add tests for setAttachmentCID()
1 parent 5bbf3af commit 1741648

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

tests/system/Email/EmailTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,55 @@ private function createMockEmail(): MockEmail
162162

163163
return new MockEmail($config);
164164
}
165+
166+
public function testSetAttachmentCIDFile(): void
167+
{
168+
$email = $this->createMockEmail();
169+
170+
$email->setFrom('your@example.com', 'Your Name');
171+
$email->setTo('foo@example.jp');
172+
173+
$filename = SUPPORTPATH . 'Images/ci-logo.png';
174+
$email->attach($filename);
175+
$cid = $email->setAttachmentCID($filename);
176+
$email->setMessage('<img src="cid:' . $cid . '" alt="CI Logo">');
177+
178+
$this->assertTrue($email->send());
179+
180+
$this->assertStringStartsWith('ci-logo.png@', $cid);
181+
$this->assertStringStartsWith(
182+
'ci-logo.png@',
183+
$email->archive['attachments'][0]['cid']
184+
);
185+
$this->assertMatchesRegularExpression(
186+
'/<img src="cid:ci-logo.png@(.+?)" alt="CI Logo">/u',
187+
$email->archive['body']
188+
);
189+
}
190+
191+
public function testSetAttachmentCIDBufferString(): void
192+
{
193+
$email = $this->createMockEmail();
194+
195+
$email->setFrom('your@example.com', 'Your Name');
196+
$email->setTo('foo@example.jp');
197+
198+
$filename = SUPPORTPATH . 'Images/ci-logo.png';
199+
$imageData = file_get_contents($filename);
200+
$email->attach($imageData, 'inline', 'image001.png', 'image/png');
201+
$cid = $email->setAttachmentCID('image001.png');
202+
$email->setMessage('<img src="cid:' . $cid . '" alt="CI Logo">');
203+
204+
$this->assertTrue($email->send());
205+
206+
$this->assertStringStartsWith('image001.png@', $cid);
207+
$this->assertStringStartsWith(
208+
'image001.png@',
209+
$email->archive['attachments'][0]['cid']
210+
);
211+
$this->assertMatchesRegularExpression(
212+
'/<img src="cid:image001.png@(.+?)" alt="CI Logo">/u',
213+
$email->archive['body']
214+
);
215+
}
165216
}

0 commit comments

Comments
 (0)