# Aegilock WooCommerce PHPUnit Tests

This directory contains comprehensive PHPUnit tests for the Aegilock Transaction Guardian plugin.

## Test Files

- `test-aegilock-database-handler.php` - Tests for database operations, transactions, and SQL injection protection
- `test-aegilock-fraud-calculator.php` - Tests for fraud detection algorithms and scoring
- `test-aegilock-order-processor.php` - Tests for order processing, actions, and status management

## Running Tests

### Prerequisites
- PHPUnit installed
- WordPress test environment
- WooCommerce test environment

### Basic Usage
```bash
# Run all tests
phpunit

# Run specific test file
phpunit tests/test-aegilock-database-handler.php

# Run with coverage report
phpunit --coverage-html tests/coverage/html/
```

### Test Categories

#### Database Handler Tests
- Table creation and integrity
- SQL injection protection
- Transaction support with rollback
- Fraud log creation and retrieval
- Performance with pagination

#### Fraud Calculator Tests
- Email pattern detection
- Country risk assessment
- Amount-based risk scoring
- Customer trust verification
- Currency neutrality
- Performance benchmarks

#### Order Processor Tests
- Order status management
- Fraud action execution
- Test mode behavior
- Email notifications
- Bulk order processing
- Error handling

## Test Environment

The tests use a mock WordPress environment with:
- Mock database operations
- Simulated WooCommerce orders
- Test-specific settings and options
- Performance benchmarks

## Coverage Reports

Test coverage reports are generated in `tests/coverage/html/` directory.

## Best Practices

- Each test class focuses on a single component
- Tests include both positive and negative scenarios
- Performance tests ensure scalability
- Security tests verify protection against common attacks
- Mock objects simulate WordPress/WooCommerce environment

## Integration

The health check system (`Aegilock_Testing` class) verifies the presence and availability of these PHPUnit tests, providing a bridge between the plugin's built-in diagnostics and comprehensive test coverage.