# HVAC Taxonomy Implementation Testing Plan

## Overview

This document outlines comprehensive testing procedures for the HVAC Trainer Profile taxonomy conversion, which converts 5 text fields to proper WordPress taxonomies:

- `business_type` → `business_type` taxonomy
- `training_audience` → `training_audience` taxonomy  
- `training_formats` → `training_formats` taxonomy
- `training_locations` → `training_locations` taxonomy
- `training_resources` → `training_resources` taxonomy

## Pre-Testing Setup

### 1. Backup Data
```bash
# Backup database
wp db export backup_$(date +%Y%m%d_%H%M%S).sql

# Backup uploads directory
tar -czf uploads_backup_$(date +%Y%m%d_%H%M%S).tar.gz wp-content/uploads/
```

### 2. Environment Verification
```bash
# Verify WordPress installation
wp core verify-checksums

# Check plugin status
wp plugin status hvac-community-events

# Verify user roles
wp role list
```

## Phase 1: Backend Infrastructure Testing

### 1.1 Taxonomy Registration
```bash
# Run automated test script
bin/test-taxonomy-implementation.sh

# Manual verification
wp eval "var_dump(get_taxonomies(['public' => true], 'names'));"
```

**Expected Results:**
- All 5 taxonomies registered: `business_type`, `training_audience`, `training_formats`, `training_locations`, `training_resources`
- Each taxonomy has correct labels and settings
- Default terms created automatically

### 1.2 Default Terms Verification
```bash
# Check term counts
wp term list business_type --format=table
wp term list training_audience --format=table
wp term list training_formats --format=table
wp term list training_locations --format=table
wp term list training_resources --format=table
```

**Expected Results:**
- Business Type: 7 terms (Manufacturer, Distributor, Contractor, Consultant, Educator, Government, Other)
- Training Audience: 4 terms (Anyone, Industry professionals, Internal staff, Registered students)
- Training Formats: 4 terms (In-person, Virtual, Hybrid, On-demand)
- Training Locations: 5 terms (Online, Local, Regional Travel, National Travel, International Travel)
- Training Resources: 12 terms (Classroom, Training Lab, various equipment types, etc.)

### 1.3 Post Type Integration
```bash
# Verify trainer profile post type
wp post list --post_type=trainer_profile --format=table

# Test taxonomy assignment
wp post term add [PROFILE_ID] business_type Contractor
wp post term list [PROFILE_ID] business_type --format=table
```

## Phase 2: Data Migration Testing

### 2.1 Pre-Migration State
```bash
# Document current user meta data
wp user meta list [USER_ID] --format=table | grep -E "(business_type|training_)"

# Document current profile meta data  
wp post meta list [PROFILE_ID] --format=table | grep -E "(business_type|training_)"
```

### 2.2 Migration Execution
```bash
# Test dry-run migration first
wp eval "
require_once ABSPATH . 'wp-content/plugins/hvac-community-events/includes/taxonomy-migration.php';
\$result = HVAC_Taxonomy_Migration::run_migration(true);
print_r(\$result);
"

# Run actual migration
wp eval "
require_once ABSPATH . 'wp-content/plugins/hvac-community-events/includes/taxonomy-migration.php';
\$result = HVAC_Taxonomy_Migration::run_migration(false);
print_r(\$result);
"
```

**Expected Results:**
- Migration completes without errors
- All existing text data converted to taxonomy terms
- Old meta fields cleaned up
- No data loss occurs

### 2.3 Post-Migration Verification
```bash
# Verify taxonomy assignments
wp post term list [PROFILE_ID] business_type --format=table
wp post term list [PROFILE_ID] training_audience --format=table

# Verify old meta fields removed
wp post meta list [PROFILE_ID] --format=table | grep -E "(business_type|training_)"
```

## Phase 3: User Interface Testing

### 3.1 Registration Form Testing

**Test Cases:**
1. **Navigate to registration form** `/trainer/registration/`
2. **Verify taxonomy fields display correctly:**
   - Business Type: Radio buttons with taxonomy terms
   - Training Audience: Checkboxes with taxonomy terms
   - Training Formats: Checkboxes with taxonomy terms
   - Training Locations: Checkboxes with taxonomy terms
   - Training Resources: Checkboxes with taxonomy terms
3. **Test form submission:**
   - Select options from each taxonomy field
   - Submit form
   - Verify successful registration
   - Check that taxonomy terms are assigned to created profile

**Expected Results:**
- All taxonomy fields load dynamically from database
- Form validation works correctly
- Profile creation assigns correct taxonomy terms
- Fallback to hardcoded options if taxonomies unavailable

### 3.2 Profile Edit Testing (Legacy Template)

**Test Cases:**
1. **Navigate to profile edit** `/trainer/profile/edit/`
2. **Verify current values display correctly:**
   - Check that existing taxonomy selections are pre-selected
   - Verify fallback to user meta if profile not migrated yet
3. **Test form updates:**
   - Change taxonomy selections
   - Save form
   - Verify changes persist

### 3.3 Profile Edit Testing (Master Trainer)

**Test Cases:**
1. **Navigate to master trainer profile edit**
2. **Verify taxonomy checkboxes display:**
   - Training Audience: Multiple checkboxes
   - Training Formats: Multiple checkboxes
   - Training Locations: Multiple checkboxes
   - Training Resources: Multiple checkboxes
3. **Test AJAX form updates:**
   - Change selections
   - Save via AJAX
   - Verify changes applied to taxonomy terms

### 3.4 Profile Display Testing

**Test Cases:**
1. **Navigate to profile view** `/trainer/profile/`
2. **Verify taxonomy terms display correctly:**
   - Business type shows as single value
   - Other taxonomies show as comma-separated lists
3. **Test with different user roles:**
   - Regular trainer: Can edit own profile
   - Master trainer: Can edit any profile
   - Administrator: Full access

## Phase 4: Integration Testing

### 4.1 CSV Import Testing

**Test Cases:**
1. **Prepare test CSV with taxonomy data**
2. **Run CSV import process**
3. **Verify taxonomy assignment:**
   ```bash
   # Check if taxonomies assigned correctly
   wp post term list [IMPORTED_PROFILE_ID] business_type --format=table
   ```

**Expected Results:**
- CSV data correctly parsed and assigned to taxonomies
- Multiple values (comma-separated) handled correctly
- New terms created automatically if needed

### 4.2 Role-Based Permission Testing

**Test Cases:**
1. **Create test users with different roles:**
   ```bash
   wp user create test_trainer test@trainer.com --role=hvac_trainer
   wp user create test_master test@master.com --role=hvac_master_trainer
   ```
2. **Test profile access permissions:**
   - Regular trainer: Can only edit own profile
   - Master trainer: Can edit any profile
   - Administrator: Full access to all profiles
3. **Test taxonomy management permissions:**
   - Verify who can create new taxonomy terms
   - Test bulk taxonomy operations

### 4.3 AJAX Handler Testing

**Test Cases:**
1. **Test profile save AJAX:**
   - Modify taxonomy selections via AJAX
   - Verify server response
   - Check database updates
2. **Test auto-save functionality:**
   - Verify safe fields auto-save correctly
   - Test taxonomy field auto-save (if enabled)

## Phase 5: Performance Testing

### 5.1 Database Query Analysis
```bash
# Enable query debugging
wp config set WP_DEBUG true
wp config set SAVEQUERIES true

# Test page load performance
curl -w "@curl-format.txt" -o /dev/null -s "http://localhost/trainer/profile/edit/"
```

### 5.2 Large Dataset Testing

**Test Cases:**
1. **Create multiple profiles with taxonomy data**
2. **Test form rendering performance**
3. **Test taxonomy query performance**
4. **Monitor memory usage**

## Phase 6: Error Handling Testing

### 6.1 Taxonomy Unavailable Testing

**Test Cases:**
1. **Temporarily disable taxonomy registration**
2. **Test form fallback behavior:**
   - Verify hardcoded options display
   - Test form submission still works
3. **Re-enable taxonomies and verify recovery**

### 6.2 Migration Error Testing

**Test Cases:**
1. **Test migration with corrupted data**
2. **Test migration rollback**
3. **Test partial migration scenarios**

## Phase 7: Cross-Browser Testing

### 7.1 Browser Compatibility
- **Chrome:** Latest version
- **Firefox:** Latest version  
- **Safari:** Latest version
- **Edge:** Latest version

### 7.2 Mobile Testing
- **iOS Safari:** Test form interactions
- **Android Chrome:** Test form interactions
- **Responsive design:** Verify taxonomy checkboxes display correctly

## Phase 8: Security Testing

### 8.1 Input Validation
- Test XSS protection on taxonomy term names
- Test SQL injection protection
- Verify nonce validation

### 8.2 Permission Bypass Testing
- Attempt to edit profiles without permission
- Test direct taxonomy term creation
- Verify AJAX security

## Phase 9: Backward Compatibility Testing

### 9.1 Legacy Data Testing
- Test profiles created before taxonomy implementation
- Verify migration handles edge cases
- Test mixed environments (some migrated, some not)

### 9.2 API Compatibility
- Test existing API endpoints still work
- Verify shortcode compatibility
- Test theme integration

## Test Automation

### Automated Test Suite
```bash
# Run all automated tests
bin/test-taxonomy-implementation.sh

# Run specific test categories
npm test -- --grep "taxonomy"
```

### Continuous Integration
- Set up automated testing on staging deployments
- Monitor taxonomy performance metrics
- Alert on migration failures

## Success Criteria

### Functional Requirements ✅
- [ ] All 5 taxonomies registered and functional
- [ ] Default terms created correctly
- [ ] Migration script converts existing data without loss
- [ ] Forms display taxonomy options dynamically
- [ ] Profile editing works with taxonomies
- [ ] CSV import handles taxonomy data
- [ ] Permissions work correctly

### Performance Requirements ✅
- [ ] Page load times < 2 seconds
- [ ] Form rendering < 500ms
- [ ] Database queries optimized
- [ ] Memory usage within limits

### Security Requirements ✅
- [ ] Input validation working
- [ ] Permission system secure
- [ ] No XSS vulnerabilities
- [ ] AJAX properly secured

### Usability Requirements ✅
- [ ] Forms are intuitive
- [ ] Error messages are clear
- [ ] Mobile experience is good
- [ ] Accessibility requirements met

## Rollback Plan

If critical issues are discovered:

1. **Immediate Actions:**
   ```bash
   # Restore database backup
   wp db import backup_YYYYMMDD_HHMMSS.sql
   
   # Revert plugin to previous version
   git checkout [PREVIOUS_COMMIT]
   scripts/deploy.sh staging
   ```

2. **Data Preservation:**
   - Export any new taxonomy data
   - Document issues for future fixes
   - Communicate with users about temporary reversion

3. **Fix and Redeploy:**
   - Address identified issues
   - Re-run testing suite
   - Deploy fixes when ready

## Documentation Updates

After successful testing:
- Update API documentation
- Create user guides for new taxonomy features  
- Update developer documentation
- Record lessons learned for future migrations