CluPilotCloud/tests/Feature/ErrorPagesTest.php

53 lines
1.8 KiB
PHP

<?php
use Illuminate\Support\Facades\View;
/**
* The error pages, in both languages.
*
* These are the pages nobody looks at until something has already gone wrong,
* which is exactly why they rot. Four of them shipped printing the raw
* translation key `errors.404.hint` in place of a sentence: the lang file gives
* those codes a `null` hint, and Laravel's translator returns the KEY when a
* line is null, so the page rendered the identifier.
*/
$codes = [401, 403, 404, 405, 419, 429, 500];
it('renders every error page without leaking a translation key', function (int $code) {
foreach (['de', 'en'] as $locale) {
app()->setLocale($locale);
$html = View::make("errors.{$code}")->render();
expect($html)
->toContain((string) $code)
->not->toContain("errors.{$code}.")
// The generic catch: any unresolved key of ours has this shape.
->not->toMatch('/errors\.\d{3}\./');
}
})->with($codes);
it('shows a hint where there is one and nothing where there is not', function () {
app()->setLocale('de');
// 419 has a hint in the lang file; 404 deliberately does not. Asserted on
// the element, not on the word: "hint" is also the CSS class that styles it.
expect(View::make('errors.419')->render())
->toContain(__('errors.419.hint'))
->toContain('<p class="hint">');
$html = View::make('errors.404')->render();
expect($html)->toContain(__('errors.404.title'))
->and($html)->not->toContain('<p class="hint">');
});
it('serves a real 404 through the stack', function () {
// The view rendering above cannot catch a broken error handler.
$this->get('/definitely-not-a-route')
->assertNotFound()
->assertSee(__('errors.404.title'))
->assertDontSee('errors.404.');
});