# Laravel Test Suite Documentation

## Overview

Comprehensive test suite covering all features and functionality of the OA Media Kraft application.

## Test Statistics

-   **Total Tests**: 78
-   **Total Assertions**: 201
-   **Test Coverage**: Feature Tests (9 files) + Unit Tests (4 files)

## Feature Tests

### 1. HomePageTest (7 tests)

Tests for the main homepage functionality:

-   ✅ Homepage loads successfully with correct view and data
-   ✅ Services data is displayed correctly
-   ✅ Portfolio items are rendered
-   ✅ Light/dark theme switching works
-   ✅ Named route 'home' resolves correctly

### 2. AboutPageTest (4 tests)

Tests for the about page:

-   ✅ About page loads with correct view
-   ✅ Services are displayed
-   ✅ Theme support (light/dark mode)
-   ✅ Named route 'about' works

### 3. ContactFormTest (9 tests)

Comprehensive contact form validation and functionality:

-   ✅ Successful form submission with email sending
-   ✅ Validation: name is required
-   ✅ Validation: email is required
-   ✅ Validation: email must be valid format
-   ✅ Validation: message is required
-   ✅ Subject field is optional
-   ✅ IP address and user agent are saved
-   ✅ Emails sent to contact@oamediakraft.co.uk with cc to ola@oamediakraft.co.uk
-   ✅ Acknowledgement email sent to sender

### 4. NewsletterTest (9 tests)

Newsletter subscription and unsubscription:

-   ✅ Successful subscription with email confirmation
-   ✅ Validation: email is required
-   ✅ Validation: email must be valid
-   ✅ Prevents duplicate subscriptions
-   ✅ Saves IP address
-   ✅ Successful unsubscription
-   ✅ Unsubscribe requires email parameter
-   ✅ Handles non-existent email gracefully
-   ✅ Sends notification and confirmation emails

### 5. PhotographyPagesTest (5 tests)

Photography module pages:

-   ✅ Photography home page loads
-   ✅ Portfolio page loads
-   ✅ Services page loads
-   ✅ Booking page loads
-   ✅ Services are displayed (Portrait, Product, Event, Aerial)

### 6. DesignPagesTest (5 tests)

Design module pages:

-   ✅ Design home page loads
-   ✅ Portfolio page loads
-   ✅ Pricing page loads
-   ✅ Process page loads
-   ✅ Services displayed (Brand Identity, Print, Digital Design)

### 7. UiUxPageTest (6 tests)

UI/UX dedicated page:

-   ✅ UI/UX page loads with all data
-   ✅ Services are displayed
-   ✅ Process steps are shown
-   ✅ Work samples are visible
-   ✅ Theme support works
-   ✅ Named route 'uiux' resolves

### 8. LegalPagesTest (4 tests)

Legal and informational pages:

-   ✅ Terms of service page loads
-   ✅ Privacy policy page loads
-   ✅ Sitemap page loads
-   ✅ Accessibility statement page loads

### 9. OtherModulesTest (4 tests)

Additional module pages:

-   ✅ Podcast home page loads
-   ✅ Branding home page loads
-   ✅ Livestream home page loads
-   ✅ Hero home page loads

## Unit Tests

### 1. ContactSubmissionTest (6 tests)

ContactSubmission model functionality:

-   ✅ Model can be created with all attributes
-   ✅ Fillable attributes are correct
-   ✅ Model can be retrieved from database
-   ✅ Can be created without optional subject field
-   ✅ Timestamps are automatically set
-   ✅ Data persistence works correctly

### 2. NewsletterSubscriptionTest (6 tests)

NewsletterSubscription model:

-   ✅ Subscription can be created
-   ✅ Fillable attributes are defined
-   ✅ Can be retrieved from database
-   ✅ Can be deleted (unsubscribe)
-   ✅ subscribed_at field is cast to datetime
-   ✅ Timestamps work correctly

### 3. UserTest (7 tests)

User model authentication:

-   ✅ User can be created
-   ✅ Fillable attributes (name, email, password)
-   ✅ Hidden attributes (password, remember_token)
-   ✅ Password is properly hashed
-   ✅ email_verified_at cast to datetime
-   ✅ Password has hashed cast
-   ✅ User retrieval from database

### 4. RouteTest (9 tests)

Route configuration validation:

-   ✅ All 21 named routes exist
-   ✅ Contact route uses POST method
-   ✅ Newsletter subscribe uses POST
-   ✅ Newsletter unsubscribe uses GET
-   ✅ Photography routes have correct prefix
-   ✅ Design routes have correct prefix
-   ✅ Podcast routes have correct prefix
-   ✅ Branding routes have correct prefix
-   ✅ Livestream routes have correct prefix

## Running Tests

### Run all tests:

```bash
php artisan test
# or
./vendor/bin/phpunit
```

### Run specific test file:

```bash
php artisan test --filter HomePageTest
./vendor/bin/phpunit tests/Feature/HomePageTest.php
```

### Run specific test method:

```bash
php artisan test --filter test_homepage_loads_successfully
```

### Run with coverage (requires Xdebug):

```bash
php artisan test --coverage
```

## Test Database

Tests use the `RefreshDatabase` trait which:

-   Rolls back database after each test
-   Ensures clean state for each test
-   Uses in-memory SQLite for faster execution

## Mocked Services

The following services are mocked in tests:

-   **Mail**: Uses `Mail::fake()` to prevent actual email sending
-   Assertions verify emails are queued with correct recipients

## Key Tested Routes

### Public Routes (GET):

-   `/` - Homepage
-   `/about` - About page
-   `/terms`, `/privacy`, `/sitemap`, `/accessibility` - Legal pages
-   `/ui-ux` - UI/UX services
-   `/photography/*` - Photography module
-   `/design/*` - Design module
-   `/podcast`, `/branding`, `/livestream` - Other modules

### Form Submission Routes (POST):

-   `/contact` - Contact form submission
-   `/newsletter/subscribe` - Newsletter subscription

### Unsubscribe Route (GET):

-   `/newsletter/unsubscribe?email={email}` - Newsletter unsubscribe

## Coverage Areas

✅ **Page Rendering**: All views load correctly with status 200
✅ **Data Passing**: Controllers pass correct data to views
✅ **Form Validation**: All required fields validated
✅ **Email Functionality**: Mail sending tested (mocked)
✅ **Database Operations**: CRUD operations work correctly
✅ **Route Configuration**: All named routes exist and use correct methods
✅ **Theme Support**: Light/dark mode works across pages
✅ **Model Attributes**: Fillable, hidden, and cast attributes
✅ **Data Persistence**: Database saves and retrieves correctly

## Issues Fixed During Testing

1. **Syntax Error in design/pricing.blade.php**: Missing `=>` operator in array element (line 108)
    - Fixed: `'title' 'Scalable Files'` → `'title' => 'Scalable Files'`

## Continuous Integration

Tests are suitable for CI/CD pipelines:

-   Fast execution (~2 seconds)
-   No external dependencies (mocked emails)
-   Database automatically managed
-   All tests independent and parallelizable

## Next Steps

Consider adding:

1. Browser tests using Laravel Dusk
2. API endpoint tests if API is added
3. Performance tests for heavy pages
4. Security tests (CSRF, XSS, SQL injection)
5. Accessibility tests (WCAG compliance)
