What Are The Benefits Of Using Digicom?

Digicom is an ecosystem of financial applications built on top of blockchain networks. Unlike traditional banking systems which rely on centralized computers for data storage and processing, Digicom…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Testing Markdown Content at Laravel 5.8

After looking for some information on Google, I have noticed there is not much information about how to test the Markdown templates you can create in Laravel for Notifications or Mails. So I have decided to post it here in case it can help to some people :).

Now how can we test that our Markdown content is accurate given the right parameters? The best way I have found is rendering the Markdown view within the test, and assert the view contains what you are looking for.

Let us imagine we have a Markdown view for an Email Notification at emails.notification (emails/notification.blade.php):

Within our tests we can use the Facade “Facades\Illuminate\Mail\Markdown” to render the view and then test that it contains what we want.

In this case we want to test that the view will show up the name of the user that we pass as a parameter:

$markdown = Markdown::render(‘emails.notification’, [‘user’ => $user]);

As a first parameter we pass the markdown view we want to render, and as second parameter we pass the variables we want to use within our view.

Finally we can test the content using the function assertContains():

$this->assertContains($user->name, $markdown->toHtml());

I hope this could be helpful for someone.

Add a comment

Related posts:

Is Virtual Reality making Medicine more Magic?

Virtual reality has been around as concept for quite some time. One of the first depictions of it was in the 1935 short story “Pygmalion’s Spectacles” by Stanley G.Weinbaum, that tells a tale of a…

A Sit in the Woods.

I felt the need to escape to the woods for just a few minutes today. As I sat down between two logs, I felt the damp earth beneath me and listened to the trickle of a nearby spring. While the wind…

The African Who Should Have Been an American

To those unfamiliar with the series, it documents the story of modern treasure hunters the Brothers Lagina. The treasure of Oak Island is an old story in American history. If you want to learn more…