Skip to content
Advertisement

laravel feature tests with locales

I am new to Laravel and I am having an issue to write a test function that asserts that the HTTP response of my welcome page is 200 knowing that I have EN and FR locales defined, meaning that the test should test both localhost:8000/en and localhost:8000/fr.

This is my exampletest.php:

JavaScript

I don’t like writing the code twice for both /en and /fr.

This is my web.php:

JavaScript

And i have written my localization middleware below:

JavaScript

I would appreciate your help on the above. I believe the test should be dynamic.

Thank you in advance..

Advertisement

Answer

I don’t think there’s any way around repeating yourself if you want to test multiple locales. But there’s no requirement to put each test in a separate method. This may work, but I’ve never done testing on multiple locales in my applications.

JavaScript

You could take this further and actually check that the localized content is being served correctly.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement