# Product Updates Production Testing Guide


**Last Updated:** 2026-03-25

## Overview

This guide provides step-by-step instructions for testing the Product Updates storage system on production after deployment.

## Image pipeline E2E (staging or production)

After changes affecting uploads, library, or JSON image paths:

1. **Upload** — Upload JPEG/PNG/WebP; confirm file exists under `wp-content/uploads/produkt-updates/` and API returns a path that loads (200).
2. **Library** — Open image library; confirm **no duplicate rows** for the same basename (absolute vs relative merged); “in use” badges match selection.
3. **Select & save** — Set featured image on a feature and a small improvement; save; reload admin and confirm path is **root-relative** where applicable.
4. **Public** — Open the feature post URL and a listing page; hero/OG image returns **200** at **`/produkt-updates/bilder/...`**; legacy `/wp-content/uploads/...` and `/produkt-updates/media/...` should **301** to `/produkt-updates/bilder/...`; prefer WebP when sidecar exists (`produktUpdatesResolveDisplayImagePath`).
5. **Feed** — `GET /produkt-updates/feed.json`; item `image` URLs are absolute **https** under `https://www.ordio.com/produkt-updates/bilder/...` and return 200.
6. **Delete** — Delete an image from the library (bulk or single); confirm **unlink**, JSON refs cleared (`cleanupImageFromJson`), and **`php v2/api/produkt-updates-image-persistence-check.php --fail-on-issues`** passes (or fix drift first).
7. **Feature/improvement delete** — After save, the row is gone from JSON but **image files remain on disk** (still visible in the library) unless removed via step 6.
8. **Shared featured image** — Point two features at the same `/produkt-updates/bilder/…` asset; **Replace** the image on one feature only; confirm the other feature’s thumbnail still **200** and the shared file remains on disk. Optional: `php v2/scripts/dev-helpers/test-produkt-updates-image-refcount.php`.
9. **Admin AJAX** — Replace via library/URL/upload on an existing feature; confirm JSON saves without full page reload and the list thumbnail updates (or run from modal-only flows as applicable).
10. **Post delete + library** — Delete a feature that had a unique featured image; confirm the file **still** appears in the image library until you explicitly delete it there.

## Pre-Testing Checklist

- [ ] All files deployed to production
- [ ] Admin panel accessible and login works
- [ ] File permissions set correctly
- [ ] Storage initialized (if needed)

## Testing Tools Available

### 1. Production Setup Analysis

**URL:** `/v2/admin/produkt-updates/analyze-production-setup.php`

**Purpose:** Comprehensive analysis of production environment, storage locations, and optimal setup recommendations.

**What it checks:**

- Server configuration (PHP version, user, permissions)
- All storage locations (existence, permissions, disk space)
- Current resolved paths (data file, images)
- Best practices compliance
- Recommendations for fixes

**How to use:**

1. Log in to admin panel
2. Navigate to: `/v2/admin/produkt-updates/analyze-production-setup.php`
3. Review JSON output for:
   - `summary.status` - Should be "ok"
   - `recommendations` - Any critical/high priority issues
   - `optimal_setup` - Recommended configuration

### 2. Endpoint Testing

**URL:** `/v2/admin/produkt-updates/test-production-endpoints.php`

**Purpose:** Tests all diagnostic endpoints and analyzes responses.

**What it checks:**

- Storage health endpoint
- Server investigation endpoint
- Data location check endpoint
- Image investigation endpoint
- Response times and HTTP codes
- Identifies issues from responses

**How to use:**

1. Log in to admin panel
2. Navigate to: `/v2/admin/produkt-updates/test-production-endpoints.php`
3. Review JSON output for:
   - `summary.all_successful` - Should be true
   - `analysis.critical_issues` - Should be empty
   - Individual endpoint results

**CLI Usage:**

```bash
php v2/admin/produkt-updates/test-production-endpoints.php
```

### 3. Comprehensive Production Test

**URL:** `/v2/admin/produkt-updates/comprehensive-production-test.php`

**Purpose:** End-to-end testing of all Product Updates functionality.

**What it checks:**

- Storage path resolution
- Data file operations (read, write, JSON validity)
- Image directory operations
- Public page accessibility
- Image proxy endpoint
- Atomic write capability

**How to use:**

1. Log in to admin panel
2. Navigate to: `/v2/admin/produkt-updates/comprehensive-production-test.php`
3. Review JSON output for:
   - `summary.all_tests_passed` - Should be true
   - `summary.status` - Should be "PASS"
   - Individual test suite results

## Step-by-Step Testing Procedure

### Step 1: Initial Setup Analysis

1. Access: `/v2/admin/produkt-updates/analyze-production-setup.php`
2. Check `summary.status`:

   - ✅ `ok` - System configured correctly
   - ⚠️ `warning` - Some issues found, review recommendations
   - ❌ `critical` - Critical issues, immediate action required

3. Review `recommendations` array:
   - **Critical priority:** Must fix immediately (volatile storage, missing directories)
   - **High priority:** Should fix soon (permissions, disk space)
   - **Warning priority:** Monitor (low disk space)

### Step 2: Test Diagnostic Endpoints

1. Access: `/v2/admin/produkt-updates/test-production-endpoints.php`
2. Verify all endpoints return HTTP 200:

   - Storage health
   - Server investigation
   - Data location check
   - Image investigation

3. Check for issues:
   - `using_volatile_storage` - Should be false
   - `critical_issues` - Should be empty array
   - `locations_match` - Should be true

### Step 3: Run Comprehensive Tests

1. Access: `/v2/admin/produkt-updates/comprehensive-production-test.php`
2. Verify all test suites pass:

   - Storage Path Resolution
   - Data File Operations
   - Image Directory Operations
   - Public Page Accessibility
   - Image Proxy Endpoint
   - Atomic Write Capability

3. Check summary:
   - `all_tests_passed` - Should be true
   - `success_rate` - Should be 100%
   - `status` - Should be "PASS"

### Step 4: Manual Verification

#### Admin Panel

1. Log in to admin panel
2. Navigate to Settings > Storage Status
3. Verify:
   - Data file location is persistent (not `/tmp/`)
   - Image directory is persistent (not `/tmp/`)
   - No warnings displayed
   - All status indicators green

#### Public Pages

1. Visit `/produkt-updates`
2. Verify:

   - Page loads correctly
   - Content displays
   - Images load correctly
   - Navigation works

3. Visit a month page (e.g., `/produkt-updates/2025-01`)
4. Verify:

   - Month content displays
   - Images load
   - Links work

5. Visit an individual post (if available)
6. Verify:
   - Post content displays
   - Featured image loads
   - Back navigation works

#### Image Upload Test

1. In admin panel, try uploading an image
2. Verify:
   - Upload succeeds
   - Image appears in image library
   - Image displays correctly on public pages

#### Data Save Test

1. In admin panel, make a small change (e.g., edit a feature)
2. Save changes
3. Verify:
   - Save succeeds
   - Changes appear immediately
   - Changes persist after page refresh

## Common Issues and Solutions

### Issue: Endpoints Return 403 Forbidden

**Cause:** Authentication not configured or token/IP whitelist not set

**Solution:**

1. Check `v2/config/storage-diagnostics-auth.php`
2. Set `STORAGE_DIAGNOSTICS_AUTH_METHOD` to appropriate method
3. Configure IP whitelist or token
4. Or use admin session authentication

### Issue: Tests Show Volatile Storage

**Cause:** Data/images stored in `/tmp/` directory

**Solution:**

1. Run data migration: `/v2/admin/produkt-updates/migrate-to-persistent-storage.php?action=migrate`
2. Run image migration: `/v2/admin/produkt-updates/migrate-images-to-persistent.php?action=migrate`
3. Fix permissions if needed
4. Re-run tests to verify

### Issue: Public Pages Not Loading

**Cause:** Data file not readable or path resolution issue

**Solution:**

1. Check data file location: `/v2/api/produkt-updates-data-location-check.php`
2. Verify file permissions
3. Check if data file exists and contains valid JSON
4. Review error logs

### Issue: Images Not Displaying

**Cause:** Images missing or proxy endpoint issue

**Solution:**

1. Check image investigation: `/v2/api/produkt-updates-image-investigation.php`
2. Verify images exist in persistent location
3. Check image proxy endpoint: `/v2/api/serve-produkt-updates-image.php?file=test.jpg`
4. Review JSON references match actual image locations

### Issue: Atomic Write Test Fails

**Cause:** Directory not writable or permissions issue

**Solution:**

1. Check directory permissions
2. Verify web server user owns directory
3. Run initialization script: `/v2/admin/produkt-updates/init-storage.php`
4. Fix permissions: `chmod 755` for directories, `chmod 644` for files

## Expected Test Results

### Production Setup Analysis

```json
{
  "summary": {
    "status": "ok",
    "using_volatile_storage": false,
    "critical_issues": 0,
    "high_issues": 0,
    "optimal_setup_configured": true
  }
}
```

### Endpoint Testing

```json
{
  "summary": {
    "all_successful": true,
    "average_response_time": 150.5
  },
  "analysis": {
    "using_volatile_storage": false,
    "critical_issues": []
  }
}
```

### Comprehensive Tests

```json
{
  "summary": {
    "all_tests_passed": true,
    "success_rate": 100.0,
    "status": "PASS"
  }
}
```

## Post-Testing Actions

### If All Tests Pass

1. ✅ Document test results
2. ✅ Set up monitoring (health check endpoint)
3. ✅ Configure alerts for critical issues
4. ✅ Schedule regular testing (weekly/monthly)

### If Tests Fail

1. ❌ Review failure details in test output
2. ❌ Check recommendations from setup analysis
3. ❌ Fix issues using migration/initialization scripts
4. ❌ Re-run tests to verify fixes
5. ❌ Document issues and solutions

## Monitoring Setup

### Health Check Monitoring

Set up automated monitoring to check:

- `/v2/api/produkt-updates-storage-health.php` every 5 minutes
- Alert on: `overall_status !== 'OK'`
- Alert on: `using_volatile_storage === true`
- Alert on: `critical_issues_count > 0`

### Log Monitoring

Monitor `v2/logs/produkt-updates-storage.log` for:

- CRITICAL level messages
- ERROR level messages
- WARNING messages about volatile storage

### Metrics Tracking

Monitor `v2/data/storage-metrics.json` for:

- Error rate > 5%
- No writes in 24+ hours
- Rapid increase in error count

## Next Steps

After successful testing:

1. **Documentation:** Update deployment notes with test results
2. **Monitoring:** Set up automated health checks
3. **Alerts:** Configure email alerts for critical issues
4. **Regular Testing:** Schedule weekly/monthly test runs
5. **Backup Verification:** Verify backup system works correctly

## Support

**For Issues:**

- Review test output JSON for specific error details
- Check error logs: `v2/logs/produkt-updates-storage.log`
- Review diagnostic endpoints for detailed information
- Contact: hady@ordio.com

**Documentation:**

- Storage Migration Guide: `docs/PRODUCT_UPDATES_STORAGE_MIGRATION.md`
- Production Deployment: `docs/PRODUCT_UPDATES_PRODUCTION_DEPLOYMENT.md`
- Implementation Summary: `docs/PRODUCT_UPDATES_IMPLEMENTATION_SUMMARY.md`
