Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer collective, backed by the Pireon OAuth identity server. The public site is a separate, server-rendered application consuming /api/public/v1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
74 lines
2.1 KiB
PHP
74 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Panel;
|
|
|
|
use Database\Seeders\RolePermissionSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use Tests\FakesPireon;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* The link to the API documentation in the panel's sidebar.
|
|
*
|
|
* It points outside the panel, which is the interesting part: the page opens
|
|
* in a new tab so that reaching for the reference does not throw away whatever
|
|
* was half-written in the panel.
|
|
*/
|
|
class DocsNavigationTest extends TestCase
|
|
{
|
|
use FakesPireon, RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->seed(RolePermissionSeeder::class);
|
|
}
|
|
|
|
#[Test]
|
|
public function the_sidebar_links_to_the_documentation(): void
|
|
{
|
|
$this->actingAs($this->userWithRoles('super_admin'));
|
|
|
|
$html = (string) $this->get('/admin')->assertSuccessful()->getContent();
|
|
|
|
$this->assertStringContainsString(route('docs.api'), $html);
|
|
$this->assertMatchesRegularExpression(
|
|
'/href="[^"]*docs\/api"[^>]*target="_blank"/',
|
|
$html,
|
|
'The documentation should open in a new tab.',
|
|
);
|
|
}
|
|
|
|
#[Test]
|
|
public function anybody_who_can_reach_the_panel_can_reach_the_docs(): void
|
|
{
|
|
// Reading the API reference is not a privilege: the page itself is
|
|
// public, so hiding the link would only make it harder to find.
|
|
$this->actingAs($this->userWithRoles('viewer'));
|
|
|
|
$this->get('/admin')
|
|
->assertSuccessful()
|
|
->assertSee(route('docs.api'), escape: false);
|
|
}
|
|
|
|
/**
|
|
* The panel is configured once per process, so a label resolved there
|
|
* would freeze in whatever language happened to be active at boot. This is
|
|
* the test that catches that, and it has to run in its own request to
|
|
* mean anything.
|
|
*/
|
|
#[Test]
|
|
public function the_label_follows_the_language_being_browsed(): void
|
|
{
|
|
$this->actingAs($this->userWithRoles('super_admin'));
|
|
|
|
$this->get('/admin?lang=en')
|
|
->assertSuccessful()
|
|
->assertSee(__('docs.title', [], 'en'));
|
|
}
|
|
}
|