Files
SealShare/tests/Feature/PageTemplateTest.php
T
surtic86andClaude Opus 5 4530298398
docker / test (8.5) (push) Successful in 3m10s
linter / quality (push) Successful in 1m5s
tests / ci (8.5) (push) Successful in 3m9s
docker / build-and-push (push) Successful in 21m5s
docker / release (push) Skipped
Cut over-engineering found by a repo-wide audit
- Config: auth, services, logging, queue and database only repeated the
  framework's own files and are gone; the others keep only the keys that
  differ (app version, cache serializable_classes, session cookie name,
  Markdown mail theme, the shares disk, three Octane values, Livewire's
  pagination theme and payload guards).
- Email verification is removed: User never implemented MustVerifyEmail,
  so it was never enforced, and SealShare has a single admin and no
  registration. CreateNewUser goes with it.
- FileEncryptionService::encryptFile() and generateSalt() were only used
  by tests; tests build files with encryptTestFile() in tests/Pest.php.
- The expiration options are defined once, as Share::EXPIRATIONS. "30 Days"
  now lasts 30 days instead of a calendar month, and Admin settings only
  save a default expiration that is one of the options.
- One-caller helpers are inlined, the uploader reads chunk responses with
  XHR's responseType, and starter-kit leftovers are removed.
- Docker: PHP reads the PHP_* limits from the environment itself
  (${VAR:-default} in uploads.ini); both entrypoints stop writing the ini.
  docker-compose.yml shares the app and scheduler variables through one
  anchor. The dev image installs gd for the screenshot publisher and fake
  test images.
- Development runs in Docker only: the composer dev script, concurrently,
  laravel/pail, laravel/sail, autoprefixer and the shell-quote override
  are gone.
- phpunit.xml forces the test environment with <server> entries, so tests
  run in the dev container no longer use its real database.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-18 23:14:33 +02:00

76 lines
3.9 KiB
PHP

<?php
use App\Models\Setting;
use App\Models\Share;
use App\Models\User;
use Illuminate\Support\Facades\Storage;
use Illuminate\Testing\TestResponse;
use Tests\TestCase;
/**
* The opening tag of the page template's pane (resources/views/components/page.blade.php).
*/
function pageTag(string $html): string
{
preg_match('/<div\s[^>]*data-test="page"[^>]*>/', $html, $matches);
return $matches[0] ?? '';
}
test('every page is one page template, one h1 and the same width', function (Closure $visit) {
$html = $visit($this)->assertOk()->getContent();
expect(substr_count($html, 'data-test="page"'))->toBe(1)
->and(preg_match_all('/<h1[\s>]/', $html))->toBe(1)
->and(pageTag($html))->toContain('data-md-width="narrow"');
})->with([
'upload' => [fn (TestCase $test): TestResponse => $test->get(route('upload'))],
'download' => [fn (TestCase $test): TestResponse => $test->get(route('share.download', Share::factory()->withPassword()->create()))],
'share created' => [fn (TestCase $test): TestResponse => $test->get(route('share.created', Share::factory()->create()))],
'login' => [fn (TestCase $test): TestResponse => $test->get(route('login'))],
'forgot password' => [fn (TestCase $test): TestResponse => $test->get(route('password.request'))],
'reset password' => [fn (TestCase $test): TestResponse => $test->get(route('password.reset', 'token'))],
'two-factor challenge' => [fn (TestCase $test): TestResponse => $test->withSession(['login.id' => User::factory()->withTwoFactor()->create()->id])->get(route('two-factor.login'))],
'setup' => [function (TestCase $test): TestResponse {
User::query()->where('is_admin', true)->delete();
return $test->get(route('setup'));
}],
'system password' => [function (TestCase $test): TestResponse {
Setting::set('system_password', bcrypt('system-secret'));
return $test->get(route('system-password'));
}],
'confirm password' => [fn (TestCase $test): TestResponse => $test->actingAs(User::factory()->create())->get(route('password.confirm'))],
'profile' => [fn (TestCase $test): TestResponse => $test->actingAs(User::factory()->create())->get(route('profile.edit'))],
'password' => [fn (TestCase $test): TestResponse => $test->actingAs(User::factory()->create())->get(route('user-password.edit'))],
'two-factor settings' => [fn (TestCase $test): TestResponse => $test->actingAs(User::factory()->create())->withSession(['auth.password_confirmed_at' => time()])->get(route('two-factor.show'))],
'appearance' => [fn (TestCase $test): TestResponse => $test->actingAs(User::factory()->create())->get(route('appearance.edit'))],
'admin settings' => [fn (TestCase $test): TestResponse => $test->actingAs(User::factory()->admin()->create())->get(route('admin.settings'))],
'admin dashboard' => [fn (TestCase $test): TestResponse => $test->actingAs(User::factory()->admin()->create())->get(route('admin.dashboard'))],
]);
test("a brand page is headed by the site's own logo, title and description", function () {
Setting::set('site_title', 'Acme Files');
Setting::set('site_description', 'Send files to Acme Engineering.');
Setting::set('site_logo', 'branding/acme.png');
$html = $this->get(route('login'))
->assertOk()
->assertSeeInOrder(['data-test="page-logo"', '<h1', 'Send files to Acme Engineering.'], false)
->assertSee(Storage::disk('public')->url('branding/acme.png'), false)
->getContent();
expect($html)->toMatch('/<h1[^>]*>\s*Acme Files\s*<\/h1>/');
});
test('a brand page falls back to the app name and SealShare\'s own line without branding', function () {
$html = $this->get(route('upload'))
->assertOk()
->assertSeeInOrder(['<h1', 'Share your files safely and securely'], false)
->assertDontSee('data-test="page-logo"', false)
->getContent();
expect($html)->toMatch('/<h1[^>]*>\s*'.preg_quote(config('app.name'), '/').'\s*<\/h1>/');
});