|
2 | 2 |
|
3 | 3 | namespace Tests; |
4 | 4 |
|
5 | | -use Buildcode\LaravelDatabaseEmails\Email; |
6 | 5 | use Illuminate\Support\Facades\DB; |
| 6 | +use Dompdf\Dompdf; |
7 | 7 |
|
8 | 8 | class DatabaseInteractionTest extends TestCase |
9 | 9 | { |
@@ -160,4 +160,48 @@ function recipient_should_be_swapped_for_test_address_when_in_testing_mode() |
160 | 160 |
|
161 | 161 | $this->assertEquals('test@address.com', $email->getRecipient()); |
162 | 162 | } |
| 163 | + |
| 164 | + /** @test */ |
| 165 | + function attachments_should_be_saved_correctly() |
| 166 | + { |
| 167 | + $email = $this->composeEmail() |
| 168 | + ->attach(__DIR__ . '/files/pdf-sample.pdf') |
| 169 | + ->send(); |
| 170 | + |
| 171 | + $this->assertCount(1, $email->getAttachments()); |
| 172 | + |
| 173 | + $attachment = $email->getAttachments()[0]; |
| 174 | + |
| 175 | + $this->assertEquals('attachment', $attachment['type']); |
| 176 | + $this->assertEquals(__DIR__ . '/files/pdf-sample.pdf', $attachment['attachment']['file']); |
| 177 | + |
| 178 | + $email = $this->composeEmail() |
| 179 | + ->attach(__DIR__ . '/files/pdf-sample.pdf') |
| 180 | + ->attach(__DIR__ . '/files/pdf-sample-2.pdf') |
| 181 | + ->send(); |
| 182 | + |
| 183 | + $this->assertCount(2, $email->getAttachments()); |
| 184 | + |
| 185 | + $this->assertEquals(__DIR__ . '/files/pdf-sample.pdf', $email->getAttachments()[0]['attachment']['file']); |
| 186 | + $this->assertEquals(__DIR__ . '/files/pdf-sample-2.pdf', $email->getAttachments()[1]['attachment']['file']); |
| 187 | + } |
| 188 | + |
| 189 | + /** @test */ |
| 190 | + function in_memory_attachments_should_be_saved_correctly() |
| 191 | + { |
| 192 | + $pdf = new Dompdf; |
| 193 | + $pdf->loadHtml('Hello CI!'); |
| 194 | + $pdf->setPaper('A4', 'landscape'); |
| 195 | + |
| 196 | + $email = $this->composeEmail() |
| 197 | + ->attachData($pdf->outputHtml(), 'generated.pdf', [ |
| 198 | + 'mime' => 'application/pdf' |
| 199 | + ]) |
| 200 | + ->send(); |
| 201 | + |
| 202 | + $this->assertCount(1, $email->getAttachments()); |
| 203 | + |
| 204 | + $this->assertEquals('rawAttachment', $email->getAttachments()[0]['type']); |
| 205 | + $this->assertEquals($pdf->outputHtml(), $email->getAttachments()[0]['attachment']['data']); |
| 206 | + } |
163 | 207 | } |
0 commit comments