Skip to content

Commit 9693f2c

Browse files
committed
Test mailable has valid content
1 parent 13e5edd commit 9693f2c

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

app/Mail/PostPublished.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Bus\Queueable;
77
use Illuminate\Contracts\Queue\ShouldQueue;
88
use Illuminate\Mail\Mailable;
9+
use Illuminate\Mail\Mailables\Address;
910
use Illuminate\Mail\Mailables\Content;
1011
use Illuminate\Mail\Mailables\Envelope;
1112
use Illuminate\Queue\SerializesModels;
@@ -34,7 +35,17 @@ public function __construct(Post $post)
3435
public function envelope()
3536
{
3637
return new Envelope(
38+
from: new Address('[email protected]', 'Medium Online Publication'),
39+
to: new Address('[email protected]', 'Abu Jobaer'),
40+
bcc: new Address('[email protected]', 'Ria Jobaer'),
41+
replyTo: [
42+
new Address('[email protected]', 'Taylor Otwell'),
43+
],
3744
subject: 'Post Published',
45+
tags: ['architecture', 'design-patterns'],
46+
metadata: [
47+
'post_id' => $this->post->id,
48+
],
3849
);
3950
}
4051

tests/Feature/MailTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,34 @@ public function mailable_can_be_previewed()
3939
$this->get(route('mailable.preview', $post->id))
4040
->assertStatus(200);
4141
}
42+
43+
/** @test */
44+
public function mailable_has_valid_content()
45+
{
46+
$this->actingAs($user = User::factory()->create());
47+
48+
$post = Post::factory()->create(['user_id' => $user->id]);
49+
50+
$mailable = new PostPublished($post);
51+
52+
$mailable->assertFrom('[email protected]');
53+
54+
$mailable->assertTo('[email protected]');
55+
56+
$mailable->assertHasBcc('[email protected]');
57+
58+
$mailable->assertHasReplyTo('[email protected]');
59+
60+
$mailable->assertHasSubject('Post Published');
61+
62+
$mailable->assertHasTag('design-patterns');
63+
64+
$mailable->assertHasMetadata('post_id', $post->id);
65+
66+
$mailable->assertSeeInHtml('Post Published');
67+
68+
$mailable->assertSeeInOrderInHtml(['View Post', 'Thanks']);
69+
70+
$mailable->assertSeeInOrderInText(['View Post', 'Thanks']);
71+
}
4272
}

0 commit comments

Comments
 (0)