# Testing

Runner: PHPUnit 11.5.58 (`phpunit/phpunit`). Config: `phpunit.xml`.

## Ejecutar

```bash
php artisan test
```

```bash
composer test
```

`composer test` ejecuta `php artisan config:clear` y luego `php artisan test`.

Filtrar:

```bash
php artisan test tests/Feature/Admin/Leads
php artisan test --filter=permission
```

## Entorno de tests

`phpunit.xml` fuerza:

- `APP_ENV=testing`
- `DB_CONNECTION=sqlite`, `DB_DATABASE=:memory:`
- `CACHE_STORE=array`, `SESSION_DRIVER=array`, `MAIL_MAILER=array`, `QUEUE_CONNECTION=sync`
- `BCRYPT_ROUNDS=4`

Tests no tocan `database/database.sqlite` ni datos reales.

## Carpetas

- `tests/Unit/Cms` — `ImageVariantService`, `HtmlSanitizer`, `SlugGenerator`, scopes de publicación.
- `tests/Unit/Models` — `Solution`, `Product`, `Project`, `Lead`.
- `tests/Feature/Admin` — CRUD y permisos por módulo (`Solutions`, `Products`, `Projects`, `Leads`, `Users`, `Roles`, `Settings`, componentes, layout, accesibilidad).
- `tests/Feature/Landing` — landing pública, opciones visuales, accesibilidad del formulario.
- `tests/Feature/Quote` — contrato `POST /quote`.
- `tests/Feature/Cms` — servicios de settings y `HandlesImageUpload`.
- `tests/Feature/Import` — `landing:import-groff`.
- `tests/Feature/Seeders` — `AluminumRailingsSeeder`.
- `tests/Feature/Auth`, `tests/Feature/ProfileTest.php`, `tests/Feature/CreateAdminUserTest.php`, `tests/Feature/SetupSmokeTest.php`, `tests/Feature/StorageLinksTest.php`.

## Política del proyecto

**Solo tests funcionales. Sin tests que afirmen copy/texto fijo ni strings CSS.**

Origen: plan maestro L8 y `odd/tasks/f0-setup.md` L4. Los tests verifican:

- comportamiento HTTP (status, redirect, errores de validación),
- persistencia en BD,
- permisos y roles,
- efectos observables (archivos creados/borrados, valores guardados, links generados),
- estructura mínima necesaria (ej. `id="gallery"` presente/ausente), no textos editoriales.

No se agregan asserts sobre frases de marketing, labels visibles ni colores CSS. Los chequeos de paleta/marca son greps manuales en QA, no tests.

## Patrones usados

- `RefreshDatabase` para BD limpia por test.
- `$this->seed()` o `$this->seed(RolesAndPermissionsSeeder::class)` cuando el test necesita roles/permisos.
- `$this->withoutVite()` en tests que renderizan vistas Blade con `@vite`.
- `Storage::fake('public')` para aislar uploads; luego `Storage::disk('public')->assertExists/assertMissing/allFiles()`.
- `UploadedFile::fake()->image(...)` y `createWithContent(...)` para imágenes válidas/inválidas.
- Factories (`SolutionFactory`, `ProductFactory`, `ProjectFactory`, `LeadFactory`, `UserFactory`) solo para datos de test; seeders de contenido no usan factories.
- Pruebas de permisos crean roles temporales o usan `admin`/`publisher`/`editor` del seeder.

## Verificación manual complementaria

- `php artisan route:list --except-vendor` — rutas registradas.
- `php artisan list | grep -E 'landing:|cms:'` — comandos propios.
- `npm run build` — build de assets.
- Greps de marca/paleta y revisión de navegador quedan en QA (F5); no forman parte de la suite.
