Hand-rolled login/register/logout on Laravel's built-in Auth facade rather than Breeze/Jetstream, which scaffold Tailwind v3 config and would fight our existing Tailwind v4 CSS-first setup. Login/Register are Livewire components; logout is a plain POST route (auth-gated, CSRF-protected). Routing: "/" is now a public landing page describing the project; the sites list moved from "/" to "/sites" to make room for it. Data gating: App\Support\GuestPreview::paginate() forces page 1 and a 5-row page size for unauthenticated visitors on Sites, Discover, and a site's Pages/Backlinks tables, while total() still reflects the real match count — authenticated users get the existing full pagination unchanged. A shared guest-preview-notice component shows "N of M results, sign in to see all" and only renders when something is actually being hidden. Testing: pointed the test suite at a dedicated MySQL database (huginn_testing) instead of the default in-memory SQLite, since the existing fulltext index migration isn't SQLite-compatible — this app is MySQL-specific by now regardless. Added AuthFlowTest (register, login, wrong-password rejection, logout) and GuestPreviewTest (guest capped to a preview, authenticated sees everything), all passing. Also fixed a real bug the tests caught: request()->session() isn't reliably attached during Livewire's in-process test action calls; switched Login/Register to the session() helper, which resolves the session store directly and works in both contexts.
45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Site;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class GuestPreviewTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private function seedSites(int $count): void
|
|
{
|
|
for ($i = 0; $i < $count; $i++) {
|
|
Site::create([
|
|
'collection' => 'CC-MAIN-TEST',
|
|
'domain' => "example{$i}.com",
|
|
'url' => "https://example{$i}.com/",
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function test_guest_sees_only_a_preview_of_sites(): void
|
|
{
|
|
$this->seedSites(8);
|
|
|
|
$response = $this->get(route('sites.index'));
|
|
|
|
$response->assertOk();
|
|
$response->assertSeeText('Showing a preview (5 of 8 results)');
|
|
}
|
|
|
|
public function test_authenticated_user_sees_all_sites(): void
|
|
{
|
|
$this->seedSites(8);
|
|
|
|
$response = $this->actingAs(User::factory()->create())->get(route('sites.index'));
|
|
|
|
$response->assertOk();
|
|
$response->assertDontSeeText('Showing a preview');
|
|
}
|
|
}
|