@@ -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 (
'[email protected] ' ,
'Your Name ' );
171+ $ email->
setTo (
'[email protected] ' );
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 (
'[email protected] ' ,
'Your Name ' );
196+ $ email->
setTo (
'[email protected] ' );
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