#!/bin/bash # Phase 2A Validation Script # # Validates the complete Phase 2A implementation including: # - File structure verification # - Code syntax validation # - Database schema checks # - Integration testing # - Performance validation # # Usage: ./scripts/validate-phase2a.sh [environment] # Environment: local (default), staging, production set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Configuration SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" ENVIRONMENT="${1:-local}" # Environment-specific settings case $ENVIRONMENT in "local") BASE_URL="http://localhost:8080" ;; "staging") BASE_URL="https://upskill-staging.measurequick.com" ;; "production") BASE_URL="https://upskill.measurequick.com" ;; *) echo -e "${RED}❌ Invalid environment: $ENVIRONMENT${NC}" echo "Valid environments: local, staging, production" exit 1 ;; esac echo -e "${BLUE}🚀 Phase 2A Validation Script${NC}" echo -e "${BLUE}==============================${NC}" echo -e "Environment: ${YELLOW}$ENVIRONMENT${NC}" echo -e "Base URL: ${YELLOW}$BASE_URL${NC}" echo -e "Project Directory: ${YELLOW}$PROJECT_DIR${NC}" echo "" # Track validation results VALIDATION_ERRORS=0 VALIDATION_WARNINGS=0 # Logging functions log_success() { echo -e "${GREEN}✅ $1${NC}" } log_error() { echo -e "${RED}❌ $1${NC}" ((VALIDATION_ERRORS++)) } log_warning() { echo -e "${YELLOW}âš ī¸ $1${NC}" ((VALIDATION_WARNINGS++)) } log_info() { echo -e "${BLUE}â„šī¸ $1${NC}" } log_section() { echo -e "\n${BLUE}📋 $1${NC}" echo -e "${BLUE}$(printf '%.0s-' {1..40})${NC}" } # Phase 2A File Structure Validation validate_file_structure() { log_section "File Structure Validation" # Core Phase 2A files local phase2a_files=( "includes/class-hvac-event-template-manager.php" "includes/class-hvac-event-form-builder.php" "includes/class-hvac-bulk-event-manager.php" "assets/js/hvac-event-form-templates.js" "assets/js/hvac-bulk-operations.js" "assets/css/hvac-event-form-templates.css" "assets/css/hvac-bulk-operations.css" "tests/phase2a-comprehensive-test.js" "docs/PHASE-2A-EVENT-TEMPLATES-STATUS.md" ) for file in "${phase2a_files[@]}"; do if [[ -f "$PROJECT_DIR/$file" ]]; then log_success "File exists: $file" else log_error "Missing file: $file" fi done # Check file sizes (ensure files are not empty) for file in "${phase2a_files[@]}"; do if [[ -f "$PROJECT_DIR/$file" ]]; then size=$(wc -c < "$PROJECT_DIR/$file") if [[ $size -gt 1000 ]]; then log_success "File has content: $file ($size bytes)" else log_warning "File may be incomplete: $file ($size bytes)" fi fi done } # PHP Syntax Validation validate_php_syntax() { log_section "PHP Syntax Validation" local php_files=( "includes/class-hvac-event-template-manager.php" "includes/class-hvac-event-form-builder.php" "includes/class-hvac-bulk-event-manager.php" ) for file in "${php_files[@]}"; do if [[ -f "$PROJECT_DIR/$file" ]]; then if php -l "$PROJECT_DIR/$file" >/dev/null 2>&1; then log_success "PHP syntax valid: $file" else log_error "PHP syntax error in: $file" php -l "$PROJECT_DIR/$file" 2>&1 | head -3 fi fi done } # JavaScript Syntax Validation validate_js_syntax() { log_section "JavaScript Syntax Validation" local js_files=( "assets/js/hvac-event-form-templates.js" "assets/js/hvac-bulk-operations.js" ) for file in "${js_files[@]}"; do if [[ -f "$PROJECT_DIR/$file" ]]; then # Check for basic syntax issues if node -c "$PROJECT_DIR/$file" >/dev/null 2>&1; then log_success "JavaScript syntax valid: $file" else log_error "JavaScript syntax error in: $file" node -c "$PROJECT_DIR/$file" 2>&1 | head -3 fi fi done } # Integration Validation validate_integration() { log_section "Integration Validation" # Check if files are properly integrated in main plugin if grep -q "class-hvac-event-template-manager.php" "$PROJECT_DIR/includes/class-hvac-plugin.php"; then log_success "Template Manager integrated in main plugin" else log_error "Template Manager not integrated in main plugin" fi if grep -q "class-hvac-bulk-event-manager.php" "$PROJECT_DIR/includes/class-hvac-plugin.php"; then log_success "Bulk Event Manager integrated in main plugin" else log_error "Bulk Event Manager not integrated in main plugin" fi # Check database table creation in activator if grep -q "HVAC_Event_Template_Manager" "$PROJECT_DIR/includes/class-hvac-activator.php"; then log_success "Template Manager table creation integrated" else log_error "Template Manager table creation not integrated" fi if grep -q "HVAC_Bulk_Event_Manager" "$PROJECT_DIR/includes/class-hvac-activator.php"; then log_success "Bulk Event Manager table creation integrated" else log_error "Bulk Event Manager table creation not integrated" fi } # Security Validation validate_security() { log_section "Security Validation" local security_patterns=( "wp_verify_nonce" "sanitize_text_field" "esc_html" "absint" "wp_kses_post" ) for pattern in "${security_patterns[@]}"; do local count=$(grep -r "$pattern" "$PROJECT_DIR/includes/class-hvac-event-template-manager.php" "$PROJECT_DIR/includes/class-hvac-bulk-event-manager.php" 2>/dev/null | wc -l) if [[ $count -gt 0 ]]; then log_success "Security pattern '$pattern' used ($count occurrences)" else log_warning "Security pattern '$pattern' not found" fi done } # Performance Validation validate_performance() { log_section "Performance Validation" # Check for caching implementation if grep -q "wp_cache_set\|set_transient" "$PROJECT_DIR/includes/class-hvac-event-template-manager.php"; then log_success "Caching implemented in Template Manager" else log_warning "No caching found in Template Manager" fi # Check for database optimization if grep -q "LIMIT\|INDEX\|KEY" "$PROJECT_DIR/includes/class-hvac-event-template-manager.php" "$PROJECT_DIR/includes/class-hvac-bulk-event-manager.php"; then log_success "Database optimization patterns found" else log_warning "No database optimization patterns found" fi } # End-to-End Testing run_e2e_tests() { log_section "End-to-End Testing" # Check if Node.js and required packages are available if command -v node >/dev/null 2>&1; then log_info "Node.js available, checking for Playwright..." if [[ -f "$PROJECT_DIR/tests/phase2a-comprehensive-test.js" ]]; then log_info "Running Phase 2A comprehensive tests..." cd "$PROJECT_DIR" # Install playwright if not available if ! npm list playwright >/dev/null 2>&1; then log_info "Installing Playwright..." npm install playwright >/dev/null 2>&1 || log_warning "Failed to install Playwright automatically" fi # Run the tests if HEADLESS=true BASE_URL="$BASE_URL" TIMEOUT=30000 node tests/phase2a-comprehensive-test.js; then log_success "End-to-end tests passed" else log_error "End-to-end tests failed" fi else log_error "Phase 2A test file not found" fi else log_warning "Node.js not available, skipping E2E tests" fi } # Documentation Validation validate_documentation() { log_section "Documentation Validation" local doc_files=( "docs/PHASE-2A-EVENT-TEMPLATES-STATUS.md" "CLAUDE.md" "Status.md" ) for file in "${doc_files[@]}"; do if [[ -f "$PROJECT_DIR/$file" ]]; then if grep -q "Phase 2A\|Event Template\|Bulk Operations" "$PROJECT_DIR/$file"; then log_success "Documentation updated: $file" else log_warning "Documentation may not be updated: $file" fi else log_warning "Documentation file missing: $file" fi done } # WordPress Compatibility Check validate_wp_compatibility() { log_section "WordPress Compatibility" # Check for WordPress best practices local wp_patterns=( "add_action" "add_filter" "wp_ajax_" "wp_enqueue_script" "wp_enqueue_style" "wp_localize_script" ) for pattern in "${wp_patterns[@]}"; do local count=$(grep -r "$pattern" "$PROJECT_DIR/includes/class-hvac-event-template-manager.php" "$PROJECT_DIR/includes/class-hvac-bulk-event-manager.php" 2>/dev/null | wc -l) if [[ $count -gt 0 ]]; then log_success "WordPress pattern '$pattern' used ($count occurrences)" else log_warning "WordPress pattern '$pattern' not found" fi done } # Generate Validation Report generate_report() { log_section "Validation Summary" local total_checks=$((VALIDATION_ERRORS + VALIDATION_WARNINGS)) local timestamp=$(date '+%Y-%m-%d %H:%M:%S') echo -e "\n${BLUE}📊 Phase 2A Validation Report${NC}" echo -e "${BLUE}=============================${NC}" echo -e "Timestamp: ${timestamp}" echo -e "Environment: ${ENVIRONMENT}" echo -e "Base URL: ${BASE_URL}" echo "" if [[ $VALIDATION_ERRORS -eq 0 ]]; then echo -e "${GREEN}✅ Status: PASSED${NC}" else echo -e "${RED}❌ Status: FAILED${NC}" fi echo "" echo -e "${GREEN}✅ Successful checks: Validated without critical errors${NC}" echo -e "${RED}❌ Critical errors: ${VALIDATION_ERRORS}${NC}" echo -e "${YELLOW}âš ī¸ Warnings: ${VALIDATION_WARNINGS}${NC}" # Write report to file local report_file="$PROJECT_DIR/validation-reports/phase2a-validation-$(date +%Y%m%d-%H%M%S).log" mkdir -p "$(dirname "$report_file")" { echo "Phase 2A Validation Report" echo "==========================" echo "Timestamp: $timestamp" echo "Environment: $ENVIRONMENT" echo "Base URL: $BASE_URL" echo "Critical Errors: $VALIDATION_ERRORS" echo "Warnings: $VALIDATION_WARNINGS" echo "" echo "Validation completed successfully." } > "$report_file" log_info "Report saved: $report_file" } # Main validation sequence main() { log_info "Starting Phase 2A validation..." validate_file_structure validate_php_syntax validate_js_syntax validate_integration validate_security validate_performance validate_documentation validate_wp_compatibility # Only run E2E tests for local and staging environments if [[ "$ENVIRONMENT" != "production" ]]; then run_e2e_tests else log_info "Skipping E2E tests in production environment" fi generate_report # Exit with appropriate code if [[ $VALIDATION_ERRORS -eq 0 ]]; then log_success "Phase 2A validation completed successfully!" exit 0 else log_error "Phase 2A validation failed with $VALIDATION_ERRORS critical errors" exit 1 fi } # Run main function main "$@"